roda-sprockets 1.1.0 → 2.0.0rc1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c5624471b78bed45e3ad30586950ddd71710008d5f2b7831d418d08eea65390
4
- data.tar.gz: d231ec5e75c74f884cfef8cb37f565480b982bb6a3cd7249269b4e2a81618425
3
+ metadata.gz: 508fedb44f1daee79f32b2ef1746fb5a266aa771465dc44b42a9d2de03787d6a
4
+ data.tar.gz: 15678eedb2c7d2aa7d5e8c1136dd2b16c77d4336514e689875488a7ec593e934
5
5
  SHA512:
6
- metadata.gz: 49f8d649e83eca62de5464f7be4ce388284204fb9a1664ed44efdb9e91f7b97185cfc590369e0cc9e8aaa3a7056bc6c0439754303511f206e0db75821ab95d66
7
- data.tar.gz: 4fd782e737b76b53aa090c6d5ade85028d83c662a420ed201f4ab0a81bed75ac64186af9f7ce62af9ea0d92cdb8f6454fee4cde25cce5b167646be54f3a3e936
6
+ metadata.gz: eac697f7e01b05019e19a48704088910ceb1451ad2d6e40dccfc3ee8d8c67ef3b301d61876ca6089b4ce8454f19a1b02afbe3065abd812fdd804017188ddd838
7
+ data.tar.gz: c25b68ac51d50b091f398a5d98780f15987c20643535e289ed034d60929229ca0af556545dd6268981c83921dd763080c1a572306e5ef009161c37c20b57716c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ v2.0.0
2
+
3
+ - :debug argument now defaults to true, if RACK_ENV is development, false
4
+ otherwise - also false in rake tasks (#10)
5
+ - add sprockets_env class method, so you can shorten code like
6
+ `App.sprockets_options[:sprockets]` to just `App.sprockets_env` (#11)
7
+
1
8
  v1.1.0
2
9
 
3
10
  - Fix the Rack::Lint issue (#1)
data/README.md CHANGED
@@ -23,12 +23,11 @@ And then execute:
23
23
  class App < Roda
24
24
  plugin :sprockets, precompile: %w(site.js site.css),
25
25
  opal: true,
26
- debug: true
27
26
  plugin :public
28
27
 
29
28
  route do |r|
30
29
  r.public
31
- r.sprockets
30
+ r.sprockets if ENV['RACK_ENV'] == 'development'
32
31
  end
33
32
  end
34
33
  ```
@@ -53,11 +52,13 @@ end
53
52
  plugin takes files + `path_prefix`)
54
53
  * `path_prefix` - a Roda prefix of your assets directory. By default: `/assets`
55
54
  * `protocol` - either :http (default) or :https.
56
- * `css_compressor`, `js_compressor` - pick a compressor of your choice.
55
+ * `css_compressor`, `js_compressor` - pick a compressor of your choice (respected
56
+ only if `debug` is false)
57
57
  * `host` - for hosting your assets on a different server
58
58
  * `digest` (bool) - digest your assets for unique filenames, default: true
59
59
  * `opal` (bool) - Opal support, default: false
60
- * `debug` (bool) - debug mode, default: false
60
+ * `debug` (bool) - debug mode, default: true if RACK_ENV is development,
61
+ false otherwise (in rake tasks it's false too)
61
62
  * `cache` - a `Sprockets::Cache` instance, default: nil (no cache)
62
63
 
63
64
  ### Templates:
@@ -142,6 +143,27 @@ Roda::RodaPlugins::Sprockets::Task.define!(App)
142
143
 
143
144
  And launch: `rake assets:precompile` or `rake assets:clean`
144
145
 
146
+ ### Sprockets extended configuration:
147
+
148
+ You can configure your environment directly by accessing a method `sprockets_env`
149
+ (which is a `Sprockets::Environment`) on your `App` class.
150
+
151
+ For instance, to enable Brotli with [sprockets-exporters_pack](https://github.com/hansottowirtz/sprockets-exporters_pack)
152
+ you will need to either add this code inside your `App` class:
153
+
154
+ ```ruby
155
+ sprockets_env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::ExportersPack::BrotliExporter
156
+ ```
157
+
158
+ Or at some other point:
159
+
160
+ ```ruby
161
+ App.sprockets_env.register_exporter %w(text/css application/javascript image/svg+xml), Sprockets::ExportersPack::BrotliExporter
162
+ ```
163
+
164
+ Do note, that some extensions, like for example [opal-optimizer](https://github.com/hmdne/opal-optimizer)
165
+ won't need any configuration at all beside `require "opal/optimizer/sprockets"`.
166
+
145
167
  ## Contributing
146
168
 
147
169
  1. Fork it ( https://github.com/hmdne/roda-sprockets/fork )
@@ -3,13 +3,12 @@ require 'roda'
3
3
  class App < Roda
4
4
  plugin :sprockets, precompile: %w(application.js),
5
5
  prefix: %w(app/),
6
- opal: true,
7
- debug: ENV['RACK_ENV'] != 'production'
6
+ opal: true
8
7
  plugin :public
9
8
 
10
9
  route do |r|
11
10
  r.public
12
- r.sprockets if ENV['RACK_ENV'] != 'production'
11
+ r.sprockets if ENV['RACK_ENV'] == 'development'
13
12
 
14
13
  r.root do
15
14
  <<~END
@@ -1,7 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  gem "roda-sprockets", path: "../.."
4
- gem "opal", github: "opal/opal"
4
+ gem "opal"
5
5
  gem "opal-sprockets"
6
6
  gem "puma"
7
7
  gem "rake"
8
+ gem "uglifier"
@@ -3,13 +3,13 @@ require 'roda'
3
3
  class App < Roda
4
4
  plugin :sprockets, precompile: %w(application.js),
5
5
  prefix: %w(app/),
6
- opal: true,
7
- debug: ENV['RACK_ENV'] != 'production'
6
+ js_compressor: :uglify,
7
+ opal: true
8
8
  plugin :public
9
9
 
10
10
  route do |r|
11
11
  r.public
12
- r.sprockets if ENV['RACK_ENV'] != 'production'
12
+ r.sprockets if ENV['RACK_ENV'] == 'development'
13
13
 
14
14
  r.root do
15
15
  <<~END
data/examples/sass/app.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require 'roda'
2
2
 
3
3
  class App < Roda
4
- plugin :sprockets, precompile: %w(application.css),
5
- debug: ENV['RACK_ENV'] != 'production'
4
+ plugin :sprockets, precompile: %w(application.css)
6
5
  plugin :public
7
6
 
8
7
  route do |r|
9
8
  r.public
10
- r.sprockets if ENV['RACK_ENV'] != 'production'
9
+ r.sprockets if ENV['RACK_ENV'] == 'development'
11
10
 
12
11
  r.root do
13
12
  <<~END
@@ -18,7 +18,7 @@ class Roda
18
18
  host: nil,
19
19
  digest: true,
20
20
  opal: false,
21
- debug: false,
21
+ debug: nil,
22
22
  cache: nil,
23
23
  }.freeze
24
24
 
@@ -35,6 +35,14 @@ class Roda
35
35
  options[:root] = app.opts[:root] || Dir.pwd
36
36
  end
37
37
 
38
+ if options[:debug].nil?
39
+ if ENV['RACK_ENV'] == 'development'
40
+ options[:debug] = true
41
+ else
42
+ options[:debug] = false
43
+ end
44
+ end
45
+
38
46
  # opal-sprockets registers engines when required, but if we create Sprockets::Environment before
39
47
  # requiring that, they don't get registered
40
48
  require 'opal/sprockets' if options[:opal]
@@ -81,7 +89,7 @@ class Roda
81
89
 
82
90
  unless options[:debug]
83
91
  options[:sprockets].css_compressor = options[:css_compressor] unless options[:css_compressor].nil?
84
- options[:sprockets].js_compressor = options[:js_compressor] unless options[:js_compressor].nil?
92
+ options[:sprockets].js_compressor = options[:js_compressor] unless options[:js_compressor].nil?
85
93
 
86
94
  options[:sprockets_helpers].manifest = ::Sprockets::Manifest.new(options[:sprockets], options[:public_path])
87
95
  options[:sprockets_helpers].protocol = options[:protocol]
@@ -94,6 +102,10 @@ class Roda
94
102
  opts[:sprockets]
95
103
  end
96
104
 
105
+ def sprockets_env
106
+ sprockets_options[:sprockets]
107
+ end
108
+
97
109
  def sprockets_regexp
98
110
  %r{#{sprockets_options[:sprockets_helpers].prefix[1..-1]}/(.*)}
99
111
  end
@@ -26,11 +26,7 @@ class Roda
26
26
  end
27
27
 
28
28
  def sprockets_options
29
- @opts ||= begin
30
- opts = @app_klass.sprockets_options.dup
31
- opts[:debug] = false
32
- opts
33
- end
29
+ @app_klass.sprockets_options
34
30
  end
35
31
 
36
32
  def define
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "roda-sprockets"
7
- spec.version = '1.1.0'
7
+ spec.version = '2.0.0rc1'
8
8
  spec.authors = ["cj", "hmdne"]
9
9
  spec.email = ["cjlazell@gmail.com"]
10
10
  spec.summary = %q{Use sprockets to serve assets in roda.}
@@ -38,9 +38,18 @@ RSpec.describe "Example" do
38
38
  when "opal-exception"
39
39
  error.should_not be_nil
40
40
  functions = error.stack_trace["callFrames"].map { |i| i["functionName"] }
41
- functions.should include "$$a"
42
- functions.should include "$$b"
43
- functions.should include "$$c"
41
+ if debug
42
+ functions.should include "$$a"
43
+ functions.should include "$$b"
44
+ functions.should include "$$c"
45
+ else
46
+ # We minify this example, so functions should be mangled
47
+ functions.should_not include "$$a"
48
+ functions.should_not include "$$b"
49
+ functions.should_not include "$$c"
50
+ end
51
+ # Nevertheless, "Opal.modules.application" should stay unmangled.
52
+ functions.should include "Opal.modules.application"
44
53
  # How can we now test that source maps work? The browser doesn't help us...
45
54
  when "sass"
46
55
  browser.evaluate("window.getComputedStyle(document.body).backgroundColor").should be == "rgb(0, 128, 0)"
@@ -75,7 +84,7 @@ RSpec.describe "Example" do
75
84
  rescue Ferrum::JavaScriptError => e
76
85
  instance_exec(browser, true, e, &example_specific)
77
86
  ensure
78
- browser.quit
87
+ browser.quit if browser
79
88
  end
80
89
  ensure
81
90
  sigterm(pid)
@@ -87,8 +96,6 @@ RSpec.describe "Example" do
87
96
  it "works in production mode" do
88
97
  Dir.chdir example do
89
98
  Bundler.with_unbundled_env do
90
- ENV['RACK_ENV'] = 'production'
91
-
92
99
  if ENV.key? 'CI'
93
100
  system("bundle config --local path #{__dir__+"/../vendor/bundle"}")
94
101
  end
@@ -100,6 +107,8 @@ RSpec.describe "Example" do
100
107
  system("bundle exec rake assets:precompile").should be true
101
108
  Dir.children(example + "/public/assets").length.should be == 3
102
109
 
110
+ ENV['RACK_ENV'] = 'production'
111
+
103
112
  begin
104
113
  port = free_port
105
114
  pid = spawn("bundle exec rackup -p#{port}")
@@ -112,9 +121,9 @@ RSpec.describe "Example" do
112
121
 
113
122
  instance_exec(browser, false, nil, &example_specific)
114
123
  rescue Ferrum::JavaScriptError => e
115
- instance_exec(browser, true, e, &example_specific)
124
+ instance_exec(browser, false, e, &example_specific)
116
125
  ensure
117
- browser.quit
126
+ browser.quit if browser
118
127
  end
119
128
  ensure
120
129
  system("bundle exec rake assets:clean").should be true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
@@ -144,9 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
- - - ">="
147
+ - - ">"
148
148
  - !ruby/object:Gem::Version
149
- version: '0'
149
+ version: 1.3.1
150
150
  requirements: []
151
151
  rubygems_version: 3.2.22
152
152
  signing_key: