roda-sprockets 0.0.11 → 1.1.0.rc1

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: b4e53a435d78900ca0aa849736d8a5a50153928d13bb52cd7f84a74f7cc2f459
4
- data.tar.gz: dce7df67380f9cd01321f6fa1d348f1caf917428e8cd12ce68742ba2b57a8256
3
+ metadata.gz: a4a70ad21f0db49bb53cea400c3e90c27e2cae1c1d791f5c6dd471ee89b27621
4
+ data.tar.gz: 4bb46d275d252145e7406463d9a6fd1e6171eacc1bc59ff45d10e977de3b030e
5
5
  SHA512:
6
- metadata.gz: eecbbad49fbb0c2e1b7fcd0c67cc3d095e44112871dd954d37aefb6178be0f550bfbe80616dd23853ea79ad1880f0af0b2f9a89d68fe3a3db39c3bbd9f33577e
7
- data.tar.gz: ceefc9229041a9d04cd3f7001ce2c5f1f4d77677c09fbcc6eea588b949450575a7405b5a977be081f0e70d14f0253063f4d5c905b580e1a33f2acdb7055a9def
6
+ metadata.gz: 26eee21ed69f840bc04a1b024bf7d4ce7347a12d917cbfcd3eada64a7b9a76288748e99889a40fe273a150c92702c2a7048c369b1445fc078d888300055458f2
7
+ data.tar.gz: 839696f0f772909e113c14776eccf09a961723ca2dd2c33aa6edf252b3d3fb3ddd078a5021889ffd292bd3f92d41c0510ec710afbad1af4af2ce9a2034c0a037
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.gem
14
15
  mkmf.log
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ v1.1.0
2
+
3
+ - Fix the Rack::Lint issue (#1)
4
+ - :public_path argument to receive a default value (#7)
5
+ - Roda::RodaPlugins::Sprockets::Task to superclass SprocketsTask (#6)
6
+ - The debug logic now depends on :debug argument, not environment (#4)
7
+
8
+ v1.0.2
9
+
10
+ - :root argument to select a default argument more robustly (#2)
11
+
12
+ v1.0.1
13
+
14
+ - New :cache argument to plugin configuration
15
+
16
+ v1.0.0
17
+
18
+ - Sprockets 4.0 support
19
+
20
+ v0.0.11
21
+
22
+ - Support polyinstantiation, improve Opal support
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2015 cj
2
- Copyright (c) 2020 hmdne
2
+ Copyright (c) 2020-2021 hmdne and opal-sprockets contributors
3
3
 
4
4
  MIT License
5
5
 
data/README.md CHANGED
@@ -3,15 +3,14 @@
3
3
  This Roda plugin provides support for integrating Sprockets with your Roda codebase.
4
4
 
5
5
  This is a fork of [roda-sprocket_assets](https://github.com/cj/roda-sprocket_assets).
6
- This release supports Roda 3.x and Sprockets 3.x (in the future, Sprockets 4.x too).
6
+ This release supports Roda 3.x and Sprockets 3.x and 4.x.
7
7
 
8
8
  ## Installation
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'sprockets-helpers', git: 'https://github.com/hmdne/sprockets-helpers'
14
- gem 'roda-sprockets', git: 'https://github.com/hmdne/roda-sprockets'
13
+ gem 'roda-sprockets'
15
14
  ```
16
15
 
17
16
  And then execute:
@@ -23,7 +22,7 @@ And then execute:
23
22
  ```ruby
24
23
  class App < Roda
25
24
  plugin :sprockets, precompile: %w(site.js site.css),
26
- public_path: 'public/',
25
+ public_path: 'public/assets/',
27
26
  opal: true,
28
27
  debug: true
29
28
  plugin :public
@@ -42,8 +41,9 @@ end
42
41
  but also supports absolute paths) - an array of directories where your
43
42
  assets are located, by default: `%w(assets vendor/assets)`.
44
43
  * `root` - a filesystem root directory of your app. By default, `app.opts[:root]`.
45
- * `public_path` - filesystem path to your `public` directory, for all your
46
- precompilation needs. (REQUIRED)
44
+ * `public_path` - filesystem path to a place, where precompiled assets will be
45
+ stored, by default: `public/assets` (it should be a directory from which `:public`
46
+ plugin takes files + `path_prefix`)
47
47
  * `path_prefix` - a Roda prefix of your assets directory. By default: `/assets`
48
48
  * `protocol` - either :http (default) or :https.
49
49
  * `css_compressor`, `js_compressor` - pick a compressor of your choice.
@@ -51,6 +51,7 @@ end
51
51
  * `digest` (bool) - digest your assets for unique filenames, default: true
52
52
  * `opal` (bool) - Opal support, default: false
53
53
  * `debug` (bool) - debug mode, default: false
54
+ * `cache` - a `Sprockets::Cache` instance
54
55
 
55
56
  ### Templates:
56
57
 
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "roda-sprockets", path: "../.."
4
+ gem "opal-sprockets"
5
+ gem "puma"
6
+ gem "rake"
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ roda-sprockets (1.0.2)
5
+ roda (~> 3)
6
+ sprockets (>= 2.2)
7
+ sprockets-helpers (>= 1.4.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ concurrent-ruby (1.1.9)
14
+ nio4r (2.5.7)
15
+ opal (1.2.0)
16
+ ast (>= 2.3.0)
17
+ parser (~> 3.0)
18
+ opal-sprockets (1.0.1)
19
+ opal (>= 1.0, < 2.0)
20
+ sprockets (~> 4.0)
21
+ tilt (>= 1.4)
22
+ parser (3.0.2.0)
23
+ ast (~> 2.4.1)
24
+ puma (5.4.0)
25
+ nio4r (~> 2.0)
26
+ rack (2.2.3)
27
+ rake (13.0.6)
28
+ roda (3.46.0)
29
+ rack
30
+ sprockets (4.0.2)
31
+ concurrent-ruby (~> 1.0)
32
+ rack (> 1, < 3)
33
+ sprockets-helpers (1.4.0)
34
+ sprockets (>= 2.2)
35
+ tilt (2.0.10)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ opal-sprockets
42
+ puma
43
+ rake
44
+ roda-sprockets!
45
+
46
+ BUNDLED WITH
47
+ 2.1.4
@@ -0,0 +1,4 @@
1
+ This is an example found in `opal` repository in `docs/roda-sprockets.md`.
2
+
3
+ It describes how to create the simplest application with roda, roda-sprockets
4
+ and opal.
@@ -0,0 +1,6 @@
1
+ require "bundler/setup"
2
+ require "roda/plugins/sprockets_task"
3
+
4
+ require_relative "app"
5
+
6
+ Roda::RodaPlugins::Sprockets::Task.define!(App)
@@ -0,0 +1,26 @@
1
+ require 'roda'
2
+
3
+ class App < Roda
4
+ plugin :sprockets, precompile: %w(application.js),
5
+ prefix: %w(app/),
6
+ opal: true,
7
+ debug: ENV['RACK_ENV'] != 'production'
8
+ plugin :public
9
+
10
+ route do |r|
11
+ r.public
12
+ r.sprockets
13
+
14
+ r.root do
15
+ <<~END
16
+ <!doctype html>
17
+ <html>
18
+ <head>
19
+ #{ javascript_tag 'application' }
20
+ #{ opal_require 'application' }
21
+ </head>
22
+ </html>
23
+ END
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ require 'opal'
2
+
3
+ puts "wow, running ruby!"
@@ -0,0 +1,3 @@
1
+ require_relative "app"
2
+
3
+ run App.app
@@ -10,7 +10,7 @@ class Roda
10
10
  precompile: %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2),
11
11
  prefix: %w(assets vendor/assets),
12
12
  root: false,
13
- public_path: false,
13
+ public_path: "public/assets/",
14
14
  path_prefix: "/assets",
15
15
  protocol: :http,
16
16
  css_compressor: nil,
@@ -18,13 +18,10 @@ class Roda
18
18
  host: nil,
19
19
  digest: true,
20
20
  opal: false,
21
- debug: false
21
+ debug: false,
22
+ cache: nil,
22
23
  }.freeze
23
24
 
24
- def self.load_dependencies(app, _opts = nil)
25
- app.plugin :environments
26
- end
27
-
28
25
  def self.configure(app, plugin_options = {})
29
26
  if app.opts[:sprockets]
30
27
  app.opts[:sprockets].merge!(plugin_options)
@@ -34,9 +31,9 @@ class Roda
34
31
  options = app.opts[:sprockets].merge! plugin_options
35
32
  DEFAULTS.each { |k, v| options[k] = v unless options.key?(k) }
36
33
 
37
- options[:root] = app.opts[:root] if !options[:root]
38
-
39
- %i(root public_path).each { |type| raise "#{type} needs to be set." unless options[type] }
34
+ if !options[:root]
35
+ options[:root] = app.opts[:root] || Dir.pwd
36
+ end
40
37
 
41
38
  # opal-sprockets registers engines when required, but if we create Sprockets::Environment before
42
39
  # requiring that, they don't get registered
@@ -71,6 +68,10 @@ class Roda
71
68
  end
72
69
  end
73
70
 
71
+ if options[:cache]
72
+ options[:sprockets].cache = options[:cache]
73
+ end
74
+
74
75
  options[:sprockets_helpers] = ::Sprockets::Helpers::Settings.new
75
76
 
76
77
  options[:sprockets_helpers].environment = options[:sprockets]
@@ -78,12 +79,11 @@ class Roda
78
79
  options[:sprockets_helpers].prefix = options[:path_prefix] unless options[:path_prefix].nil?
79
80
  options[:sprockets_helpers].debug = options[:debug]
80
81
 
81
- app.configure :staging, :production do
82
+ unless options[:debug]
82
83
  options[:sprockets].css_compressor = options[:css_compressor] unless options[:css_compressor].nil?
83
84
  options[:sprockets].js_compressor = options[:js_compressor] unless options[:js_compressor].nil?
84
85
 
85
86
  options[:sprockets_helpers].manifest = ::Sprockets::Manifest.new(options[:sprockets], options[:public_path])
86
- options[:sprockets_helpers].prefix = options[:path_prefix] unless options[:path_prefix].nil?
87
87
  options[:sprockets_helpers].protocol = options[:protocol]
88
88
  options[:sprockets_helpers].asset_host = options[:host] unless options[:host].nil?
89
89
  end
@@ -119,7 +119,7 @@ class Roda
119
119
  Opal.require(#{file.to_json});
120
120
  </script>
121
121
  END
122
- .gsub(/\s+/, ' ')
122
+ .gsub(/\s+/, ' ').chop
123
123
  end
124
124
  end
125
125
 
@@ -132,15 +132,20 @@ class Roda
132
132
 
133
133
  status, headers, response = options[:sprockets].call env_sprockets
134
134
 
135
- # Appease Rack::Lint
136
- if (300..399).include? status
137
- headers.delete("Content-type")
138
- end
139
-
140
135
  scope.response.status = status
141
136
  scope.response.headers.merge! headers
142
137
 
143
- response.is_a?(Array) ? response.join('\n') : response.to_s
138
+ case response
139
+ when nil, []
140
+ # Empty response happens for example when 304 Not Modified happens.
141
+ # We want to return nil in this case.
142
+ # (See: https://github.com/hmdne/roda-sprockets/issues/1)
143
+ nil
144
+ when Array
145
+ response.join("\n")
146
+ else
147
+ response.to_s
148
+ end
144
149
  end
145
150
  end
146
151
  end
@@ -5,20 +5,40 @@ require 'rake/sprocketstask'
5
5
  class Roda
6
6
  module RodaPlugins
7
7
  module Sprockets
8
- class Task < Rake::TaskLib
8
+ class Task < Rake::SprocketsTask
9
9
  def initialize(app_klass)
10
+ @app_klass = app_klass
11
+ super() { update_values }
12
+ end
13
+
14
+ def update_values
15
+ @environment = sprockets_options[:sprockets]
16
+ @output = sprockets_options[:public_path]
17
+ @assets = sprockets_options[:precompile]
18
+ end
19
+
20
+ def sprockets_options
21
+ @opts ||= begin
22
+ opts = @app_klass.sprockets_options.dup
23
+ opts[:debug] = false
24
+ opts
25
+ end
26
+ end
27
+
28
+ def define
10
29
  namespace :assets do
11
30
  desc "Precompile assets"
12
31
  task :precompile do
13
- options = app_klass.sprockets_options
14
- environment = options[:sprockets]
15
- manifest = ::Sprockets::Manifest.new(environment.index, options[:public_path])
16
- manifest.compile(options[:precompile])
32
+ with_logger do
33
+ manifest.compile(assets)
34
+ end
17
35
  end
18
36
 
19
37
  desc "Clean assets"
20
38
  task :clean do
21
- FileUtils.rm_rf(app_klass.sprockets_options[:public_path])
39
+ with_logger do
40
+ manifest.clobber
41
+ end
22
42
  end
23
43
  end
24
44
  end
@@ -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 = '0.0.11'
7
+ spec.version = '1.1.0.rc1'
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.}
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 1.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
8
8
  - hmdne
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-19 00:00:00.000000000 Z
12
+ date: 2021-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: roda
@@ -89,10 +89,18 @@ extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
91
  - ".gitignore"
92
+ - CHANGELOG.md
92
93
  - Gemfile
93
94
  - LICENSE.txt
94
95
  - README.md
95
96
  - Rakefile
97
+ - examples/opal-doc/Gemfile
98
+ - examples/opal-doc/Gemfile.lock
99
+ - examples/opal-doc/README.md
100
+ - examples/opal-doc/Rakefile
101
+ - examples/opal-doc/app.rb
102
+ - examples/opal-doc/app/application.rb
103
+ - examples/opal-doc/config.ru
96
104
  - lib/roda/plugins/sprockets.rb
97
105
  - lib/roda/plugins/sprockets_task.rb
98
106
  - lib/roda/sprockets.rb
@@ -101,7 +109,7 @@ homepage: https://github.com/hmdne/roda-sprockets
101
109
  licenses:
102
110
  - MIT
103
111
  metadata: {}
104
- post_install_message:
112
+ post_install_message:
105
113
  rdoc_options: []
106
114
  require_paths:
107
115
  - lib
@@ -112,12 +120,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
120
  version: '0'
113
121
  required_rubygems_version: !ruby/object:Gem::Requirement
114
122
  requirements:
115
- - - ">="
123
+ - - ">"
116
124
  - !ruby/object:Gem::Version
117
- version: '0'
125
+ version: 1.3.1
118
126
  requirements: []
119
- rubygems_version: 3.1.2
120
- signing_key:
127
+ rubygems_version: 3.2.22
128
+ signing_key:
121
129
  specification_version: 4
122
130
  summary: Use sprockets to serve assets in roda.
123
131
  test_files: []