rux-rails 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +1 -4
- data/README.md +3 -5
- data/lib/rux-rails/output_buffer.rb +13 -0
- data/lib/rux-rails/railtie.rb +8 -36
- data/lib/rux-rails/rux_loader.rb +7 -0
- data/lib/rux-rails/tag_builder.rb +2 -2
- data/lib/rux-rails/version.rb +1 -1
- data/lib/rux-rails.rb +4 -12
- data/rux-rails.gemspec +2 -1
- 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/config/application.rb +4 -0
- data/spec/dummy/log/test.log +3511 -0
- data/spec/html_safety_spec.rb +10 -0
- data/spec/spec_helper.rb +57 -8
- metadata +27 -16
- 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/safe_buffer.rb +0 -13
- data/spec/dummy/app/components/button.rb +0 -15
- data/spec/dummy/app/components/home_component.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b7a679a3ee90ae6b529db0784f4b94012e90bbb25830520cdfd9e78d7ceb799
|
4
|
+
data.tar.gz: 43babb6951b66022a80188c441f3a8ef052255d15c7d95e38814c2af896e4a04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bebca880ba79a25eed37a0b1bb5fd8052a03d7a580301a5adc1ee8cab9e79b317cae245696521f98b3fd363ab916eae585796244330c3096711516fdf304a6f4
|
7
|
+
data.tar.gz: 9bdc46fd60266214a5eae8c4a83181625bf1ba87cdd33b512ad766169344618c83801203535c5490e9060ac8ea9cfa7b2db82f813039939497695de5ef5b1c0c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.5.0
|
2
|
+
* Extract monkeypatches into the [onload gem](https://github.com/camertron/onload).
|
3
|
+
* Upgrade to rux v1.2.
|
4
|
+
* Drop official support for Rails < 6 and Ruby < 3.
|
5
|
+
|
1
6
|
## 1.4.0
|
2
7
|
* Make rux-rails safe to load in production.
|
3
8
|
- All the monkeypatches to `Kernel`, etc are now only loaded if `config.rux.transpile` is `true`.
|
data/Gemfile
CHANGED
@@ -2,17 +2,14 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
gem 'rux', github: 'camertron/rux' # path: '/Users/cdutro/workspace/rux'
|
6
|
-
|
7
5
|
group :development, :test do
|
8
|
-
gem 'pry-byebug'
|
9
6
|
gem 'rake'
|
7
|
+
gem 'debug'
|
10
8
|
end
|
11
9
|
|
12
10
|
group :development do
|
13
11
|
gem 'appraisal'
|
14
12
|
gem 'benchmark-ips'
|
15
|
-
gem 'rails', '~> 7.0'
|
16
13
|
gem 'slim', '~> 5.0'
|
17
14
|
end
|
18
15
|
|
data/README.md
CHANGED
@@ -81,11 +81,9 @@ In my humble opinion, the rux version:
|
|
81
81
|
|
82
82
|
Integrating rux into your Rails app is pretty straightforward.
|
83
83
|
|
84
|
-
1. Add rux-rails to
|
84
|
+
1. Add rux-rails to your Gemfile, eg:
|
85
85
|
```ruby
|
86
|
-
|
87
|
-
gem 'rux-rails', '~> 1.0'
|
88
|
-
end
|
86
|
+
gem 'rux-rails', '~> 1.0'
|
89
87
|
```
|
90
88
|
1. Run `bundle install`
|
91
89
|
1. ... that's it.
|
@@ -104,7 +102,7 @@ config.rux.transpile = false
|
|
104
102
|
|
105
103
|
### Production Environment
|
106
104
|
|
107
|
-
By
|
105
|
+
By default, `config.rux.transpile` is set to `false` in the production environment, which means rux-rails' monkeypatches to `Kernel`, etc aren't loaded in production (which is a good thing). You could choose to turn it on, but automatic transpilation of .rux files is disabled automatically in the production environment for the same reasons the asset pipeline is disabled. Your view components (and static assets) don't change once deployed, so it's more efficient to precompile (or pre-transpile) them before deploying. Rux-rails comes with a handy rake task that can pre-transpile all your .rux templates:
|
108
106
|
|
109
107
|
```bash
|
110
108
|
bundle exec rake rux:transpile
|
data/lib/rux-rails/railtie.rb
CHANGED
@@ -1,38 +1,22 @@
|
|
1
1
|
require 'rails/railtie'
|
2
|
-
|
3
|
-
require 'active_support'
|
4
|
-
require 'active_support/isolated_execution_state' if ActiveSupport::VERSION::MAJOR > 6
|
2
|
+
require 'onload'
|
5
3
|
|
6
4
|
module RuxRails
|
7
5
|
class Railtie < Rails::Railtie
|
8
6
|
config.rux = ActiveSupport::OrderedOptions.new
|
9
7
|
|
10
|
-
initializer 'rux-rails.initialize', before:
|
8
|
+
initializer 'rux-rails.initialize', before: 'onload.initialize' do |app|
|
9
|
+
ViewComponent::Base.send(:include, RuxRails::Components)
|
10
|
+
|
11
11
|
if config.rux.transpile.nil? && (Rails.env.development? || Rails.env.test?)
|
12
12
|
config.rux.transpile = true
|
13
|
+
Onload.enabled = true
|
14
|
+
else
|
15
|
+
Onload.enabled = config.rux.transpile
|
13
16
|
end
|
14
17
|
|
15
|
-
RuxRails.transpile_on_load = -> () { config.rux.transpile }
|
16
|
-
|
17
18
|
if config.rux.transpile
|
18
|
-
|
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
|
19
|
+
Onload.register('.rux', RuxRails::RuxLoader)
|
36
20
|
end
|
37
21
|
|
38
22
|
ActionView::Template.register_template_handler(
|
@@ -43,18 +27,6 @@ module RuxRails
|
|
43
27
|
app.config.eager_load_paths << library_path
|
44
28
|
app.config.autoload_paths << library_path
|
45
29
|
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
30
|
end
|
59
31
|
|
60
32
|
rake_tasks do
|
data/lib/rux-rails/version.rb
CHANGED
data/lib/rux-rails.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module RuxRails
|
2
2
|
autoload :Components, 'rux-rails/components'
|
3
|
-
autoload :
|
3
|
+
autoload :OutputBuffer, 'rux-rails/output_buffer'
|
4
|
+
autoload :RuxLoader, 'rux-rails/rux_loader'
|
4
5
|
autoload :TagBuilder, 'rux-rails/tag_builder'
|
5
6
|
autoload :TemplateHandler, 'rux-rails/template_handler'
|
6
7
|
autoload :Visitor, 'rux-rails/visitor'
|
@@ -16,23 +17,14 @@ module RuxRails
|
|
16
17
|
def tag_builder
|
17
18
|
@tag_builder ||= TagBuilder.new
|
18
19
|
end
|
19
|
-
|
20
|
-
def transpile_on_load?
|
21
|
-
transpile_on_load.call
|
22
|
-
end
|
23
20
|
end
|
24
21
|
|
25
|
-
self.transpile_on_load =
|
22
|
+
self.transpile_on_load = true
|
26
23
|
end
|
27
24
|
|
28
25
|
|
29
26
|
require 'rux'
|
30
27
|
require 'rux-rails/railtie'
|
31
28
|
|
32
|
-
# require both of these to support multiple versions of view_component
|
33
|
-
require 'view_component'
|
34
|
-
require 'view_component/engine'
|
35
|
-
|
36
|
-
ViewComponent::Base.send(:include, RuxRails::Components)
|
37
29
|
Rux.tag_builder = RuxRails.tag_builder
|
38
|
-
Rux.buffer = RuxRails::
|
30
|
+
Rux.buffer = RuxRails::OutputBuffer
|
data/rux-rails.gemspec
CHANGED
@@ -10,9 +10,10 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = s.summary = 'Rux view components on Rails.'
|
11
11
|
s.platform = Gem::Platform::RUBY
|
12
12
|
|
13
|
-
s.add_dependency 'rux', '~> 1.
|
13
|
+
s.add_dependency 'rux', '~> 1.2'
|
14
14
|
s.add_dependency 'railties', '>= 5.0'
|
15
15
|
s.add_dependency 'view_component', '>= 2', '< 4'
|
16
|
+
s.add_dependency 'onload', '~> 1.0'
|
16
17
|
|
17
18
|
s.require_path = 'lib'
|
18
19
|
|
@@ -2,7 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe HomeController, type: :request do
|
4
4
|
describe '#index' do
|
5
|
-
|
5
|
+
before(:each) do
|
6
|
+
# Force a recompile to avoid test pollution
|
7
|
+
HomeComponent.compile
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'transpiles the file' do
|
6
11
|
get '/'
|
7
12
|
|
8
13
|
expect(response).to have_http_status(:ok)
|
@@ -10,5 +15,36 @@ describe HomeController, type: :request do
|
|
10
15
|
have_selector("div.container img[src='/images/cat.png'] + button", text: "Click Me!")
|
11
16
|
)
|
12
17
|
end
|
18
|
+
|
19
|
+
it "allows hot reloading" do
|
20
|
+
get "/"
|
21
|
+
|
22
|
+
expect(response).to have_http_status(:ok)
|
23
|
+
expect(response.body).to(
|
24
|
+
have_selector(".container", text: "Click Me!")
|
25
|
+
)
|
26
|
+
|
27
|
+
new_contents = <<~RUX
|
28
|
+
class HomeComponent < ViewComponent::Base
|
29
|
+
def call
|
30
|
+
<div class="container">
|
31
|
+
<Image src="cat.png" size="40" />
|
32
|
+
<Button outline={true} disabled size={:large}>
|
33
|
+
Click if you dare
|
34
|
+
</Button>
|
35
|
+
</div>
|
36
|
+
end
|
37
|
+
end
|
38
|
+
RUX
|
39
|
+
|
40
|
+
with_file_contents(Rails.root.join(*%w[app components home_component.rux]), new_contents) do
|
41
|
+
get "/"
|
42
|
+
|
43
|
+
expect(response).to have_http_status(:ok)
|
44
|
+
expect(response.body).to(
|
45
|
+
have_selector(".container", text: "Click if you dare")
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
13
49
|
end
|
14
50
|
end
|