an opal experiment

This commit is contained in:
Torsten 2023-02-05 16:18:18 +02:00
parent 549ccfad5d
commit 50874df46f
14 changed files with 127 additions and 1 deletions

View File

@ -32,6 +32,8 @@ gem "devise-async"
gem "passenger" , "6.0.15" , require: "phusion_passenger/rack_handler"
gem "bootsnap", require: false
gem "opal-rails"
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 ]

View File

@ -262,6 +262,18 @@ GEM
mustache
nokogiri (~> 1.7)
sanitize
opal (1.7.2)
ast (>= 2.3.0)
parser (~> 3.0, >= 3.0.3.2)
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)
parser (3.2.0.0)
@ -435,6 +447,7 @@ DEPENDENCIES
kaminari
merged!
mina
opal-rails
passenger (= 6.0.15)
pg (~> 1.1)
pundit (~> 2.3)

View File

@ -3,3 +3,4 @@
//= link_tree ../../javascript .js
//= link_tree ../../../vendor/javascript .js
//= link_tree ../builds
//= link_directory ../javascript .js

View File

@ -0,0 +1 @@
require "opal"

View File

@ -0,0 +1,7 @@
class KantaController < ApplicationController
def show
@image = Merged::Image.first
end
end

View File

@ -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'

View File

@ -0,0 +1,7 @@
%h1 Editing kantum
= render 'form'
= link_to 'Show', @kantum
\|
= link_to 'Back', kanta_path

View File

@ -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

View File

@ -0,0 +1,5 @@
%h1 New kantum
= render 'form'
= link_to 'Back', kanta_path

View File

@ -0,0 +1,18 @@
.flex.justify-center
.flex.flex-col
= @image.attributes
%a.underline{ '@click' => "hi"}
Back
:opal
class Kanta
def initialize(hash)
hash.each do |k,v|
puts k
puts v
end
end
end
kanta = Kanta.new(bg: 'bg-cyan-200')

View File

@ -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"}

View File

@ -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

View File

@ -1,4 +1,5 @@
Rails.application.routes.draw do
resources :kanta
resources :pictures
resources :stories

View File

@ -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, "<script type='text/javascript'>\n"]
temple << [:static, ::Opal.compile(node.value[:text]) ]
temple << [:static, "\n</script>"]
temple
end
end
end
end
Haml::Filters.registered[:opal] ||= Haml::Filters::Opal