roda-sprockets 0.0.11
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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +23 -0
- data/README.md +119 -0
- data/Rakefile +2 -0
- data/lib/roda/plugins/sprockets.rb +151 -0
- data/lib/roda/plugins/sprockets_task.rb +32 -0
- data/lib/roda/sprockets.rb +1 -0
- data/roda-sprockets.gemspec +26 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b4e53a435d78900ca0aa849736d8a5a50153928d13bb52cd7f84a74f7cc2f459
|
4
|
+
data.tar.gz: dce7df67380f9cd01321f6fa1d348f1caf917428e8cd12ce68742ba2b57a8256
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: eecbbad49fbb0c2e1b7fcd0c67cc3d095e44112871dd954d37aefb6178be0f550bfbe80616dd23853ea79ad1880f0af0b2f9a89d68fe3a3db39c3bbd9f33577e
|
7
|
+
data.tar.gz: ceefc9229041a9d04cd3f7001ce2c5f1f4d77677c09fbcc6eea588b949450575a7405b5a977be081f0e70d14f0253063f4d5c905b580e1a33f2acdb7055a9def
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2015 cj
|
2
|
+
Copyright (c) 2020 hmdne
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# Roda::Sprockets
|
2
|
+
|
3
|
+
This Roda plugin provides support for integrating Sprockets with your Roda codebase.
|
4
|
+
|
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).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'sprockets-helpers', git: 'https://github.com/hmdne/sprockets-helpers'
|
14
|
+
gem 'roda-sprockets', git: 'https://github.com/hmdne/roda-sprockets'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class App < Roda
|
25
|
+
plugin :sprockets, precompile: %w(site.js site.css),
|
26
|
+
public_path: 'public/',
|
27
|
+
opal: true,
|
28
|
+
debug: true
|
29
|
+
plugin :public
|
30
|
+
|
31
|
+
route do |r|
|
32
|
+
r.public
|
33
|
+
r.sprockets
|
34
|
+
end
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
### Parameters for the plugin:
|
39
|
+
|
40
|
+
* `precompile` - an array of files that you want to precompile
|
41
|
+
* `prefix` (relative to the `root`, which is `app.opts[:root]` by default,
|
42
|
+
but also supports absolute paths) - an array of directories where your
|
43
|
+
assets are located, by default: `%w(assets vendor/assets)`.
|
44
|
+
* `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)
|
47
|
+
* `path_prefix` - a Roda prefix of your assets directory. By default: `/assets`
|
48
|
+
* `protocol` - either :http (default) or :https.
|
49
|
+
* `css_compressor`, `js_compressor` - pick a compressor of your choice.
|
50
|
+
* `host` - for hosting your assets on a different server
|
51
|
+
* `digest` (bool) - digest your assets for unique filenames, default: true
|
52
|
+
* `opal` (bool) - Opal support, default: false
|
53
|
+
* `debug` (bool) - debug mode, default: false
|
54
|
+
|
55
|
+
### Templates:
|
56
|
+
|
57
|
+
In your layout.erb (take note of the stylesheet_tag and javascript_tag):
|
58
|
+
|
59
|
+
```erb
|
60
|
+
<!doctype html>
|
61
|
+
<html>
|
62
|
+
<head>
|
63
|
+
<meta charset='utf-8'>
|
64
|
+
<title>Website</title>
|
65
|
+
<%= stylesheet_tag 'site' %>
|
66
|
+
</head>
|
67
|
+
<body>
|
68
|
+
<h1>Website</h1>
|
69
|
+
<%= yield %>
|
70
|
+
<%= javascript_tag 'site' %>
|
71
|
+
</body>
|
72
|
+
</html>
|
73
|
+
```
|
74
|
+
|
75
|
+
### Opal support:
|
76
|
+
|
77
|
+
Opal is the first citizen of this plugin. Add `opal` and `opal-browser`
|
78
|
+
gems, `require 'opal'`, `require 'opal-browser'` before this plugin gets
|
79
|
+
loaded. Create `assets/js/site.rb`:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
require 'opal'
|
83
|
+
require 'opal-browser'
|
84
|
+
|
85
|
+
$document.body << DOM {
|
86
|
+
div "Hello world!"
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
You will need to tell Opal to load this file. Add this in your template
|
91
|
+
after everything has been loaded or somewhere else:
|
92
|
+
|
93
|
+
```html
|
94
|
+
<%= opal_require 'site' %>
|
95
|
+
```
|
96
|
+
|
97
|
+
Note that it won't be needed for plain Javascript use, only Opal needs that
|
98
|
+
line.
|
99
|
+
|
100
|
+
### Rake precompilation tasks:
|
101
|
+
|
102
|
+
In your Rakefile:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
require_relative 'app'
|
106
|
+
require 'roda/plugins/sprockets_task'
|
107
|
+
|
108
|
+
Roda::RodaPlugins::Sprockets::Task.define!(App)
|
109
|
+
```
|
110
|
+
|
111
|
+
And launch: `rake assets:precompile` or `rake assets:clean`
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
1. Fork it ( https://github.com/hmdne/roda-sprockets/fork )
|
116
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
117
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
118
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
119
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'roda'
|
2
|
+
require 'sprockets'
|
3
|
+
require 'sprockets-helpers'
|
4
|
+
|
5
|
+
class Roda
|
6
|
+
module RodaPlugins
|
7
|
+
module Sprockets
|
8
|
+
DEFAULTS = {
|
9
|
+
sprockets: nil,
|
10
|
+
precompile: %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2),
|
11
|
+
prefix: %w(assets vendor/assets),
|
12
|
+
root: false,
|
13
|
+
public_path: false,
|
14
|
+
path_prefix: "/assets",
|
15
|
+
protocol: :http,
|
16
|
+
css_compressor: nil,
|
17
|
+
js_compressor: nil,
|
18
|
+
host: nil,
|
19
|
+
digest: true,
|
20
|
+
opal: false,
|
21
|
+
debug: false
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
def self.load_dependencies(app, _opts = nil)
|
25
|
+
app.plugin :environments
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure(app, plugin_options = {})
|
29
|
+
if app.opts[:sprockets]
|
30
|
+
app.opts[:sprockets].merge!(plugin_options)
|
31
|
+
else
|
32
|
+
app.opts[:sprockets] = plugin_options.dup
|
33
|
+
end
|
34
|
+
options = app.opts[:sprockets].merge! plugin_options
|
35
|
+
DEFAULTS.each { |k, v| options[k] = v unless options.key?(k) }
|
36
|
+
|
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] }
|
40
|
+
|
41
|
+
# opal-sprockets registers engines when required, but if we create Sprockets::Environment before
|
42
|
+
# requiring that, they don't get registered
|
43
|
+
require 'opal/sprockets' if options[:opal]
|
44
|
+
options[:sprockets] ||= ::Sprockets::Environment.new
|
45
|
+
|
46
|
+
options[:prefix].each do |prefix|
|
47
|
+
# Support absolute asset paths
|
48
|
+
# https://github.com/kalasjocke/sinatra-asset-pipeline/pull/54
|
49
|
+
if prefix.end_with? '/'
|
50
|
+
paths = if Pathname.new(prefix).absolute?
|
51
|
+
Dir[File.join(prefix)]
|
52
|
+
else
|
53
|
+
Dir[File.join(options[:root], prefix)]
|
54
|
+
end
|
55
|
+
else
|
56
|
+
paths = if Pathname.new(prefix).absolute?
|
57
|
+
Dir[File.join(prefix, '*')]
|
58
|
+
else
|
59
|
+
Dir[File.join(options[:root], prefix, '*')]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
paths.each do |path|
|
64
|
+
options[:sprockets].append_path path
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
if options[:opal]
|
69
|
+
Opal.paths.each do |path|
|
70
|
+
options[:sprockets].append_path path
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
options[:sprockets_helpers] = ::Sprockets::Helpers::Settings.new
|
75
|
+
|
76
|
+
options[:sprockets_helpers].environment = options[:sprockets]
|
77
|
+
options[:sprockets_helpers].digest = options[:digest]
|
78
|
+
options[:sprockets_helpers].prefix = options[:path_prefix] unless options[:path_prefix].nil?
|
79
|
+
options[:sprockets_helpers].debug = options[:debug]
|
80
|
+
|
81
|
+
app.configure :staging, :production do
|
82
|
+
options[:sprockets].css_compressor = options[:css_compressor] unless options[:css_compressor].nil?
|
83
|
+
options[:sprockets].js_compressor = options[:js_compressor] unless options[:js_compressor].nil?
|
84
|
+
|
85
|
+
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
|
+
options[:sprockets_helpers].protocol = options[:protocol]
|
88
|
+
options[:sprockets_helpers].asset_host = options[:host] unless options[:host].nil?
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
module ClassMethods
|
93
|
+
def sprockets_options
|
94
|
+
opts[:sprockets]
|
95
|
+
end
|
96
|
+
|
97
|
+
def sprockets_regexp
|
98
|
+
%r{#{sprockets_options[:sprockets_helpers].prefix[1..-1]}/(.*)}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
module InstanceMethods
|
103
|
+
include ::Sprockets::Helpers
|
104
|
+
|
105
|
+
def sprockets_options
|
106
|
+
self.class.sprockets_options
|
107
|
+
end
|
108
|
+
|
109
|
+
# Overload of Sprockets::Helpers#sprockets_helpers_settings to support polyinstantiation
|
110
|
+
def sprockets_helpers_settings
|
111
|
+
sprockets_options[:sprockets_helpers]
|
112
|
+
end
|
113
|
+
|
114
|
+
# Require Opal assets
|
115
|
+
def opal_require file
|
116
|
+
<<~END
|
117
|
+
<script>
|
118
|
+
Opal.loaded(typeof(OpalLoaded) === "undefined" ? [] : OpalLoaded);
|
119
|
+
Opal.require(#{file.to_json});
|
120
|
+
</script>
|
121
|
+
END
|
122
|
+
.gsub(/\s+/, ' ')
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
module RequestMethods
|
127
|
+
def sprockets
|
128
|
+
get self.roda_class.sprockets_regexp do |path|
|
129
|
+
options = scope.sprockets_options
|
130
|
+
env_sprockets = scope.request.env.dup
|
131
|
+
env_sprockets['PATH_INFO'] = path
|
132
|
+
|
133
|
+
status, headers, response = options[:sprockets].call env_sprockets
|
134
|
+
|
135
|
+
# Appease Rack::Lint
|
136
|
+
if (300..399).include? status
|
137
|
+
headers.delete("Content-type")
|
138
|
+
end
|
139
|
+
|
140
|
+
scope.response.status = status
|
141
|
+
scope.response.headers.merge! headers
|
142
|
+
|
143
|
+
response.is_a?(Array) ? response.join('\n') : response.to_s
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
register_plugin :sprockets, Sprockets
|
150
|
+
end
|
151
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/tasklib'
|
3
|
+
require 'rake/sprocketstask'
|
4
|
+
|
5
|
+
class Roda
|
6
|
+
module RodaPlugins
|
7
|
+
module Sprockets
|
8
|
+
class Task < Rake::TaskLib
|
9
|
+
def initialize(app_klass)
|
10
|
+
namespace :assets do
|
11
|
+
desc "Precompile assets"
|
12
|
+
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])
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Clean assets"
|
20
|
+
task :clean do
|
21
|
+
FileUtils.rm_rf(app_klass.sprockets_options[:public_path])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.define!(app_klass)
|
27
|
+
self.new app_klass
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "roda/plugins/sprockets"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "roda-sprockets"
|
7
|
+
spec.version = '0.0.11'
|
8
|
+
spec.authors = ["cj", "hmdne"]
|
9
|
+
spec.email = ["cjlazell@gmail.com"]
|
10
|
+
spec.summary = %q{Use sprockets to serve assets in roda.}
|
11
|
+
spec.description = %q{Use sprockets to serve assets in roda.}
|
12
|
+
spec.homepage = "https://github.com/hmdne/roda-sprockets"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'roda', '~> 3'
|
21
|
+
spec.add_dependency 'sprockets', '>= 2.2'
|
22
|
+
spec.add_dependency 'sprockets-helpers', '>= 1.4.0'
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roda-sprockets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cj
|
8
|
+
- hmdne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: roda
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '3'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: sprockets
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '2.2'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '2.2'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: sprockets-helpers
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.4.0
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.4.0
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
description: Use sprockets to serve assets in roda.
|
85
|
+
email:
|
86
|
+
- cjlazell@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/roda/plugins/sprockets.rb
|
97
|
+
- lib/roda/plugins/sprockets_task.rb
|
98
|
+
- lib/roda/sprockets.rb
|
99
|
+
- roda-sprockets.gemspec
|
100
|
+
homepage: https://github.com/hmdne/roda-sprockets
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubygems_version: 3.1.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: Use sprockets to serve assets in roda.
|
123
|
+
test_files: []
|