From 5f0c2f37a7d65149d47c08785abc28db047841ff Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 8 Feb 2023 11:39:23 +0200 Subject: [PATCH] move vue tryout --- app/assets/javascript/vue_r.rb | 2 - app/assets/javascript/vue_r/application.rb | 67 ---------------------- app/assets/javascript/vue_r/mounter.rb | 64 --------------------- app/controllers/kanta_controller.rb | 7 --- app/views/kanta/_form.html.haml | 10 ---- app/views/kanta/edit.html.haml | 7 --- app/views/kanta/index.html.haml | 19 ------ app/views/kanta/new.html.haml | 5 -- app/views/kanta/show.html.haml | 16 ------ config/routes.rb | 1 - 10 files changed, 198 deletions(-) delete mode 100644 app/assets/javascript/vue_r.rb delete mode 100644 app/assets/javascript/vue_r/application.rb delete mode 100644 app/assets/javascript/vue_r/mounter.rb delete mode 100644 app/controllers/kanta_controller.rb delete mode 100644 app/views/kanta/_form.html.haml delete mode 100644 app/views/kanta/edit.html.haml delete mode 100644 app/views/kanta/index.html.haml delete mode 100644 app/views/kanta/new.html.haml delete mode 100644 app/views/kanta/show.html.haml diff --git a/app/assets/javascript/vue_r.rb b/app/assets/javascript/vue_r.rb deleted file mode 100644 index baf4b4c..0000000 --- a/app/assets/javascript/vue_r.rb +++ /dev/null @@ -1,2 +0,0 @@ -require "vue_r/application" -require "vue_r/mounter" diff --git a/app/assets/javascript/vue_r/application.rb b/app/assets/javascript/vue_r/application.rb deleted file mode 100644 index b89d570..0000000 --- a/app/assets/javascript/vue_r/application.rb +++ /dev/null @@ -1,67 +0,0 @@ -module VueR - class Application - - def initialize(hash) - hash.each do |k,v| - wrap_attr(k,v) - end - @effect = nil - @subscribers = {} - end - - def wrap_attr(k,v) - instance_variable_set "@#{k}" , v - define_getter(k) - define_setter(k) - end - - def define_getter(k) - self.class.define_method k.to_sym do - track(k) - instance_variable_get "@#{k}".to_sym - end - end - - def define_setter(k) - self.class.define_method "#{k}=".to_sym do |new_v| - instance_variable_set "@#{k}" , new_v - trigger(k) - end - end - - def track( key ) - puts "Tracking:#{key}-#{@effect.hash}" - return unless @effect - get_subscribers_for(key) << @effect - end - - def trigger(key) - puts "Trigger:#{key}" - effects = get_subscribers_for(key) - effects.each {|effect| effect.call() } - end - - def get_subscribers_for(key) - key = key.to_sym - unless @subscribers.has_key?(key) - @subscribers[key] = Set.new - end - @subscribers[key] - end - - def mount(on_class) - @mounter = Mounter.new(on_class , self) - @mounter.mount - end - - def watch_effect( update_proc ) - effect = Proc.new do - @effect = effect - update_proc.call - @effect = nil - end - effect.call - end - - end -end diff --git a/app/assets/javascript/vue_r/mounter.rb b/app/assets/javascript/vue_r/mounter.rb deleted file mode 100644 index 61da525..0000000 --- a/app/assets/javascript/vue_r/mounter.rb +++ /dev/null @@ -1,64 +0,0 @@ -require 'opal-parser' - -module VueR - class Mounter - HANDLEBARS = /{{\s?([^}]*)\s?}}/ - def initialize( id , app ) - @root = $document[id] - @application = app - end - - def mount - mount_Element(@root) - end - - def mount_Text elem - text = elem.text - scan = text.scan(HANDLEBARS) - return unless scan.length > 0 - raise "only one curly per text implemented not:#{scan.length}" if scan.length > 1 - match = text.match(HANDLEBARS) - str_before = text[0 ... match.begin(0)] - str_after = text[ match.end(0) .. -1] - ruby = match[0][2 ... -2] - puts "Text: #{ruby}" - proc = Proc.new do - elem.text = str_before + @application.eval(ruby).to_s + str_after - end - @application.watch_effect(proc) - end - - def mount_Element(elem) - elem.attributes.each do |name , value| - mount_attribute(elem , name) if name.start_with?("r_") - mount_event(elem , name) if name.start_with?("e_") - end - elem.children.each do |elem| - base_name = elem.class.to_s.split("::").last - send "mount_#{base_name}" , elem - end - end - - def mount_attribute(element , name) - native_name = name[2 .. -1] - ruby = element[name] - old_value = element[native_name] - puts "Attribute: #{ruby}" - proc = Proc.new do - element[native_name] = old_value + " " + @application.eval(ruby).to_s - end - @application.watch_effect(proc) - end - - - def mount_event(element , name) - native_name = name.gsub("e_" , "") - ruby = element[name] - puts "Event: #{native_name}:#{ruby}" - element.on!(native_name) do - got = @application.eval(ruby) - puts "Clicked #{got}" - end - end - end -end diff --git a/app/controllers/kanta_controller.rb b/app/controllers/kanta_controller.rb deleted file mode 100644 index b4de40a..0000000 --- a/app/controllers/kanta_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class KantaController < ApplicationController - - def show - @image = Merged::Image.first - end - -end diff --git a/app/views/kanta/_form.html.haml b/app/views/kanta/_form.html.haml deleted file mode 100644 index 99b17e7..0000000 --- a/app/views/kanta/_form.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -= form_for @kantum do |f| - - if @kantum.errors.any? - #error_explanation - %h2= "#{pluralize(@kantum.errors.count, "error")} prohibited this kantum from being saved:" - %ul - - @kantum.errors.full_messages.each do |message| - %li= message - - .actions - = f.submit 'Save' diff --git a/app/views/kanta/edit.html.haml b/app/views/kanta/edit.html.haml deleted file mode 100644 index d2becac..0000000 --- a/app/views/kanta/edit.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -%h1 Editing kantum - -= render 'form' - -= link_to 'Show', @kantum -\| -= link_to 'Back', kanta_path diff --git a/app/views/kanta/index.html.haml b/app/views/kanta/index.html.haml deleted file mode 100644 index fe2ed70..0000000 --- a/app/views/kanta/index.html.haml +++ /dev/null @@ -1,19 +0,0 @@ -%h1 Listing kanta - -%table - %thead - %tr - %th - %th - %th - - %tbody - - @kanta.each do |kantum| - %tr - %td= link_to 'Show', kantum - %td= link_to 'Edit', edit_kantum_path(kantum) - %td= link_to 'Destroy', kantum, method: :delete, data: { confirm: 'Are you sure?' } - -%br - -= link_to 'New Kantum', new_kantum_path diff --git a/app/views/kanta/new.html.haml b/app/views/kanta/new.html.haml deleted file mode 100644 index 0524e57..0000000 --- a/app/views/kanta/new.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%h1 New kantum - -= render 'form' - -= link_to 'Back', kanta_path diff --git a/app/views/kanta/show.html.haml b/app/views/kanta/show.html.haml deleted file mode 100644 index f0c38ca..0000000 --- a/app/views/kanta/show.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -#app - .flex.justify-center - = #@image.attributes - - .flex.justify-center - %a.underline{ e_click: "bg_change" , r_class: 'bg'} - {{ bg }} -:opal - class Clicker < VueR::Application - def bg_change - self.bg = "bg-cyan-50" - end - end - - kanta = Clicker.new(bg: 'bg-cyan-200') - kanta.mount("#app") diff --git a/config/routes.rb b/config/routes.rb index 96bf0bd..d5e869a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,4 @@ Rails.application.routes.draw do - resources :kanta resources :pictures resources :stories