frails 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ee508fa6664a6ab99ce98455154178494206803ec8d377d0fe305b6b5601bdc
4
- data.tar.gz: d55d3414d0e8e105abfc59a23dffc6d09feaeaf1a54924231137b91949abad9c
3
+ metadata.gz: 6b49013f43563b5bf245a5e4190e36326ed5c92086e8b189918504fa9fd31904
4
+ data.tar.gz: 1cc03eb7682559dd5563d4b7152266fbe7f4ab3f0b2a7b0d6393a90833bb547f
5
5
  SHA512:
6
- metadata.gz: 1e68db6995b9d72a2250b1f6f4672fe171f3aa3464627270a9dd8d9e4f710ad2313a4ebb0f5bc6d1a4aabe9b7dcb185df34652598d8f6e88bc659d9f2d954a83
7
- data.tar.gz: '09e905d8ac0b2df6a9f90bdfaabe9501182982817e8a777060b151c9babd239ad4c94a9ebae6f8c4173e63146d1a514f9e8ee93db40329672cfcca0bd07c41b6'
6
+ metadata.gz: 63a219ca5f4ebf78c7cfbf53b1d38c7ee8b7e7ddfec0d9578046962cace8e1eb7e3bf18bbdb323610e4b61144f76c1def6c679e08238a7c220afb7d717c7d02a
7
+ data.tar.gz: 78e7991fa8ee31e6c911cf651dd232ee7a56b23e2b081457d8152e834d55da8afbd82185a6252db69d008245098be6d4338ba4aa8241451d6cab414acee87d6b
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ /node_modules/
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
@@ -6,3 +7,5 @@
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
10
+ .DS_Store
11
+ *.log
@@ -9,6 +9,4 @@ Style/ClassAndModuleChildren:
9
9
  Metrics/LineLength:
10
10
  Max: 100
11
11
  Layout/IndentationConsistency:
12
- EnforcedStyle: rails
13
- SupportedStyles:
14
- - rails
12
+ EnforcedStyle: indented_internal_methods
data/Gemfile CHANGED
@@ -1,8 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  source 'https://rubygems.org'
4
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
5
 
5
- # Specify your gem's dependencies in frails.gemspec
6
+ # Declare your gem's dependencies in frails.gemspec.
7
+ # Bundler will treat runtime dependencies like base dependencies, and
8
+ # development dependencies will be added by default to the :development group.
6
9
  gemspec
7
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
+
8
19
  gem 'rubocop', require: false
@@ -1,93 +1,161 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frails (0.1.0)
4
+ frails (0.3.0)
5
+ nokogiri (>= 1.10.4)
5
6
  rack-proxy (>= 0.6.5)
6
- railties (>= 5.2)
7
+ rails (>= 6.0)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
11
- actionpack (5.2.3)
12
- actionview (= 5.2.3)
13
- activesupport (= 5.2.3)
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)
14
32
  rack (~> 2.0)
15
33
  rack-test (>= 0.6.3)
16
34
  rails-dom-testing (~> 2.0)
17
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
18
- actionview (5.2.3)
19
- activesupport (= 5.2.3)
35
+ 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)
20
44
  builder (~> 3.1)
21
45
  erubi (~> 1.4)
22
46
  rails-dom-testing (~> 2.0)
23
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
24
- activesupport (5.2.3)
47
+ 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
62
  concurrent-ruby (~> 1.0, >= 1.0.2)
26
63
  i18n (>= 0.7, < 2)
27
64
  minitest (~> 5.1)
28
65
  tzinfo (~> 1.1)
66
+ zeitwerk (~> 2.1, >= 2.1.8)
29
67
  ast (2.4.0)
30
68
  builder (3.2.3)
31
69
  concurrent-ruby (1.1.5)
32
70
  crass (1.0.4)
33
- erubi (1.8.0)
71
+ erubi (1.9.0)
72
+ globalid (0.4.2)
73
+ activesupport (>= 4.2.0)
34
74
  i18n (1.6.0)
35
75
  concurrent-ruby (~> 1.0)
36
- jaro_winkler (1.5.2)
76
+ jaro_winkler (1.5.3)
37
77
  loofah (2.2.3)
38
78
  crass (~> 1.0.2)
39
79
  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)
40
84
  method_source (0.9.2)
85
+ mimemagic (0.3.3)
86
+ mini_mime (1.0.2)
41
87
  mini_portile2 (2.4.0)
42
- minitest (5.11.3)
43
- nokogiri (1.10.2)
88
+ minitest (5.12.0)
89
+ nio4r (2.5.2)
90
+ nokogiri (1.10.4)
44
91
  mini_portile2 (~> 2.4.0)
45
- parallel (1.16.0)
46
- parser (2.6.2.0)
92
+ parallel (1.17.0)
93
+ parser (2.6.4.1)
47
94
  ast (~> 2.4.0)
48
- psych (3.1.0)
49
95
  rack (2.0.7)
50
96
  rack-proxy (0.6.5)
51
97
  rack
52
98
  rack-test (1.1.0)
53
99
  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)
54
115
  rails-dom-testing (2.0.3)
55
116
  activesupport (>= 4.2.0)
56
117
  nokogiri (>= 1.6)
57
- rails-html-sanitizer (1.0.4)
118
+ rails-html-sanitizer (1.2.0)
58
119
  loofah (~> 2.2, >= 2.2.2)
59
- railties (5.2.3)
60
- actionpack (= 5.2.3)
61
- activesupport (= 5.2.3)
120
+ railties (6.0.0)
121
+ actionpack (= 6.0.0)
122
+ activesupport (= 6.0.0)
62
123
  method_source
63
124
  rake (>= 0.8.7)
64
- thor (>= 0.19.0, < 2.0)
125
+ thor (>= 0.20.3, < 2.0)
65
126
  rainbow (3.0.0)
66
- rake (10.5.0)
67
- rubocop (0.66.0)
127
+ rake (12.3.3)
128
+ rubocop (0.74.0)
68
129
  jaro_winkler (~> 1.5.1)
69
130
  parallel (~> 1.10)
70
- parser (>= 2.5, != 2.5.1.1)
71
- psych (>= 3.1.0)
131
+ parser (>= 2.6)
72
132
  rainbow (>= 2.2.2, < 4.0)
73
133
  ruby-progressbar (~> 1.7)
74
- unicode-display_width (>= 1.4.0, < 1.6)
75
- ruby-progressbar (1.10.0)
134
+ unicode-display_width (>= 1.4.0, < 1.7)
135
+ 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)
76
143
  thor (0.20.3)
77
144
  thread_safe (0.3.6)
78
145
  tzinfo (1.2.5)
79
146
  thread_safe (~> 0.1)
80
- unicode-display_width (1.5.0)
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)
81
152
 
82
153
  PLATFORMS
83
154
  ruby
84
155
 
85
156
  DEPENDENCIES
86
- bundler (~> 2.0)
87
157
  frails!
88
- minitest (~> 5.0)
89
- rake (~> 10.0)
90
158
  rubocop
91
159
 
92
160
  BUNDLED WITH
93
- 2.0.1
161
+ 2.0.2
data/README.md CHANGED
@@ -2,10 +2,11 @@
2
2
 
3
3
  Frails is a modern asset pipeline for [Rails](https://rubyonrails.org), built on [Webpack](https://webpack.js.org/). Its aims are:
4
4
 
5
- - Follow convention over configuration as much as possible.
6
- - Tight integration with Rails, without tying you up in knots.
7
- - Full Webpack control without fighting with the likes of Webpacker.
8
- - Embrace modern front end practises.
5
+ - Follow convention over configuration as much as possible.
6
+ - Tight integration with Rails, without tying you up in knots.
7
+ - Un-opinionated webpack configuration - batteries not included!
8
+ - Full Webpack control without fighting with the likes of Webpacker.
9
+ - Embrace modern front end practices.
9
10
 
10
11
  ## Installation
11
12
 
@@ -35,27 +36,176 @@ or run the dev server:
35
36
 
36
37
  $ yarn webpack-dev-server
37
38
 
38
- Rails will proxy requests to any running Webpack dev server
39
+ Rails will proxy requests to any running Webpack dev server.
39
40
 
40
- ## Configuration
41
+ ### Using in Tests
42
+
43
+ Please note that Frails is not designed or intended to be run in your test environment. This would require a full webpack compile on every test run, which would slow your tests down hugely! Instead, I recommend that you test your Javascript independently using the likes of Jest or some other good Javascript test runner.
44
+
45
+ ### Webpack Configuration
46
+
47
+ Frails requires the user of the `webpack-assets-manifest` webpack plugin in order for its helpers to
48
+ work correctly. This is because it needs to be able lookup the real paths of assets, and the
49
+ manifest file provides that data.
50
+
51
+ ```javascript
52
+ module.exports = {
53
+ ...
54
+ plugins: [
55
+ new WebpackAssetsManifest({
56
+ writeToDisk: true,
57
+ entrypoints: true,
58
+ publicPath: true
59
+ })
60
+ ]
61
+ }
62
+ ```
63
+
64
+ ### Compilation for Production
41
65
 
42
- Frails is built to be as simple as possible, so has very few configuration options. But if you really must change the defaults, just add any of the following config options by adding to `config/application.rb` or and/any of the environment initialzers at `config/environment`.
66
+ To take advantage of Rails asset host functionality, we recommend that you compile your assets using the provided Rake task:
43
67
 
44
- For example:
68
+ $ rails frails:compile
69
+
70
+ This will ensure that you assets respect the `asset_host` configuration.
71
+
72
+ ### Rails Helpers
73
+
74
+ #### `javascript_pack_tag`
75
+
76
+ Just like `javascript_include_tag`, but will use your webpack assets.
45
77
 
46
78
  ```ruby
47
- Rails.application.configure do
48
- config.frails.dev_server_port = 3035
49
- end
79
+ javascript_include_tag 'application'
80
+ ```
81
+
82
+ #### `stylesheet_pack_tag`
83
+
84
+ Just like `stylesheet_link_tag`, but will use your webpack assets.
85
+
86
+ ```ruby
87
+ stylesheet_pack_tag 'application'
88
+ ```
89
+
90
+ #### `image_pack_tag`
91
+
92
+ Just like `image_tag`, but will use your webpack assets.
93
+
94
+ ```ruby
95
+ image_pack_tag 'logo.png'
96
+ ```
97
+
98
+ ### Side Loaded Assets
99
+
100
+ Frails has the ability to automatically include your Javascript and CSS based on the current layout
101
+ and/or view. It even supports side loading partials.
102
+
103
+ As an example, given a view at `/app/views/pages/home.html.erb`, we can create
104
+ `/app/views/pages/home.css` and/or `/app/views/pages/home.js`. These side-loaded assets will then be
105
+ included automatically in the page.
106
+
107
+ ```yml
108
+ app/views/pages: ├── home.html.erb
109
+ ├── home.css
110
+ ├── home.js
111
+ ├── _header.html.erb
112
+ ├── _header.css
113
+ ```
114
+
115
+ Make sure you yield the side loaded CSS and JS tags; `<%= yield :side_loaded_css %>` in your
116
+ `<head>`, and `<%= yield :side_loaded_js %>` at the bottom of the body:
117
+
118
+ ```html
119
+ <!DOCTYPE html>
120
+ <html>
121
+ <head>
122
+ <title>My App</title>
123
+ <%= yield :side_loaded_css %>
124
+ </head>
125
+ <body>
126
+ <%= yield %> <%= yield :side_loaded_js %>
127
+ </body>
128
+ </html>
50
129
  ```
51
130
 
52
- Of course, if you do change any of these options, be sure to modify your Webpack config accordingly.
131
+ CSS is included in-line for faster renders, and JS is included as <script src="..."> tags. Check out
132
+ `./package/side_load.js` for the webpack config needed to make this work.
133
+
134
+ #### Partials and CSS Modules
135
+
136
+ Partial CSS supports CSS Modules, and it is recommended that partial CSS are compiled as local CSS
137
+ modules. Then in your partial, you can use the `css_module` attribute on any HTML tag, and it will
138
+ be replaced with the compiled class name of the CSS module.
139
+
140
+ So given a partial `views/layouts/_awesome.html.erb`:
141
+
142
+ ```html
143
+ <div css_module="base">Hello World</div>
144
+ ```
145
+
146
+ and a stylesheet at `views/layouts/_awesome.css`:
147
+
148
+ ```css
149
+ .base {
150
+ color: red;
151
+ }
152
+ ```
153
+
154
+ When the partial is rendered, it will look something like this:
155
+
156
+ ```html
157
+ <div class="app-views-layouts-_awesome__base___abc123">Hello World</div>
158
+ ```
159
+
160
+ And the compiled CSS:
161
+
162
+ ```css
163
+ .app-views-layouts-_awesome__base___abc123 {
164
+ color: red;
165
+ }
166
+ ```
167
+
168
+ Of course in theory, you could apply this to all your side loaded CSS, but Frails will only
169
+ transform `css_module` HTML attributes in partials.
170
+
171
+ Your Webpack config could use the following to compile your partial CSS as modules (local), and
172
+ layout and view CSS normally (global):
173
+
174
+ ```javascript
175
+ module.exports = {
176
+ module: {
177
+ rules: [
178
+ {
179
+ // Partials - modules (local)
180
+ test: /app\/views\/.+(\/_([\w-_]+)\.css)$/,
181
+ use: ["style-loader", "css-loader"]
182
+ },
183
+ {
184
+ // Layouts and views - no CSS modules (global)
185
+ test: /app\/views\/.+(\/[^_]([\w-_]+)\.css)$/,
186
+ use: ["style-loader", "css-loader"]
187
+ }
188
+ ]
189
+ }
190
+ };
191
+ ```
192
+
193
+ ## Configuration
194
+
195
+ 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.
196
+
197
+ Be sure to install dotenv-flow package and add that to the very top of your primary webpack config:
198
+
199
+ ```javascript
200
+ require("dotenv-flow").config();
201
+ ```
53
202
 
54
203
  ### Options
55
204
 
56
- - `dev_server_port` - The HTTP port that Rails will proxy asset requests to. (default: `8080`)
57
- - `dev_server_host` - The HTTP host that Rails will proxy asset requests to. (default: `localhost`)
58
- - `public_output_path` - The public path where Webpack will output its build to, relative to your app's `/public` directory. (default: `/assets`)
205
+ - `ENV['FRAILS_DEV_SERVER_PORT']` - The HTTP port that Rails will proxy asset requests to. (default: `8080`)
206
+ - `ENV['FRAILS_DEV_SERVER_HOST']` - The HTTP host that Rails will proxy asset requests to. (default: `localhost`)
207
+ - `ENV['FRAILS_PUBLIC_OUTPUT_PATH']` - The public path where Webpack will output its build to, relative to your app's `/public` directory. (default: `assets`)
208
+ - `ENV['FRAILS_MANIFEST_PATH']` - Path to the produced Webpack manifest file, relative to the `public_output_path`. (default: `manifest.json`)
59
209
 
60
210
  ## Development
61
211
 
@@ -69,4 +219,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/joelmo
69
219
 
70
220
  ## Thanks...
71
221
 
72
- 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. 🙏
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. 🙏