rux-rails 1.4.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/Gemfile +4 -4
- data/README.md +59 -5
- data/lib/rux-rails/engine.rb +46 -0
- data/lib/rux-rails/output_buffer.rb +13 -0
- data/lib/rux-rails/rux_loader.rb +7 -0
- data/lib/rux-rails/tag_builder.rb +2 -2
- data/lib/rux-rails/tasks/transpile.rake +11 -10
- data/lib/rux-rails/version.rb +1 -1
- data/lib/rux-rails.rb +7 -12
- data/rux-rails.gemspec +4 -2
- data/spec/components/rails/button_spec.rb +18 -0
- data/spec/components/rails/button_to_spec.rb +24 -0
- data/spec/components/rails/content_tag_spec.rb +13 -0
- data/spec/components/rails/form_with_spec.rb +20 -0
- data/spec/components/rails/hidden_field_spec.rb +11 -0
- data/spec/components/rails/label_spec.rb +21 -0
- data/spec/components/rails/link_to_spec.rb +16 -0
- data/spec/components/rails/password_field_spec.rb +11 -0
- data/spec/components/rails/text_field_spec.rb +11 -0
- data/spec/components/rux/component_spec.rb +9 -0
- data/spec/controllers/home_controller_spec.rb +37 -1
- data/spec/dummy/app/components/html_safety_component.rb +13 -0
- data/spec/dummy/app/components/html_safety_component.rux +9 -0
- data/spec/dummy/app/components/image.rux +16 -0
- data/spec/dummy/config/application.rb +4 -0
- data/spec/dummy/log/test.log +792 -131
- data/spec/dummy/tmp/local_secret.txt +1 -0
- data/spec/html_safety_spec.rb +10 -0
- data/spec/spec_helper.rb +28 -10
- metadata +56 -23
- data/lib/rux-rails/components/audio.rb +0 -18
- data/lib/rux-rails/components/image.rb +0 -18
- data/lib/rux-rails/components/video.rb +0 -18
- data/lib/rux-rails/components.rb +0 -5
- data/lib/rux-rails/core_ext/kernel.rb +0 -67
- data/lib/rux-rails/core_ext/kernel_zeitwerk.rb +0 -63
- data/lib/rux-rails/ext/activesupport/dependencies.rb +0 -47
- data/lib/rux-rails/ext/bootsnap/autoload.rb +0 -27
- data/lib/rux-rails/ext/zeitwerk/loader.rb +0 -35
- data/lib/rux-rails/railtie.rb +0 -64
- data/lib/rux-rails/safe_buffer.rb +0 -13
- data/spec/dummy/app/components/button.rb +0 -15
- data/spec/dummy/app/components/home_component.rb +0 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2b59303eb0458badf9c071ca4daf818aea0197168a8f5e982f7259aac5b6a05c9782c9f3426636b3058fab160acd15bb29a2e4a1f6b9c037c2afcd6466b5530a
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
require 'pry-byebug'
|
|
2
|
-
|
|
3
1
|
ENV['RAILS_ENV'] ||= 'test'
|
|
4
2
|
|
|
5
3
|
require 'rails'
|
|
6
|
-
require 'rux-rails'
|
|
7
|
-
|
|
8
4
|
require 'action_controller/railtie'
|
|
5
|
+
require 'rux-rails'
|
|
9
6
|
|
|
10
7
|
Dir.chdir(File.join(*%w(spec dummy))) do
|
|
11
8
|
require File.expand_path(File.join(*%w(dummy config application)), __dir__)
|
|
@@ -14,13 +11,34 @@ end
|
|
|
14
11
|
|
|
15
12
|
require 'rspec/rails'
|
|
16
13
|
|
|
17
|
-
module
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
module RuxRails
|
|
15
|
+
module SpecHelpers
|
|
16
|
+
extend RSpec::SharedContext
|
|
17
|
+
include Capybara::RSpecMatchers
|
|
18
|
+
|
|
19
|
+
let(:app) { Rails.application }
|
|
20
|
+
|
|
21
|
+
before(:each) do
|
|
22
|
+
Dir.glob("spec/dummy/app/components/*.rb").each do |f|
|
|
23
|
+
File.unlink(f)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def view_context
|
|
28
|
+
respond_to?(:vc_test_view_context) ? vc_test_view_context : vc_test_controller.view_context
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def with_file_contents(path, contents)
|
|
32
|
+
old_contents = ::File.read(path)
|
|
33
|
+
::File.write(path, contents)
|
|
34
|
+
yield
|
|
35
|
+
ensure
|
|
36
|
+
::File.write(path, old_contents)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
21
39
|
end
|
|
22
40
|
|
|
23
41
|
RSpec.configure do |config|
|
|
24
|
-
config.include(SpecHelpers)
|
|
25
|
-
config.include
|
|
42
|
+
config.include(RuxRails::SpecHelpers)
|
|
43
|
+
config.include ViewComponent::TestHelpers, type: :component
|
|
26
44
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rux-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cameron Dutro
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-10-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rux
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.
|
|
19
|
+
version: '1.3'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.
|
|
26
|
+
version: '1.3'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: railties
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -47,7 +47,7 @@ dependencies:
|
|
|
47
47
|
version: '2'
|
|
48
48
|
- - "<"
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
|
-
version: '
|
|
50
|
+
version: '5'
|
|
51
51
|
type: :runtime
|
|
52
52
|
prerelease: false
|
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -57,7 +57,35 @@ dependencies:
|
|
|
57
57
|
version: '2'
|
|
58
58
|
- - "<"
|
|
59
59
|
- !ruby/object:Gem::Version
|
|
60
|
-
version: '
|
|
60
|
+
version: '5'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: onload
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - "~>"
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '1.1'
|
|
68
|
+
type: :runtime
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - "~>"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.1'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: use_context
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.2'
|
|
82
|
+
type: :runtime
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '1.2'
|
|
61
89
|
description: Rux view components on Rails.
|
|
62
90
|
email:
|
|
63
91
|
- camertron@gmail.com
|
|
@@ -71,30 +99,33 @@ files:
|
|
|
71
99
|
- README.md
|
|
72
100
|
- Rakefile
|
|
73
101
|
- lib/rux-rails.rb
|
|
74
|
-
- lib/rux-rails/
|
|
75
|
-
- lib/rux-rails/
|
|
76
|
-
- lib/rux-rails/
|
|
77
|
-
- lib/rux-rails/components/video.rb
|
|
78
|
-
- lib/rux-rails/core_ext/kernel.rb
|
|
79
|
-
- lib/rux-rails/core_ext/kernel_zeitwerk.rb
|
|
80
|
-
- lib/rux-rails/ext/activesupport/dependencies.rb
|
|
81
|
-
- lib/rux-rails/ext/bootsnap/autoload.rb
|
|
82
|
-
- lib/rux-rails/ext/zeitwerk/loader.rb
|
|
83
|
-
- lib/rux-rails/railtie.rb
|
|
84
|
-
- lib/rux-rails/safe_buffer.rb
|
|
102
|
+
- lib/rux-rails/engine.rb
|
|
103
|
+
- lib/rux-rails/output_buffer.rb
|
|
104
|
+
- lib/rux-rails/rux_loader.rb
|
|
85
105
|
- lib/rux-rails/tag_builder.rb
|
|
86
106
|
- lib/rux-rails/tasks/transpile.rake
|
|
87
107
|
- lib/rux-rails/template_handler.rb
|
|
88
108
|
- lib/rux-rails/version.rb
|
|
89
109
|
- lib/rux-rails/visitor.rb
|
|
90
110
|
- rux-rails.gemspec
|
|
111
|
+
- spec/components/rails/button_spec.rb
|
|
112
|
+
- spec/components/rails/button_to_spec.rb
|
|
113
|
+
- spec/components/rails/content_tag_spec.rb
|
|
114
|
+
- spec/components/rails/form_with_spec.rb
|
|
115
|
+
- spec/components/rails/hidden_field_spec.rb
|
|
116
|
+
- spec/components/rails/label_spec.rb
|
|
117
|
+
- spec/components/rails/link_to_spec.rb
|
|
118
|
+
- spec/components/rails/password_field_spec.rb
|
|
119
|
+
- spec/components/rails/text_field_spec.rb
|
|
120
|
+
- spec/components/rux/component_spec.rb
|
|
91
121
|
- spec/controllers/home_controller_spec.rb
|
|
92
122
|
- spec/dummy/app/assets/config/manifest.js
|
|
93
123
|
- spec/dummy/app/assets/images/cat.png
|
|
94
|
-
- spec/dummy/app/components/button.rb
|
|
95
124
|
- spec/dummy/app/components/button.rux
|
|
96
|
-
- spec/dummy/app/components/home_component.rb
|
|
97
125
|
- spec/dummy/app/components/home_component.rux
|
|
126
|
+
- spec/dummy/app/components/html_safety_component.rb
|
|
127
|
+
- spec/dummy/app/components/html_safety_component.rux
|
|
128
|
+
- spec/dummy/app/components/image.rux
|
|
98
129
|
- spec/dummy/app/controllers/application_controller.rb
|
|
99
130
|
- spec/dummy/app/controllers/home_controller.rb
|
|
100
131
|
- spec/dummy/app/views/home/index.html.ruxt
|
|
@@ -103,11 +134,13 @@ files:
|
|
|
103
134
|
- spec/dummy/config/routes.rb
|
|
104
135
|
- spec/dummy/config/secrets.yml
|
|
105
136
|
- spec/dummy/log/test.log
|
|
137
|
+
- spec/dummy/tmp/local_secret.txt
|
|
138
|
+
- spec/html_safety_spec.rb
|
|
106
139
|
- spec/spec_helper.rb
|
|
107
140
|
homepage: http://github.com/camertron/rux-rails
|
|
108
141
|
licenses: []
|
|
109
142
|
metadata: {}
|
|
110
|
-
post_install_message:
|
|
143
|
+
post_install_message:
|
|
111
144
|
rdoc_options: []
|
|
112
145
|
require_paths:
|
|
113
146
|
- lib
|
|
@@ -122,8 +155,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
122
155
|
- !ruby/object:Gem::Version
|
|
123
156
|
version: '0'
|
|
124
157
|
requirements: []
|
|
125
|
-
rubygems_version: 3.
|
|
126
|
-
signing_key:
|
|
158
|
+
rubygems_version: 3.5.22
|
|
159
|
+
signing_key:
|
|
127
160
|
specification_version: 4
|
|
128
161
|
summary: Rux view components on Rails.
|
|
129
162
|
test_files: []
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module RuxRails
|
|
2
|
-
module Components
|
|
3
|
-
class Audio < ViewComponent::Base
|
|
4
|
-
include ActionView::Helpers::AssetUrlHelper
|
|
5
|
-
|
|
6
|
-
attr_reader :src, :params
|
|
7
|
-
|
|
8
|
-
def initialize(src:, **params)
|
|
9
|
-
@src = src
|
|
10
|
-
@params = params
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def call
|
|
14
|
-
audio_tag(src, **params)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module RuxRails
|
|
2
|
-
module Components
|
|
3
|
-
class Image < ViewComponent::Base
|
|
4
|
-
include ActionView::Helpers::AssetUrlHelper
|
|
5
|
-
|
|
6
|
-
attr_reader :src, :params
|
|
7
|
-
|
|
8
|
-
def initialize(src:, **params)
|
|
9
|
-
@src = src
|
|
10
|
-
@params = params
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def call
|
|
14
|
-
image_tag(src, **params)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module RuxRails
|
|
2
|
-
module Components
|
|
3
|
-
class Video < ViewComponent::Base
|
|
4
|
-
include ActionView::Helpers::AssetUrlHelper
|
|
5
|
-
|
|
6
|
-
attr_reader :src, :params
|
|
7
|
-
|
|
8
|
-
def initialize(src:, **params)
|
|
9
|
-
@src = src
|
|
10
|
-
@params = params
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def call
|
|
14
|
-
video_tag(src, **params)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
data/lib/rux-rails/components.rb
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
module RuxRails
|
|
2
|
-
module LoadPatch
|
|
3
|
-
def load(file, *args)
|
|
4
|
-
# ActiveSupport::Dependencies adds an extra .rb to the end
|
|
5
|
-
if file.end_with?('.rux.rb')
|
|
6
|
-
file = file.chomp('.rb')
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
if file.end_with?('.rux')
|
|
10
|
-
tmpl = Rux::File.new(file)
|
|
11
|
-
tmpl.write if RuxRails.transpile_on_load?
|
|
12
|
-
|
|
13
|
-
return super(tmpl.default_outfile, *args)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
super(file, *args)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
module RequirePatch
|
|
21
|
-
def require(file)
|
|
22
|
-
# check to see if there's a .rux file somewhere on the load path
|
|
23
|
-
path = nil
|
|
24
|
-
rux_file = file.end_with?('.rux') ? file : "#{file}.rux"
|
|
25
|
-
|
|
26
|
-
if File.absolute_path(rux_file) == rux_file && File.exist?(rux_file)
|
|
27
|
-
path = rux_file
|
|
28
|
-
elsif rux_file.start_with?(".#{File::SEPARATOR}")
|
|
29
|
-
abs_path = File.expand_path(rux_file)
|
|
30
|
-
path = abs_path if File.exist?(abs_path)
|
|
31
|
-
else
|
|
32
|
-
$LOAD_PATH.each do |lp|
|
|
33
|
-
check_path = File.expand_path(File.join(lp, rux_file))
|
|
34
|
-
|
|
35
|
-
if File.exist?(check_path)
|
|
36
|
-
path = check_path
|
|
37
|
-
break
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
return super(file) unless path
|
|
43
|
-
return false if $LOADED_FEATURES.include?(path)
|
|
44
|
-
|
|
45
|
-
# Must call the Kernel.load class method here because that's the one
|
|
46
|
-
# activesupport doesn't mess with, and in fact the one activesupport
|
|
47
|
-
# itself uses to actually load files. In case you were curious,
|
|
48
|
-
# activesupport redefines Object#load and Object#require i.e. the
|
|
49
|
-
# instance versions that get inherited by all other objects. Yeah,
|
|
50
|
-
# it's pretty awful stuff.
|
|
51
|
-
Kernel.load(path)
|
|
52
|
-
$LOADED_FEATURES << path
|
|
53
|
-
|
|
54
|
-
return true
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
module Kernel
|
|
60
|
-
class << self
|
|
61
|
-
prepend RuxRails::LoadPatch
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
class Object
|
|
66
|
-
prepend RuxRails::RequirePatch
|
|
67
|
-
end
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
require 'zeitwerk'
|
|
2
|
-
|
|
3
|
-
module Kernel
|
|
4
|
-
alias_method :rux_orig_require, :require
|
|
5
|
-
alias_method :rux_orig_load, :load
|
|
6
|
-
|
|
7
|
-
def load(file, *args)
|
|
8
|
-
if File.extname(file) == '.rux'
|
|
9
|
-
tmpl = Rux::File.new(file)
|
|
10
|
-
tmpl.write if RuxRails.transpile_on_load?
|
|
11
|
-
|
|
12
|
-
# I don't understand why, but it's necessary to delete the constant
|
|
13
|
-
# in order to load the .ruxc file. Otherwise you get an error about
|
|
14
|
-
# an uninitialized constant, and it's like... yeah, I _know_ it's
|
|
15
|
-
# uninitialized, that's why I'm loading this file. Whatevs.
|
|
16
|
-
loader = Zeitwerk::Registry.loader_for(file)
|
|
17
|
-
parent, cname = loader.send(:autoloads)[file]
|
|
18
|
-
parent.send(:remove_const, cname)
|
|
19
|
-
|
|
20
|
-
return rux_orig_load(tmpl.default_outfile, *args)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
rux_orig_load(file, *args)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def require(file)
|
|
27
|
-
path = nil
|
|
28
|
-
loader = Zeitwerk::Registry.loader_for(file)
|
|
29
|
-
rux_file = file.end_with?('.rux') ? file : "#{file}.rux"
|
|
30
|
-
|
|
31
|
-
if File.absolute_path(rux_file) == rux_file && File.exist?(rux_file)
|
|
32
|
-
path = rux_file
|
|
33
|
-
elsif rux_file.start_with?(".#{File::SEPARATOR}")
|
|
34
|
-
abs_path = File.expand_path(rux_file)
|
|
35
|
-
path = abs_path if File.exist?(abs_path)
|
|
36
|
-
else
|
|
37
|
-
$LOAD_PATH.each do |lp|
|
|
38
|
-
check_path = File.expand_path(File.join(lp, rux_file))
|
|
39
|
-
|
|
40
|
-
if File.exist?(check_path)
|
|
41
|
-
path = check_path
|
|
42
|
-
break
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
unless path
|
|
48
|
-
# This will be either Ruby's original require or bootsnap's monkeypatched
|
|
49
|
-
# require in setups that use bootsnap. Lord help us with all these layers
|
|
50
|
-
# of patches.
|
|
51
|
-
return rux_orig_require(file)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
return false if $LOADED_FEATURES.include?(path)
|
|
55
|
-
|
|
56
|
-
load path
|
|
57
|
-
$LOADED_FEATURES << path
|
|
58
|
-
|
|
59
|
-
loader.on_file_autoloaded(path) if loader
|
|
60
|
-
|
|
61
|
-
return true
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require 'active_support/dependencies'
|
|
2
|
-
|
|
3
|
-
module RuxRails
|
|
4
|
-
module ActiveSupportDependenciesPatch
|
|
5
|
-
# Allow activesupport to find .rux files.
|
|
6
|
-
def search_for_file(path_suffix)
|
|
7
|
-
path_suffix_with_ext = path_suffix.sub(/(\.rux)?$/, '.rux'.freeze)
|
|
8
|
-
|
|
9
|
-
autoload_paths.each do |root|
|
|
10
|
-
path = File.join(root, path_suffix_with_ext)
|
|
11
|
-
return path if File.file?(path)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
super
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# For some reason, using autoload and a patched Kernel#load doesn't work
|
|
18
|
-
# by itself for automatically loading .rux files. Due to what I can only
|
|
19
|
-
# surmise is one of the side-effects of autoload, requiring any .rux file
|
|
20
|
-
# that's been marked by autoload will result in a NameError, i.e. Ruby
|
|
21
|
-
# reports the constant isn't defined. Pretty surprising considering we're
|
|
22
|
-
# literally in the process of _defining_ that constant. The trick is to
|
|
23
|
-
# essentially undo the autoload by removing the constant just before
|
|
24
|
-
# loading the .rux file that defines it.
|
|
25
|
-
def load_missing_constant(from_mod, const_name)
|
|
26
|
-
if require_path = from_mod.autoload?(const_name)
|
|
27
|
-
path = search_for_file(require_path)
|
|
28
|
-
|
|
29
|
-
if path && path.end_with?('.rux')
|
|
30
|
-
from_mod.send(:remove_const, const_name)
|
|
31
|
-
require require_path
|
|
32
|
-
return from_mod.const_get(const_name)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
super
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
module ActiveSupport
|
|
42
|
-
module Dependencies
|
|
43
|
-
class << self
|
|
44
|
-
prepend RuxRails::ActiveSupportDependenciesPatch
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module RuxRails
|
|
2
|
-
module BootsnapAutoloadPatch
|
|
3
|
-
def autoload(const, path)
|
|
4
|
-
# Bootsnap monkeypatches Module.autoload in order to leverage its load
|
|
5
|
-
# path cache, which effectively converts a relative path into an absolute
|
|
6
|
-
# one without incurring the cost of searching the load path.
|
|
7
|
-
# Unfortunately, if a .rux file has already been transpiled, the cache
|
|
8
|
-
# seems to always return the corresponding .rb file. Bootsnap's autoload
|
|
9
|
-
# patch passes the .rb file to Ruby's original autoload, effectively
|
|
10
|
-
# wiping out the previous autoload that pointed to the .rux file. To
|
|
11
|
-
# fix this we have to intercept the cache lookup and force autoloading
|
|
12
|
-
# the .rux file if one exists.
|
|
13
|
-
cached_path = Bootsnap::LoadPathCache.load_path_cache.find(path)
|
|
14
|
-
cached_rux_path = "#{cached_path.chomp('.rb')}.rux"
|
|
15
|
-
|
|
16
|
-
if File.file?(cached_rux_path)
|
|
17
|
-
autoload_without_bootsnap(const, cached_rux_path)
|
|
18
|
-
else
|
|
19
|
-
super
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
class Module
|
|
26
|
-
prepend RuxRails::BootsnapAutoloadPatch
|
|
27
|
-
end
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
require 'zeitwerk'
|
|
2
|
-
|
|
3
|
-
module RuxRails
|
|
4
|
-
module ZeitwerkLoaderPatch
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
def ruby?(path)
|
|
8
|
-
super || path.end_with?('.rux')
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def autoload_file(parent, cname, file)
|
|
12
|
-
if file.end_with?('.rux')
|
|
13
|
-
# Some older versions of Zeitwerk very naïvely try to remove only the
|
|
14
|
-
# last 3 characters in an attempt to strip off the .rb file extension,
|
|
15
|
-
# while newer ones only remove it if it's actually there. This line is
|
|
16
|
-
# necessary to remove the trailing leftover period for older versions,
|
|
17
|
-
# and remove the entire .rux extension for newer versions.
|
|
18
|
-
cname = cname.to_s.chomp('.').chomp('.rux').to_sym
|
|
19
|
-
else
|
|
20
|
-
# if there is a corresponding .rux file, autoload it instead of the .rb
|
|
21
|
-
# file
|
|
22
|
-
rux_file = "#{file.chomp('.rb')}.rux"
|
|
23
|
-
file = rux_file if File.exist?(rux_file)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
super
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
module Zeitwerk
|
|
32
|
-
class Loader
|
|
33
|
-
prepend RuxRails::ZeitwerkLoaderPatch
|
|
34
|
-
end
|
|
35
|
-
end
|
data/lib/rux-rails/railtie.rb
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
require 'rails/railtie'
|
|
2
|
-
|
|
3
|
-
require 'active_support'
|
|
4
|
-
require 'active_support/isolated_execution_state' if ActiveSupport::VERSION::MAJOR > 6
|
|
5
|
-
|
|
6
|
-
module RuxRails
|
|
7
|
-
class Railtie < Rails::Railtie
|
|
8
|
-
config.rux = ActiveSupport::OrderedOptions.new
|
|
9
|
-
|
|
10
|
-
initializer 'rux-rails.initialize', before: :set_autoload_paths do |app|
|
|
11
|
-
if config.rux.transpile.nil? && (Rails.env.development? || Rails.env.test?)
|
|
12
|
-
config.rux.transpile = true
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
RuxRails.transpile_on_load = -> () { config.rux.transpile }
|
|
16
|
-
|
|
17
|
-
if config.rux.transpile
|
|
18
|
-
if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled?
|
|
19
|
-
require 'rux-rails/core_ext/kernel_zeitwerk'
|
|
20
|
-
require 'rux-rails/ext/zeitwerk/loader'
|
|
21
|
-
|
|
22
|
-
RuxRails.zeitwerk_mode = true
|
|
23
|
-
else
|
|
24
|
-
require 'rux-rails/core_ext/kernel'
|
|
25
|
-
require 'rux-rails/ext/activesupport/dependencies'
|
|
26
|
-
|
|
27
|
-
RuxRails.zeitwerk_mode = false
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
begin
|
|
31
|
-
require 'bootsnap'
|
|
32
|
-
rescue LoadError
|
|
33
|
-
else
|
|
34
|
-
require 'rux-rails/ext/bootsnap/autoload'
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
ActionView::Template.register_template_handler(
|
|
39
|
-
:ruxt, RuxRails::TemplateHandler
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
Rux.library_paths.each do |library_path|
|
|
43
|
-
app.config.eager_load_paths << library_path
|
|
44
|
-
app.config.autoload_paths << library_path
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
if config.rux.transpile && app.config.file_watcher
|
|
48
|
-
paths = Set.new(app.config.eager_load_paths + app.config.autoload_paths)
|
|
49
|
-
|
|
50
|
-
dirs = paths.each_with_object({}) do |path, ret|
|
|
51
|
-
ret[path] = %w(rux)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
app.reloaders << app.config.file_watcher.new([], dirs) do
|
|
55
|
-
# empty block, watcher seems to need it?
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
rake_tasks do
|
|
61
|
-
load File.expand_path(File.join(*%w(. tasks transpile.rake)), __dir__)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
class Button < ViewComponent::Base
|
|
2
|
-
attr_reader(:outline, :size, :disabled)
|
|
3
|
-
|
|
4
|
-
def initialize(outline:, size:, disabled:)
|
|
5
|
-
@outline = outline
|
|
6
|
-
@size = size
|
|
7
|
-
@disabled = disabled
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def call
|
|
11
|
-
Rux.tag("button") {
|
|
12
|
-
content
|
|
13
|
-
}
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
class HomeComponent < ViewComponent::Base
|
|
2
|
-
def call
|
|
3
|
-
Rux.tag("div", { class: "container" }) {
|
|
4
|
-
Rux.create_buffer.tap { |_rux_buf_|
|
|
5
|
-
_rux_buf_ << render(Image.new(src: "cat.png", size: "40"))
|
|
6
|
-
_rux_buf_ << render(Button.new(outline: true, disabled: "true", size: :large)) {
|
|
7
|
-
"Click Me!"
|
|
8
|
-
}
|
|
9
|
-
}.to_s
|
|
10
|
-
}
|
|
11
|
-
end
|
|
12
|
-
end
|