diff --git a/Gemfile b/Gemfile index 5dd813e..1d4f5e6 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,9 @@ gem "devise-async" gem "passenger" , "6.0.15" , require: "phusion_passenger/rack_handler" gem "bootsnap", require: false +gem "opal-rails" +gem "opal-browser" + group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri mingw x64_mingw ] diff --git a/Gemfile.lock b/Gemfile.lock index 9fe2896..2778ed6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -262,8 +262,24 @@ GEM mustache nokogiri (~> 1.7) sanitize + opal (1.7.2) + ast (>= 2.3.0) + parser (~> 3.0, >= 3.0.3.2) + opal-browser (0.3.3) + opal (>= 1.0, < 2.0) + paggio (>= 0.3.0) + opal-rails (2.0.2) + opal (~> 1.0) + opal-sprockets (~> 1.0) + rails (>= 6.0, < 7.1) + sprockets-rails (>= 3.0) + opal-sprockets (1.0.3) + opal (>= 1.0, < 2.0) + sprockets (~> 4.0) + tilt (>= 1.4) open4 (1.3.4) orm_adapter (0.5.0) + paggio (0.3.0) parser (3.2.0.0) ast (~> 2.4.1) passenger (6.0.15) @@ -435,6 +451,8 @@ DEPENDENCIES kaminari merged! mina + opal-browser + opal-rails passenger (= 6.0.15) pg (~> 1.1) pundit (~> 2.3) diff --git a/app/assets/config/manifest.js b/app/assets/config/manifest.js index b06fc42..481e3f6 100644 --- a/app/assets/config/manifest.js +++ b/app/assets/config/manifest.js @@ -3,3 +3,4 @@ //= link_tree ../../javascript .js //= link_tree ../../../vendor/javascript .js //= link_tree ../builds +//= link_directory ../javascript .js \ No newline at end of file diff --git a/app/assets/javascript/opal_main.js.rb b/app/assets/javascript/opal_main.js.rb new file mode 100644 index 0000000..ca11882 --- /dev/null +++ b/app/assets/javascript/opal_main.js.rb @@ -0,0 +1,5 @@ +require "opal" +require "native" +require 'promise' +require 'browser/setup/mini' +require 'vue_r' diff --git a/app/assets/javascript/vue_r.rb b/app/assets/javascript/vue_r.rb new file mode 100644 index 0000000..baf4b4c --- /dev/null +++ b/app/assets/javascript/vue_r.rb @@ -0,0 +1,2 @@ +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 new file mode 100644 index 0000000..b89d570 --- /dev/null +++ b/app/assets/javascript/vue_r/application.rb @@ -0,0 +1,67 @@ +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 new file mode 100644 index 0000000..61da525 --- /dev/null +++ b/app/assets/javascript/vue_r/mounter.rb @@ -0,0 +1,64 @@ +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/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 96408e0..fec4d77 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -11,13 +11,8 @@ * It is generally better to create a new file per style scope. * *= require_self + *= require glightbox.min */ #thredded--container{ max-width: 60rem; } - -.prose{ - max-width: 100%; - color: inherit; - --tw-prose-bullets: #6b7280; -} diff --git a/app/assets/stylesheets/glightbox.min.css b/app/assets/stylesheets/glightbox.min.css new file mode 100644 index 0000000..3c9ff87 --- /dev/null +++ b/app/assets/stylesheets/glightbox.min.css @@ -0,0 +1 @@ +.glightbox-container{width:100%;height:100%;position:fixed;top:0;left:0;z-index:999999!important;overflow:hidden;-ms-touch-action:none;touch-action:none;-webkit-text-size-adjust:100%;-moz-text-size-adjust:100%;-ms-text-size-adjust:100%;text-size-adjust:100%;-webkit-backface-visibility:hidden;backface-visibility:hidden;outline:0}.glightbox-container.inactive{display:none}.glightbox-container .gcontainer{position:relative;width:100%;height:100%;z-index:9999;overflow:hidden}.glightbox-container .gslider{-webkit-transition:-webkit-transform .4s ease;transition:-webkit-transform .4s ease;transition:transform .4s ease;transition:transform .4s ease,-webkit-transform .4s ease;height:100%;left:0;top:0;width:100%;position:relative;overflow:hidden;display:-webkit-box!important;display:-ms-flexbox!important;display:flex!important;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}.glightbox-container .gslide{width:100%;position:absolute;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;opacity:0}.glightbox-container .gslide.current{opacity:1;z-index:99999;position:relative}.glightbox-container .gslide.prev{opacity:1;z-index:9999}.glightbox-container .gslide-inner-content{width:100%}.glightbox-container .ginner-container{position:relative;width:100%;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column;max-width:100%;margin:auto;height:100vh}.glightbox-container .ginner-container.gvideo-container{width:100%}.glightbox-container .ginner-container.desc-bottom,.glightbox-container .ginner-container.desc-top{-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.glightbox-container .ginner-container.desc-left,.glightbox-container .ginner-container.desc-right{max-width:100%!important}.gslide iframe,.gslide video{outline:0!important;border:none;min-height:165px;-webkit-overflow-scrolling:touch;-ms-touch-action:auto;touch-action:auto}.gslide:not(.current){pointer-events:none}.gslide-image{-webkit-box-align:center;-ms-flex-align:center;align-items:center}.gslide-image img{max-height:100vh;display:block;padding:0;float:none;outline:0;border:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;max-width:100vw;width:auto;height:auto;-o-object-fit:cover;object-fit:cover;-ms-touch-action:none;touch-action:none;margin:auto;min-width:200px}.desc-bottom .gslide-image img,.desc-top .gslide-image img{width:auto}.desc-left .gslide-image img,.desc-right .gslide-image img{width:auto;max-width:100%}.gslide-image img.zoomable{position:relative}.gslide-image img.dragging{cursor:-webkit-grabbing!important;cursor:grabbing!important;-webkit-transition:none;transition:none}.gslide-video{position:relative;max-width:100vh;width:100%!important}.gslide-video .plyr__poster-enabled.plyr--loading .plyr__poster{display:none}.gslide-video .gvideo-wrapper{width:100%;margin:auto}.gslide-video::before{content:'';position:absolute;width:100%;height:100%;background:rgba(255,0,0,.34);display:none}.gslide-video.playing::before{display:none}.gslide-video.fullscreen{max-width:100%!important;min-width:100%;height:75vh}.gslide-video.fullscreen video{max-width:100%!important;width:100%!important}.gslide-inline{background:#fff;text-align:left;max-height:calc(100vh - 40px);overflow:auto;max-width:100%;margin:auto}.gslide-inline .ginlined-content{padding:20px;width:100%}.gslide-inline .dragging{cursor:-webkit-grabbing!important;cursor:grabbing!important;-webkit-transition:none;transition:none}.ginlined-content{overflow:auto;display:block!important;opacity:1}.gslide-external{display:-webkit-box;display:-ms-flexbox;display:flex;width:100%;min-width:100%;background:#fff;padding:0;overflow:auto;max-height:75vh;height:100%}.gslide-media{display:-webkit-box;display:-ms-flexbox;display:flex;width:auto}.zoomed .gslide-media{-webkit-box-shadow:none!important;box-shadow:none!important}.desc-bottom .gslide-media,.desc-top .gslide-media{margin:0 auto;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.gslide-description{position:relative;-webkit-box-flex:1;-ms-flex:1 0 100%;flex:1 0 100%}.gslide-description.description-left,.gslide-description.description-right{max-width:100%}.gslide-description.description-bottom,.gslide-description.description-top{margin:0 auto;width:100%}.gslide-description p{margin-bottom:12px}.gslide-description p:last-child{margin-bottom:0}.zoomed .gslide-description{display:none}.glightbox-button-hidden{display:none}.glightbox-mobile .glightbox-container .gslide-description{height:auto!important;width:100%;position:absolute;bottom:0;padding:19px 11px;max-width:100vw!important;-webkit-box-ordinal-group:3!important;-ms-flex-order:2!important;order:2!important;max-height:78vh;overflow:auto!important;background:-webkit-gradient(linear,left top,left bottom,from(rgba(0,0,0,0)),to(rgba(0,0,0,.75)));background:linear-gradient(to bottom,rgba(0,0,0,0) 0,rgba(0,0,0,.75) 100%);-webkit-transition:opacity .3s linear;transition:opacity .3s linear;padding-bottom:50px}.glightbox-mobile .glightbox-container .gslide-title{color:#fff;font-size:1em}.glightbox-mobile .glightbox-container .gslide-desc{color:#a1a1a1}.glightbox-mobile .glightbox-container .gslide-desc a{color:#fff;font-weight:700}.glightbox-mobile .glightbox-container .gslide-desc *{color:inherit}.glightbox-mobile .glightbox-container .gslide-desc .desc-more{color:#fff;opacity:.4}.gdesc-open .gslide-media{-webkit-transition:opacity .5s ease;transition:opacity .5s ease;opacity:.4}.gdesc-open .gdesc-inner{padding-bottom:30px}.gdesc-closed .gslide-media{-webkit-transition:opacity .5s ease;transition:opacity .5s ease;opacity:1}.greset{-webkit-transition:all .3s ease;transition:all .3s ease}.gabsolute{position:absolute}.grelative{position:relative}.glightbox-desc{display:none!important}.glightbox-open{overflow:hidden}.gloader{height:25px;width:25px;-webkit-animation:lightboxLoader .8s infinite linear;animation:lightboxLoader .8s infinite linear;border:2px solid #fff;border-right-color:transparent;border-radius:50%;position:absolute;display:block;z-index:9999;left:0;right:0;margin:0 auto;top:47%}.goverlay{width:100%;height:calc(100vh + 1px);position:fixed;top:-1px;left:0;background:#000;will-change:opacity}.glightbox-mobile .goverlay{background:#000}.gclose,.gnext,.gprev{z-index:99999;cursor:pointer;width:26px;height:44px;border:none;display:-webkit-box;display:-ms-flexbox;display:flex;-webkit-box-pack:center;-ms-flex-pack:center;justify-content:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-orient:vertical;-webkit-box-direction:normal;-ms-flex-direction:column;flex-direction:column}.gclose svg,.gnext svg,.gprev svg{display:block;width:25px;height:auto;margin:0;padding:0}.gclose.disabled,.gnext.disabled,.gprev.disabled{opacity:.1}.gclose .garrow,.gnext .garrow,.gprev .garrow{stroke:#fff}.gbtn.focused{outline:2px solid #0f3d81}iframe.wait-autoplay{opacity:0}.glightbox-closing .gclose,.glightbox-closing .gnext,.glightbox-closing .gprev{opacity:0!important}.glightbox-clean .gslide-description{background:#fff}.glightbox-clean .gdesc-inner{padding:22px 20px}.glightbox-clean .gslide-title{font-size:1em;font-weight:400;font-family:arial;color:#000;margin-bottom:19px;line-height:1.4em}.glightbox-clean .gslide-desc{font-size:.86em;margin-bottom:0;font-family:arial;line-height:1.4em}.glightbox-clean .gslide-video{background:#000}.glightbox-clean .gclose,.glightbox-clean .gnext,.glightbox-clean .gprev{background-color:rgba(0,0,0,.75);border-radius:4px}.glightbox-clean .gclose path,.glightbox-clean .gnext path,.glightbox-clean .gprev path{fill:#fff}.glightbox-clean .gprev{position:absolute;top:-100%;left:30px;width:40px;height:50px}.glightbox-clean .gnext{position:absolute;top:-100%;right:30px;width:40px;height:50px}.glightbox-clean .gclose{width:35px;height:35px;top:15px;right:10px;position:absolute}.glightbox-clean .gclose svg{width:18px;height:auto}.glightbox-clean .gclose:hover{opacity:1}.gfadeIn{-webkit-animation:gfadeIn .5s ease;animation:gfadeIn .5s ease}.gfadeOut{-webkit-animation:gfadeOut .5s ease;animation:gfadeOut .5s ease}.gslideOutLeft{-webkit-animation:gslideOutLeft .3s ease;animation:gslideOutLeft .3s ease}.gslideInLeft{-webkit-animation:gslideInLeft .3s ease;animation:gslideInLeft .3s ease}.gslideOutRight{-webkit-animation:gslideOutRight .3s ease;animation:gslideOutRight .3s ease}.gslideInRight{-webkit-animation:gslideInRight .3s ease;animation:gslideInRight .3s ease}.gzoomIn{-webkit-animation:gzoomIn .5s ease;animation:gzoomIn .5s ease}.gzoomOut{-webkit-animation:gzoomOut .5s ease;animation:gzoomOut .5s ease}@-webkit-keyframes lightboxLoader{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes lightboxLoader{0%{-webkit-transform:rotate(0);transform:rotate(0)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@-webkit-keyframes gfadeIn{from{opacity:0}to{opacity:1}}@keyframes gfadeIn{from{opacity:0}to{opacity:1}}@-webkit-keyframes gfadeOut{from{opacity:1}to{opacity:0}}@keyframes gfadeOut{from{opacity:1}to{opacity:0}}@-webkit-keyframes gslideInLeft{from{opacity:0;-webkit-transform:translate3d(-60%,0,0);transform:translate3d(-60%,0,0)}to{visibility:visible;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);opacity:1}}@keyframes gslideInLeft{from{opacity:0;-webkit-transform:translate3d(-60%,0,0);transform:translate3d(-60%,0,0)}to{visibility:visible;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);opacity:1}}@-webkit-keyframes gslideOutLeft{from{opacity:1;visibility:visible;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}to{-webkit-transform:translate3d(-60%,0,0);transform:translate3d(-60%,0,0);opacity:0;visibility:hidden}}@keyframes gslideOutLeft{from{opacity:1;visibility:visible;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}to{-webkit-transform:translate3d(-60%,0,0);transform:translate3d(-60%,0,0);opacity:0;visibility:hidden}}@-webkit-keyframes gslideInRight{from{opacity:0;visibility:visible;-webkit-transform:translate3d(60%,0,0);transform:translate3d(60%,0,0)}to{-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);opacity:1}}@keyframes gslideInRight{from{opacity:0;visibility:visible;-webkit-transform:translate3d(60%,0,0);transform:translate3d(60%,0,0)}to{-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0);opacity:1}}@-webkit-keyframes gslideOutRight{from{opacity:1;visibility:visible;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}to{-webkit-transform:translate3d(60%,0,0);transform:translate3d(60%,0,0);opacity:0}}@keyframes gslideOutRight{from{opacity:1;visibility:visible;-webkit-transform:translate3d(0,0,0);transform:translate3d(0,0,0)}to{-webkit-transform:translate3d(60%,0,0);transform:translate3d(60%,0,0);opacity:0}}@-webkit-keyframes gzoomIn{from{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}to{opacity:1}}@keyframes gzoomIn{from{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}to{opacity:1}}@-webkit-keyframes gzoomOut{from{opacity:1}50%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}to{opacity:0}}@keyframes gzoomOut{from{opacity:1}50%{opacity:0;-webkit-transform:scale3d(.3,.3,.3);transform:scale3d(.3,.3,.3)}to{opacity:0}}@media (min-width:769px){.glightbox-container .ginner-container{width:auto;height:auto;-webkit-box-orient:horizontal;-webkit-box-direction:normal;-ms-flex-direction:row;flex-direction:row}.glightbox-container .ginner-container.desc-top .gslide-description{-webkit-box-ordinal-group:1;-ms-flex-order:0;order:0}.glightbox-container .ginner-container.desc-top .gslide-image,.glightbox-container .ginner-container.desc-top .gslide-image img{-webkit-box-ordinal-group:2;-ms-flex-order:1;order:1}.glightbox-container .ginner-container.desc-left .gslide-description{-webkit-box-ordinal-group:1;-ms-flex-order:0;order:0}.glightbox-container .ginner-container.desc-left .gslide-image{-webkit-box-ordinal-group:2;-ms-flex-order:1;order:1}.gslide-image img{max-height:97vh;max-width:100%}.gslide-image img.zoomable{cursor:-webkit-zoom-in;cursor:zoom-in}.zoomed .gslide-image img.zoomable{cursor:-webkit-grab;cursor:grab}.gslide-inline{max-height:95vh}.gslide-external{max-height:100vh}.gslide-description.description-left,.gslide-description.description-right{max-width:275px}.glightbox-open{height:auto}.goverlay{background:rgba(0,0,0,.92)}.glightbox-clean .gslide-media{-webkit-box-shadow:1px 2px 9px 0 rgba(0,0,0,.65);box-shadow:1px 2px 9px 0 rgba(0,0,0,.65)}.glightbox-clean .description-left .gdesc-inner,.glightbox-clean .description-right .gdesc-inner{position:absolute;height:100%;overflow-y:auto}.glightbox-clean .gclose,.glightbox-clean .gnext,.glightbox-clean .gprev{background-color:rgba(0,0,0,.32)}.glightbox-clean .gclose:hover,.glightbox-clean .gnext:hover,.glightbox-clean .gprev:hover{background-color:rgba(0,0,0,.7)}.glightbox-clean .gprev{top:45%}.glightbox-clean .gnext{top:45%}}@media (min-width:992px){.glightbox-clean .gclose{opacity:.7;right:20px}}@media screen and (max-height:420px){.goverlay{background:#000}} \ No newline at end of file diff --git a/app/controllers/kanta_controller.rb b/app/controllers/kanta_controller.rb new file mode 100644 index 0000000..b4de40a --- /dev/null +++ b/app/controllers/kanta_controller.rb @@ -0,0 +1,7 @@ +class KantaController < ApplicationController + + def show + @image = Merged::Image.first + end + +end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 51926d9..43692ca 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -3,7 +3,7 @@ class MembersController < ApplicationController # GET /members def index - @members = Member.order(:name).page params[:page] + @members = Member.visible_scope.order(:name).page params[:page] end # GET /members/1 diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb index 4c8da16..54b1b31 100644 --- a/app/helpers/members_helper.rb +++ b/app/helpers/members_helper.rb @@ -1,11 +1,7 @@ module MembersHelper def picture_for(someone , classes = "") - if someone.picture.blank? - image = asset_url("no_image.png") - else - image = someone.picture.url - end + image = someones_path(someone) if someone.respond_to? :name alt = someone.name else @@ -14,6 +10,13 @@ module MembersHelper image_tag(image , alt: alt , class: classes ) end + def someones_path( someone ) + if someone.picture.blank? + asset_url("no_image.png") + else + someone.picture.url + end + end def stayed(member) return "Not arrived" if member.arrived.blank? text = member.arrived.to_s diff --git a/app/javascript/application.js b/app/javascript/application.js index beff742..a667dfe 100644 --- a/app/javascript/application.js +++ b/app/javascript/application.js @@ -1 +1,10 @@ -// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails +// Configure your import map in config/importmap.rb. +// Read more: https://github.com/rails/importmap-rails + +// Currently haml filter does not support modules. +// import and make global as workaround +// +// haml module syntax is really clunky, filing issue and hoping +// +import GLightbox from 'glightbox'; +globalThis.GLightbox = GLightbox; diff --git a/app/models/member.rb b/app/models/member.rb index dac3c83..3d9d750 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -1,6 +1,6 @@ class Member < ApplicationRecord - def self.default_scope + def self.visible_scope where.not(confirmed_at: nil).where.not(picture: nil) end diff --git a/app/models/picture.rb b/app/models/picture.rb index 0bd896c..1a6bc4b 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -5,5 +5,6 @@ class Picture < ApplicationRecord validates :text, length: { maximum: 80 } validates :happened, presence: true + validates :picture, presence: true end diff --git a/app/models/story.rb b/app/models/story.rb index e55ab4b..dff5458 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -5,6 +5,7 @@ class Story < ApplicationRecord validates :text, length: { minimum: 5 , maximum: 1000 } validates :header , length: { minimum: 5 , maximum: 400} + validates :picture, presence: true def name header diff --git a/app/views/kanta/_form.html.haml b/app/views/kanta/_form.html.haml new file mode 100644 index 0000000..99b17e7 --- /dev/null +++ b/app/views/kanta/_form.html.haml @@ -0,0 +1,10 @@ += 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 new file mode 100644 index 0000000..d2becac --- /dev/null +++ b/app/views/kanta/edit.html.haml @@ -0,0 +1,7 @@ +%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 new file mode 100644 index 0000000..fe2ed70 --- /dev/null +++ b/app/views/kanta/index.html.haml @@ -0,0 +1,19 @@ +%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 new file mode 100644 index 0000000..0524e57 --- /dev/null +++ b/app/views/kanta/new.html.haml @@ -0,0 +1,5 @@ +%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 new file mode 100644 index 0000000..f0c38ca --- /dev/null +++ b/app/views/kanta/show.html.haml @@ -0,0 +1,16 @@ +#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/app/views/layouts/application.haml b/app/views/layouts/application.haml index 9aa533a..160b7eb 100644 --- a/app/views/layouts/application.haml +++ b/app/views/layouts/application.haml @@ -27,7 +27,8 @@ = csp_meta_tag = stylesheet_link_tag "tailwind" = stylesheet_link_tag "application" - + = javascript_include_tag "opal_main" + = javascript_importmap_tags - if false %script{:src => "https://cdn.tailwindcss.com"} diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index b3699bb..5b47dfe 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -47,3 +47,7 @@ = link_to edit_picture_path(picture) do %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 Edit Picture +:javascript + document.addEventListener("DOMContentLoaded", function(event) { + const lightbox = GLightbox({ }); + }); diff --git a/app/views/merged/view/_section_pictures.haml b/app/views/merged/view/_section_pictures.haml index 668fce4..f2e8e77 100644 --- a/app/views/merged/view/_section_pictures.haml +++ b/app/views/merged/view/_section_pictures.haml @@ -1,3 +1,8 @@ .mx-20.grid.grid-cols-1.md:grid-cols-2.lg:grid-cols-3.2xl:grid-cols-4.gap-8.md:gap-12.lg:gap-16 - Picture.all.limit(4).each do |picture| = render "pictures/picture" , picture: picture + +:javascript + document.addEventListener("DOMContentLoaded", function(event) { + const lightbox = GLightbox({ }); + }); diff --git a/app/views/pictures/_picture.haml b/app/views/pictures/_picture.haml index faeb4c7..70f240d 100644 --- a/app/views/pictures/_picture.haml +++ b/app/views/pictures/_picture.haml @@ -5,7 +5,9 @@ = distance_of_time_in_words_to_now picture.happened ago .h-0.overflow-hidden.relative{class: "pt-[75%]"} - = picture_for( picture , "absolute top-0 left-0 w-full h-full inset-0 object-cover hover:scale-105 ease-in duration-500") + =link_to someones_path( picture ) , {class: :glightbox , + "data-glightbox" => "title: #{picture.text}" } do + = picture_for( picture , "absolute top-0 left-0 w-full h-full inset-0 object-cover hover:scale-105 ease-in duration-500") -unless picture.text.blank? .absolute.bottom-0.left-0.right-0.px-4.pb-1.bg-gray-800.opacity-70.transition-colors.group-hover:bg-black.group-hover:opacity-100 .text-center.mt-2.text-white= picture.text diff --git a/app/views/pictures/index.html.haml b/app/views/pictures/index.html.haml index e628376..242c9e7 100644 --- a/app/views/pictures/index.html.haml +++ b/app/views/pictures/index.html.haml @@ -1,3 +1,4 @@ + = paginate @pictures .flex.justify-end.mr-10 @@ -9,9 +10,12 @@ - @pictures.each do |picture| = render picture , picture: picture -%br - .flex.ml-20 = link_to new_picture_path do %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 New Picture + +:javascript + document.addEventListener("DOMContentLoaded", function(event) { + const lightbox = GLightbox({ }); + }); diff --git a/app/views/stories/_half.haml b/app/views/stories/_half.haml index dad801d..4ed9b29 100644 --- a/app/views/stories/_half.haml +++ b/app/views/stories/_half.haml @@ -1,5 +1,5 @@ %section.overflow-hidden.grid.grid-cols-1.m-5.md:m-12.lg:m-20.md:grid-cols-2 - %div + =link_to someones_path( story ) , {class: :glightbox } do = picture_for( story , "h-56 w-full object-cover sm:h-full") .p-8.md:p-12.lg:px-16.lg:py-24 .mx-auto.max-w-xl.text-center @@ -7,6 +7,7 @@ = story.header %h4.text-xl.mt-10.md:text-2xl = distance_of_time_in_words_to_now story.happened - ago + ago, by + = link_to story.member.name , main_app.member_path(story.member) , class: :underline .mt-8{ prose_classes } = markdown(story.text) diff --git a/app/views/stories/_pic.haml b/app/views/stories/_pic.haml index 15fa325..c2131dd 100644 --- a/app/views/stories/_pic.haml +++ b/app/views/stories/_pic.haml @@ -1,6 +1,7 @@ %section.flex.justify-center.p-8.flex-col.md:flex-row.m-20 .flex.items-center.h-40.md:h-60.lg:h-96.w-full.overflow-hidden{class: "lg:w-2/3"} - = picture_for(story ,"object-cover") + =link_to someones_path( story ) , {class: :glightbox } do + = picture_for(story ,"object-cover") .flex.items-center.w-full.max-w.px-6.mt-6.mx-auto{:class => "lg:w-1/3"} .flex-1 .text-center @@ -8,6 +9,7 @@ = story.header %h4.text-xl.mt-4.lg:mt-8.md:text-2xl = distance_of_time_in_words_to_now story.happened - ago + ago, by + = link_to story.member.name , main_app.member_path(story.member) , class: :underline .mt-3{ prose_classes } = markdown(story.text) diff --git a/app/views/stories/_text.haml b/app/views/stories/_text.haml index 13a1024..01a99dc 100644 --- a/app/views/stories/_text.haml +++ b/app/views/stories/_text.haml @@ -5,7 +5,9 @@ = story.header .text-xl.pb-6{ prose_classes } = distance_of_time_in_words_to_now story.happened - ago + ago, by + = link_to story.member.name , main_app.member_path(story.member) , class: :underline .max-w-full.mt-4.gap-16.columns-1.md:columns-2.lg:columns-3.xl:columns-4{ prose_classes } - = picture_for( story , "h-56 w-full object-cover sm:h-full") + =link_to someones_path( story ) , {class: :glightbox } do + = picture_for( story , "h-56 w-full object-cover sm:h-full") = markdown(story.text) diff --git a/app/views/stories/index.html.haml b/app/views/stories/index.html.haml index e157c9f..3beb9e1 100644 --- a/app/views/stories/index.html.haml +++ b/app/views/stories/index.html.haml @@ -14,3 +14,8 @@ = link_to new_story_path do %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 New Story + +:javascript + document.addEventListener("DOMContentLoaded", function(event) { + const lightbox = GLightbox({ }); + }); diff --git a/config/importmap.rb b/config/importmap.rb index 9d84985..a851295 100644 --- a/config/importmap.rb +++ b/config/importmap.rb @@ -1,3 +1,4 @@ # Pin npm packages by running ./bin/importmap pin "application", preload: true +pin "glightbox", to: "https://ga.jspm.io/npm:glightbox@3.2.0/dist/js/glightbox.min.js" diff --git a/config/initializers/opal.rb b/config/initializers/opal.rb new file mode 100644 index 0000000..aaba247 --- /dev/null +++ b/config/initializers/opal.rb @@ -0,0 +1,22 @@ +# Check out the full list of the available configuration options at +# https://github.com/opal/opal/blob/master/lib/opal/config.rb + +Rails.application.configure do + # We suggest keeping the configuration above as default for all environments, + # disabling some of them might slightly reduce the bundle size or reduce performance + # by degrading some ruby features. + config.opal.method_missing_enabled = true + config.opal.const_missing_enabled = true + config.opal.arity_check_enabled = true + config.opal.freezing_stubs_enabled = true + config.opal.dynamic_require_severity = :ignore + + # To enable passing assigns from the controller to the opal template handler + # change the following configuration to one of these values: + # + # - true # both locals and instance variables + # - :locals # only locals + # - :ivars # only instance variables + # + config.opal.assigns_in_templates = false +end diff --git a/config/routes.rb b/config/routes.rb index d5e869a..96bf0bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :kanta resources :pictures resources :stories diff --git a/lib/opal/rails/haml_filter.rb b/lib/opal/rails/haml_filter.rb new file mode 100644 index 0000000..6d41a8e --- /dev/null +++ b/lib/opal/rails/haml_filter.rb @@ -0,0 +1,19 @@ +require "haml" +require "haml/filters" +require "haml/filters/base" + +module Haml + class Filters + class Opal < Base + def compile(node) + temple = [:multi] + temple << [:static, ""] + temple + end + end + end +end + +Haml::Filters.registered[:opal] ||= Haml::Filters::Opal