frails 0.4.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.autotest +6 -0
  3. data/.gitignore +8 -1
  4. data/.rubocop.yml +10 -1
  5. data/Gemfile +6 -8
  6. data/Gemfile.lock +64 -109
  7. data/README.md +21 -29
  8. data/Rakefile +1 -1
  9. data/babel.config.js +12 -0
  10. data/bin/test +5 -3
  11. data/config.ru +9 -0
  12. data/frails.gemspec +5 -13
  13. data/index.js +10 -31
  14. data/lib/frails.rb +33 -9
  15. data/lib/frails/component.rb +16 -5
  16. data/lib/frails/component/{abstract_component.rb → abstract.rb} +11 -9
  17. data/lib/frails/component/{plain_component.rb → base.rb} +7 -3
  18. data/lib/frails/component/{react_component.rb → react.rb} +3 -5
  19. data/lib/frails/component/{react_component_renderer.rb → react_renderer.rb} +22 -16
  20. data/lib/frails/component/{component_renderer.rb → renderer.rb} +34 -5
  21. data/lib/frails/component/renderer_concerns.rb +10 -4
  22. data/lib/frails/component/test_helpers.rb +19 -0
  23. data/lib/frails/dev_server.rb +2 -2
  24. data/lib/frails/helper.rb +15 -17
  25. data/lib/frails/log_subscriber.rb +1 -1
  26. data/lib/frails/manifest.rb +3 -7
  27. data/lib/frails/monkey/action_view/abstract_renderer.rb +0 -2
  28. data/lib/frails/monkey/action_view/partial_renderer.rb +25 -6
  29. data/lib/frails/monkey/action_view/renderer.rb +6 -7
  30. data/lib/frails/monkey/action_view/template_renderer.rb +8 -1
  31. data/lib/frails/railtie.rb +5 -13
  32. data/lib/frails/side_load_assets.rb +8 -5
  33. data/lib/frails/utils.rb +22 -0
  34. data/lib/frails/version.rb +1 -1
  35. data/lib/tasks/frails.rake +1 -6
  36. data/package.json +13 -3
  37. data/package/__snapshots__/config.test.js.snap +10 -0
  38. data/package/components.js +34 -24
  39. data/package/config.js +38 -0
  40. data/package/config.test.js +7 -0
  41. data/package/side_load.js +7 -5
  42. data/yarn.lock +4283 -51
  43. metadata +28 -21
  44. data/.travis.yml +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 322669f68bd84081e8486c39f5fb28a531603a3a059044556c6d4ede45c13893
4
- data.tar.gz: 334028b2e58f8ecb973623f8a13cfe9cd1ec92a5d4eb8ff374570f279f01996c
3
+ metadata.gz: 98fa123377477094755a4c6fc64a5c36fe5e42c02574c73876f451d28d588438
4
+ data.tar.gz: 0e9751e40c879a040351437ec42adec6f6cc73938834ed18790d43cc967f3c14
5
5
  SHA512:
6
- metadata.gz: 4f98d83b83354a19a6d6469cc16704fcf1053623e0ff2862515c313795a65d9318eafe8d804aaf2852ff54c7a462f68eb6d1093292fe244c59e77eab74d50b06
7
- data.tar.gz: 6818327395fb917c763dc9d93179f95b39cf846b3c215583195885639d031e617a3bc3993450fb2ad780ac43efff7f519a856a469cba338088094103b56c3c27
6
+ metadata.gz: 4754ad21e2cbaf8176c0a6fdb2a824bd09789e884d39d798a47bfc0be9f9eed2da1ded0b24db669b1bdf27a666a7b4eff5047a015e4f0435d9755299ba12110a
7
+ data.tar.gz: 605eb4d15e7696c303d1d57d7af64a027132b0c02f1dcd0a9e7f9a78c1fff31834f1c8167859fca27d0fdd37cd387b6640bbe77c186151785b6f7e4bbc5c66f3
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ at.add_exception %r{^\./test/dummy}
5
+ at.add_exception %r{^\./test/internal/(?:log|public|tmp|app/assets)}
6
+ end
data/.gitignore CHANGED
@@ -8,4 +8,11 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
- *.log
11
+ *.log
12
+ .byebug_history
13
+ test/dummy/node_modules
14
+ test/dummy/tmp
15
+ test/dummy/log
16
+ test/internal/node_modules
17
+ test/internal/tmp
18
+ test/internal/log
@@ -1,12 +1,21 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.4
3
+ Exclude:
4
+ - test/dummy/**/*
5
+ - node_modules/**/*
3
6
  Style/Documentation:
4
7
  Enabled: false
5
8
  Style/ModuleFunction:
6
9
  Enabled: false
10
+ Style/ClassVars:
11
+ Enabled: false
7
12
  Style/ClassAndModuleChildren:
8
13
  Enabled: false
9
- Metrics/LineLength:
14
+ Naming/MethodParameterName:
15
+ Enabled: false
16
+ Metrics/MethodLength:
17
+ Max: 20
18
+ Layout/LineLength:
10
19
  Max: 100
11
20
  Layout/IndentationConsistency:
12
21
  EnforcedStyle: indented_internal_methods
data/Gemfile CHANGED
@@ -8,12 +8,10 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
8
8
  # development dependencies will be added by default to the :development group.
9
9
  gemspec
10
10
 
11
- # Declare any dependencies that are still in development here instead of in
12
- # your gemspec. These might include edge Rails or gems from your path or
13
- # Git. Remember to move these dependencies to your gemspec before releasing
14
- # your gem to rubygems.org.
15
-
16
- # To use a debugger
17
- # gem 'byebug', group: [:development, :test]
18
-
19
11
  gem 'rubocop', require: false
12
+ gem 'combustion'
13
+ gem 'minitest', '~> 5.0'
14
+ gem 'minitest-autotest'
15
+ gem 'minitest-focus'
16
+ gem 'autotest-suffix'
17
+ gem 'mocha'
@@ -1,161 +1,116 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frails (0.4.0)
4
+ frails (0.8.0)
5
+ activesupport (>= 6.0)
5
6
  nokogiri (>= 1.10.4)
6
7
  rack-proxy (>= 0.6.5)
7
- rails (>= 6.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (6.0.0)
13
- actionpack (= 6.0.0)
14
- nio4r (~> 2.0)
15
- websocket-driver (>= 0.6.1)
16
- actionmailbox (6.0.0)
17
- actionpack (= 6.0.0)
18
- activejob (= 6.0.0)
19
- activerecord (= 6.0.0)
20
- activestorage (= 6.0.0)
21
- activesupport (= 6.0.0)
22
- mail (>= 2.7.1)
23
- actionmailer (6.0.0)
24
- actionpack (= 6.0.0)
25
- actionview (= 6.0.0)
26
- activejob (= 6.0.0)
27
- mail (~> 2.5, >= 2.5.4)
28
- rails-dom-testing (~> 2.0)
29
- actionpack (6.0.0)
30
- actionview (= 6.0.0)
31
- activesupport (= 6.0.0)
32
- rack (~> 2.0)
12
+ actionpack (6.0.3.2)
13
+ actionview (= 6.0.3.2)
14
+ activesupport (= 6.0.3.2)
15
+ rack (~> 2.0, >= 2.0.8)
33
16
  rack-test (>= 0.6.3)
34
17
  rails-dom-testing (~> 2.0)
35
18
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
36
- actiontext (6.0.0)
37
- actionpack (= 6.0.0)
38
- activerecord (= 6.0.0)
39
- activestorage (= 6.0.0)
40
- activesupport (= 6.0.0)
41
- nokogiri (>= 1.8.5)
42
- actionview (6.0.0)
43
- activesupport (= 6.0.0)
19
+ actionview (6.0.3.2)
20
+ activesupport (= 6.0.3.2)
44
21
  builder (~> 3.1)
45
22
  erubi (~> 1.4)
46
23
  rails-dom-testing (~> 2.0)
47
24
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
48
- activejob (6.0.0)
49
- activesupport (= 6.0.0)
50
- globalid (>= 0.3.6)
51
- activemodel (6.0.0)
52
- activesupport (= 6.0.0)
53
- activerecord (6.0.0)
54
- activemodel (= 6.0.0)
55
- activesupport (= 6.0.0)
56
- activestorage (6.0.0)
57
- actionpack (= 6.0.0)
58
- activejob (= 6.0.0)
59
- activerecord (= 6.0.0)
60
- marcel (~> 0.3.1)
61
- activesupport (6.0.0)
25
+ activesupport (6.0.3.2)
62
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
63
27
  i18n (>= 0.7, < 2)
64
28
  minitest (~> 5.1)
65
29
  tzinfo (~> 1.1)
66
- zeitwerk (~> 2.1, >= 2.1.8)
67
- ast (2.4.0)
68
- builder (3.2.3)
69
- concurrent-ruby (1.1.5)
70
- crass (1.0.4)
30
+ zeitwerk (~> 2.2, >= 2.2.2)
31
+ ast (2.4.1)
32
+ autotest-suffix (1.1.0)
33
+ builder (3.2.4)
34
+ combustion (1.3.0)
35
+ activesupport (>= 3.0.0)
36
+ railties (>= 3.0.0)
37
+ thor (>= 0.14.6)
38
+ concurrent-ruby (1.1.6)
39
+ crass (1.0.6)
71
40
  erubi (1.9.0)
72
- globalid (0.4.2)
73
- activesupport (>= 4.2.0)
74
- i18n (1.6.0)
41
+ i18n (1.8.5)
75
42
  concurrent-ruby (~> 1.0)
76
- jaro_winkler (1.5.3)
77
- loofah (2.3.0)
43
+ loofah (2.6.0)
78
44
  crass (~> 1.0.2)
79
45
  nokogiri (>= 1.5.9)
80
- mail (2.7.1)
81
- mini_mime (>= 0.1.1)
82
- marcel (0.3.3)
83
- mimemagic (~> 0.3.2)
84
- method_source (0.9.2)
85
- mimemagic (0.3.3)
86
- mini_mime (1.0.2)
46
+ method_source (1.0.0)
87
47
  mini_portile2 (2.4.0)
88
- minitest (5.12.2)
89
- nio4r (2.5.2)
90
- nokogiri (1.10.4)
48
+ minitest (5.14.1)
49
+ minitest-autotest (1.1.1)
50
+ minitest-server (~> 1.0)
51
+ path_expander (~> 1.0)
52
+ minitest-focus (1.2.1)
53
+ minitest (>= 4, < 6)
54
+ minitest-server (1.0.6)
55
+ minitest (~> 5.0)
56
+ mocha (1.11.2)
57
+ nokogiri (1.10.10)
91
58
  mini_portile2 (~> 2.4.0)
92
- parallel (1.17.0)
93
- parser (2.6.4.1)
94
- ast (~> 2.4.0)
95
- rack (2.0.7)
59
+ parallel (1.19.2)
60
+ parser (2.7.1.4)
61
+ ast (~> 2.4.1)
62
+ path_expander (1.1.0)
63
+ rack (2.2.3)
96
64
  rack-proxy (0.6.5)
97
65
  rack
98
66
  rack-test (1.1.0)
99
67
  rack (>= 1.0, < 3)
100
- rails (6.0.0)
101
- actioncable (= 6.0.0)
102
- actionmailbox (= 6.0.0)
103
- actionmailer (= 6.0.0)
104
- actionpack (= 6.0.0)
105
- actiontext (= 6.0.0)
106
- actionview (= 6.0.0)
107
- activejob (= 6.0.0)
108
- activemodel (= 6.0.0)
109
- activerecord (= 6.0.0)
110
- activestorage (= 6.0.0)
111
- activesupport (= 6.0.0)
112
- bundler (>= 1.3.0)
113
- railties (= 6.0.0)
114
- sprockets-rails (>= 2.0.0)
115
68
  rails-dom-testing (2.0.3)
116
69
  activesupport (>= 4.2.0)
117
70
  nokogiri (>= 1.6)
118
- rails-html-sanitizer (1.2.0)
119
- loofah (~> 2.2, >= 2.2.2)
120
- railties (6.0.0)
121
- actionpack (= 6.0.0)
122
- activesupport (= 6.0.0)
71
+ rails-html-sanitizer (1.3.0)
72
+ loofah (~> 2.3)
73
+ railties (6.0.3.2)
74
+ actionpack (= 6.0.3.2)
75
+ activesupport (= 6.0.3.2)
123
76
  method_source
124
77
  rake (>= 0.8.7)
125
78
  thor (>= 0.20.3, < 2.0)
126
79
  rainbow (3.0.0)
127
- rake (13.0.0)
128
- rubocop (0.74.0)
129
- jaro_winkler (~> 1.5.1)
80
+ rake (13.0.1)
81
+ regexp_parser (1.7.1)
82
+ rexml (3.2.4)
83
+ rubocop (0.89.0)
130
84
  parallel (~> 1.10)
131
- parser (>= 2.6)
85
+ parser (>= 2.7.1.1)
132
86
  rainbow (>= 2.2.2, < 4.0)
87
+ regexp_parser (>= 1.7)
88
+ rexml
89
+ rubocop-ast (>= 0.1.0, < 1.0)
133
90
  ruby-progressbar (~> 1.7)
134
- unicode-display_width (>= 1.4.0, < 1.7)
91
+ unicode-display_width (>= 1.4.0, < 2.0)
92
+ rubocop-ast (0.3.0)
93
+ parser (>= 2.7.1.4)
135
94
  ruby-progressbar (1.10.1)
136
- sprockets (3.7.2)
137
- concurrent-ruby (~> 1.0)
138
- rack (> 1, < 3)
139
- sprockets-rails (3.2.1)
140
- actionpack (>= 4.0)
141
- activesupport (>= 4.0)
142
- sprockets (>= 3.0.0)
143
- thor (0.20.3)
95
+ thor (1.0.1)
144
96
  thread_safe (0.3.6)
145
- tzinfo (1.2.5)
97
+ tzinfo (1.2.7)
146
98
  thread_safe (~> 0.1)
147
- unicode-display_width (1.6.0)
148
- websocket-driver (0.7.1)
149
- websocket-extensions (>= 0.1.0)
150
- websocket-extensions (0.1.4)
151
- zeitwerk (2.1.10)
99
+ unicode-display_width (1.7.0)
100
+ zeitwerk (2.4.0)
152
101
 
153
102
  PLATFORMS
154
103
  ruby
155
104
 
156
105
  DEPENDENCIES
106
+ autotest-suffix
107
+ combustion
157
108
  frails!
109
+ minitest (~> 5.0)
110
+ minitest-autotest
111
+ minitest-focus
112
+ mocha
158
113
  rubocop
159
114
 
160
115
  BUNDLED WITH
161
- 2.0.2
116
+ 2.1.4
data/README.md CHANGED
@@ -8,6 +8,13 @@ Frails is a modern asset pipeline for [Rails](https://rubyonrails.org), built on
8
8
  - Full Webpack control without fighting with the likes of Webpacker.
9
9
  - Embrace modern front end practices.
10
10
 
11
+ PLUS...
12
+
13
+ - Side loaded layouts, views and partials.
14
+ - Components
15
+ - React + SSR
16
+ - Ruby/HTML
17
+
11
18
  ## Installation
12
19
 
13
20
  Frails is designed to work only within a Rails application, so must be installed in an existing Rails app. It also requires Node.js and a valid `package.json` file in your app root.
@@ -61,14 +68,6 @@ module.exports = {
61
68
  }
62
69
  ```
63
70
 
64
- ### Compilation for Production
65
-
66
- To take advantage of Rails asset host functionality, we recommend that you compile your assets using the provided Rake task:
67
-
68
- $ rails frails:compile
69
-
70
- This will ensure that you assets respect the `asset_host` configuration.
71
-
72
71
  ### Rails Helpers
73
72
 
74
73
  #### `javascript_pack_tag`
@@ -100,11 +99,12 @@ image_pack_tag 'logo.png'
100
99
  Frails has the ability to automatically include your Javascript and CSS based on the current layout
101
100
  and/or view. It even supports side loading partials.
102
101
 
103
- Just add the following tio your `ApplicationController`:
102
+ Just set the `side_load_assets` class variable to your `ApplicationController`, or indeed to any
103
+ controller.
104
104
 
105
105
  ```ruby
106
106
  class ApplicationController < ActionController::Base
107
- side_load_assets
107
+ self.side_load_assets = true
108
108
  end
109
109
  ```
110
110
 
@@ -186,34 +186,26 @@ module.exports = {
186
186
  {
187
187
  // Partials - modules (local)
188
188
  test: /app\/views\/.+(\/_([\w-_]+)\.css)$/,
189
- use: ["style-loader", "css-loader"]
189
+ use: ["style-loader", "css-loader"],
190
190
  },
191
191
  {
192
192
  // Layouts and views - no CSS modules (global)
193
193
  test: /app\/views\/.+(\/[^_]([\w-_]+)\.css)$/,
194
- use: ["style-loader", "css-loader"]
195
- }
196
- ]
197
- }
194
+ use: ["style-loader", "css-loader"],
195
+ },
196
+ ],
197
+ },
198
198
  };
199
199
  ```
200
200
 
201
201
  ## Configuration
202
202
 
203
- Frails is built to be as simple as possible, so has very few configuration options. But if you really must change the defaults, just set any of the following environment variables. Of course, if you do change any of these options, be sure to modify your Webpack config accordingly.
204
-
205
- Be sure to install dotenv-flow package and add that to the very top of your primary webpack config:
206
-
207
- ```javascript
208
- require("dotenv-flow").config();
209
- ```
210
-
211
- ### Options
203
+ Frails is built to be as simple as possible, so has very few configuration options:
212
204
 
213
- - `ENV['FRAILS_DEV_SERVER_PORT']` - The HTTP port that Rails will proxy asset requests to. (default: `8080`)
214
- - `ENV['FRAILS_DEV_SERVER_HOST']` - The HTTP host that Rails will proxy asset requests to. (default: `localhost`)
215
- - `ENV['FRAILS_PUBLIC_OUTPUT_PATH']` - The public path where Webpack will output its build to, relative to your app's `/public` directory. (default: `assets`)
216
- - `ENV['FRAILS_MANIFEST_PATH']` - Path to the produced Webpack manifest file, relative to the `public_output_path`. (default: `manifest.json`)
205
+ - `Frails.dev_server_host` - The HTTP port that Rails will proxy asset requests to. (default: `8080`)
206
+ - `Frails.dev_server_path` - The HTTP host that Rails will proxy asset requests to. (default: `localhost`)
207
+ - `Frails.public_output_path` - The public path where Webpack will output its build to, relative to your app's `/public` directory. (default: `assets`)
208
+ - `Frails.manifest_path` - Path to the produced Webpack manifest file, relative to the `public_output_path`. (default: `manifest.json`)
217
209
 
218
210
  ## Development
219
211
 
@@ -225,6 +217,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
225
217
 
226
218
  Bug reports and pull requests are welcome on GitHub at https://github.com/joelmoss/frails.
227
219
 
228
- ## Thanks...
220
+ ## Thanks
229
221
 
230
222
  A huge thank you goes out to the peeps behind [Webpacker](https://github.com/rails/webpacker). Frails has borrowed heavily from Webpacker, particularly for the dev server proxy and minifest code. 🙏
data/Rakefile CHANGED
@@ -5,8 +5,8 @@ require 'rake/testtask'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << 'test'
8
- t.libs << 'lib'
9
8
  t.test_files = FileList['test/**/*_test.rb']
9
+ t.verbose = true
10
10
  end
11
11
 
12
12
  task default: :test
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ presets: [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ targets: {
7
+ node: "current",
8
+ },
9
+ },
10
+ ],
11
+ ],
12
+ };
data/bin/test CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
- $: << File.expand_path("../test", __dir__)
2
+ # frozen_string_literal: true
3
3
 
4
- require "bundler/setup"
5
- require "rails/plugin/test"
4
+ $LOAD_PATH << File.expand_path('../test', __dir__)
5
+
6
+ require 'bundler/setup'
7
+ require 'rails/plugin/test'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ Bundler.require :default, :development
7
+
8
+ Combustion.initialize! :all
9
+ run Combustion::Application
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.push File.expand_path('lib', __dir__)
4
-
5
- require 'frails/version'
3
+ require_relative 'lib/frails/version'
6
4
 
7
5
  Gem::Specification.new do |spec|
8
6
  spec.name = 'frails'
@@ -12,14 +10,8 @@ Gem::Specification.new do |spec|
12
10
 
13
11
  spec.summary = 'A Modern [F]ront End on [Rails] and Webpack'
14
12
  spec.homepage = 'https://github.com/joelmoss/frails'
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- unless spec.respond_to?(:metadata)
19
- raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
20
- end
21
-
22
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
23
15
 
24
16
  spec.metadata['homepage_uri'] = spec.homepage
25
17
  spec.metadata['source_code_uri'] = spec.homepage
@@ -34,7 +26,7 @@ Gem::Specification.new do |spec|
34
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
27
  spec.require_paths = ['lib']
36
28
 
37
- spec.add_dependency 'nokogiri', '>= 1.10.4'
29
+ spec.add_dependency 'activesupport', '>= 6.0'
30
+ spec.add_dependency 'nokogiri', '>= 1.10.4'
38
31
  spec.add_dependency 'rack-proxy', '>= 0.6.5'
39
- spec.add_dependency 'rails', '>= 6.0'
40
32
  end