sinatra-asset-pipeline 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -69
- data/lib/sinatra/asset_pipeline.rb +11 -13
- data/lib/sinatra/asset_pipeline/task.rb +2 -2
- data/lib/sinatra/asset_pipeline/version.rb +1 -1
- metadata +13 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67c14af31acb5da1a991e3285ec7c2d061c7c1ca
|
4
|
+
data.tar.gz: d6f476d835ab2cd9f56fed6ece5d878046409163
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b283cb132aca67a3742b9733db31a0875fe2136b226c8e668dba6141c2e6f941d88345aeb37a8edfccfaccc63d29a2853deee873b83e914a6c2a384b7ce1bbf
|
7
|
+
data.tar.gz: 20121e1bb86b608eb517077c8932a53ccbc12dd62e3e0cced02a187989551808e169280128c587dd9063dd0542394555ebfb858c0af8b8e61dab0d8e1d054c3a
|
data/README.md
CHANGED
@@ -1,19 +1,25 @@
|
|
1
1
|
Sinatra Asset Pipeline [![Build Status](https://travis-ci.org/kalasjocke/sinatra-asset-pipeline.svg?branch=master)](https://travis-ci.org/kalasjocke/sinatra-asset-pipeline)
|
2
2
|
======================
|
3
3
|
|
4
|
-
An asset pipeline implementation for Sinatra based on [Sprockets](https://github.com/
|
5
|
-
|
6
|
-
sinatra-asset-pipeline supports both compiling assets on the fly for development as well as precompiling assets for production.
|
4
|
+
An asset pipeline implementation for Sinatra based on [Sprockets](https://github.com/rails/sprockets). sinatra-asset-pipeline supports both compiling assets on the fly for development as well as precompiling assets for production. The design goal for sinatra-asset-pipeline is to provide good defaults for integrating your Sinatra application with Sprockets.
|
7
5
|
|
8
6
|
# Installation
|
9
7
|
|
10
|
-
|
8
|
+
Install Sinatra Asset Pipeline from RubyGems:
|
9
|
+
|
10
|
+
```bash
|
11
|
+
gem install sinatra-asset-pipeline
|
12
|
+
```
|
13
|
+
|
14
|
+
Or, include it in your project's `Gemfile`:
|
11
15
|
|
12
16
|
```ruby
|
13
|
-
gem 'sinatra-asset-pipeline'
|
17
|
+
gem 'sinatra-asset-pipeline', '~> 1.0'
|
14
18
|
```
|
15
19
|
|
16
|
-
|
20
|
+
# Usage
|
21
|
+
|
22
|
+
Add the provided Rake tasks to your applications `Rakefile`:
|
17
23
|
|
18
24
|
```ruby
|
19
25
|
require 'sinatra/asset_pipeline/task'
|
@@ -22,38 +28,36 @@ require './app'
|
|
22
28
|
Sinatra::AssetPipeline::Task.define! App
|
23
29
|
```
|
24
30
|
|
25
|
-
|
31
|
+
This makes your application serve assets inside `assets` folder under the public `/assets` path. You can use the helpers provided by [sprocket-helpers](https://github.com/petebrowne/sprockets-helpers) inside your assets to ease locating your assets.
|
26
32
|
|
27
|
-
|
28
|
-
Sinatra::AssetPipeline::Task.define! Sinatra::Application
|
29
|
-
```
|
30
|
-
|
31
|
-
Now, when everything is in place you can precompile assets located in `assets/<asset-type>` with:
|
33
|
+
During deployment of your application you can use `precompile` rake task to precompile your assets to serve them as static files from your applications public folder.
|
32
34
|
|
33
35
|
```bash
|
34
|
-
|
36
|
+
RACK_ENV=production rake assets:precompile
|
35
37
|
```
|
36
38
|
|
37
|
-
|
39
|
+
To leverage the Sprockets preprocessor pipeline inside your app you can use the `assets_js_compressor` and `assets_css_compressor` settings respectively. See the [Using Processors](https://github.com/rails/sprockets#using-processors) section of the Sprockets readme for details.
|
38
40
|
|
39
|
-
|
40
|
-
|
41
|
+
## Classic style
|
42
|
+
|
43
|
+
If your application runs Sinatra in classic style you can define your Rake tasks as follows:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
Sinatra::AssetPipeline::Task.define! Sinatra::Application
|
41
47
|
```
|
42
48
|
|
43
|
-
#
|
49
|
+
# Customization
|
44
50
|
|
45
51
|
In its most simple form, you just register the `Sinatra::AssetPipeline` Sinatra extension within your application:
|
46
52
|
|
47
53
|
```ruby
|
48
|
-
Bundler.require
|
49
|
-
|
50
54
|
require 'sinatra/asset_pipeline'
|
51
55
|
|
52
56
|
class App < Sinatra::Base
|
53
57
|
register Sinatra::AssetPipeline
|
54
58
|
|
55
59
|
get '/' do
|
56
|
-
|
60
|
+
'hi'
|
57
61
|
end
|
58
62
|
end
|
59
63
|
```
|
@@ -61,20 +65,21 @@ end
|
|
61
65
|
However, if your application doesn't follow the defaults you can customize it as follows:
|
62
66
|
|
63
67
|
```ruby
|
64
|
-
Bundler.require
|
65
|
-
|
66
68
|
require 'sinatra/asset_pipeline'
|
67
69
|
|
68
70
|
class App < Sinatra::Base
|
69
71
|
# Include these files when precompiling assets
|
70
|
-
set :assets_precompile, %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff)
|
72
|
+
set :assets_precompile, %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
|
71
73
|
|
72
|
-
#
|
73
|
-
set :
|
74
|
+
# The path to your assets
|
75
|
+
set :assets_paths, %w(assets)
|
74
76
|
|
75
77
|
# Use another host for serving assets
|
76
78
|
set :assets_host, '<id>.cloudfront.net'
|
77
79
|
|
80
|
+
# Which prefix to serve the assets under
|
81
|
+
set :assets_prefix, 'custom-prefix'
|
82
|
+
|
78
83
|
# Serve assets using this protocol (http, :https, :relative)
|
79
84
|
set :assets_protocol, :http
|
80
85
|
|
@@ -84,53 +89,11 @@ class App < Sinatra::Base
|
|
84
89
|
# JavaScript minification
|
85
90
|
set :assets_js_compressor, :uglifier
|
86
91
|
|
87
|
-
# Register the AssetPipeline
|
92
|
+
# Register the AssetPipeline extension, make sure this goes after all customization
|
88
93
|
register Sinatra::AssetPipeline
|
89
94
|
|
90
95
|
get '/' do
|
91
|
-
|
96
|
+
'hi'
|
92
97
|
end
|
93
98
|
end
|
94
99
|
```
|
95
|
-
|
96
|
-
Now when everything is in place you can use all helpers provided by [sprockets-helpers](https://github.com/petebrowne/sprockets-helpers), an example:
|
97
|
-
|
98
|
-
```scss
|
99
|
-
body {
|
100
|
-
background-image: image-url('cat.png');
|
101
|
-
}
|
102
|
-
```
|
103
|
-
|
104
|
-
Note that you don't need to require [sprockets-helpers](https://github.com/petebrowne/sprockets-helpers) inside your code to leverage the functionallity given to you by the integration, sinatra-asset-pipeline handles that for you.
|
105
|
-
|
106
|
-
### CSS and JavaScript minification
|
107
|
-
|
108
|
-
If you would like to use CSS and/or JavaScript minification make sure to require the needed gems in your `Gemfile`:
|
109
|
-
|
110
|
-
<table>
|
111
|
-
<tr>
|
112
|
-
<th>Minifier</th>
|
113
|
-
<th>Gem</th>
|
114
|
-
</tr>
|
115
|
-
<tr>
|
116
|
-
<td>:sass</td>
|
117
|
-
<td>sass</td>
|
118
|
-
</tr>
|
119
|
-
<tr>
|
120
|
-
<td>:closure</td>
|
121
|
-
<td>closure-compiler</td>
|
122
|
-
</tr>
|
123
|
-
<tr>
|
124
|
-
<td>:uglifier</td>
|
125
|
-
<td>uglifier</td>
|
126
|
-
</tr>
|
127
|
-
<tr>
|
128
|
-
<td>:yui</td>
|
129
|
-
<td>yui-compressor</td>
|
130
|
-
</tr>
|
131
|
-
</table>
|
132
|
-
|
133
|
-
### Compass integration
|
134
|
-
|
135
|
-
Given that we're using [sprockets-sass](https://github.com/petebrowne/sprockets-sass) under the hood we have out of the box support for [compass](https://github.com/chriseppstein/compass). Just include the compass gem in your `Gemfile` and include the compass mixins in your `app.css.scss` file.
|
136
|
-
|
@@ -1,43 +1,41 @@
|
|
1
1
|
require 'sprockets'
|
2
|
-
require 'sprockets-sass'
|
3
2
|
require 'sprockets-helpers'
|
4
3
|
|
5
4
|
module Sinatra
|
6
5
|
module AssetPipeline
|
7
6
|
def self.registered(app)
|
8
7
|
app.set_default :sprockets, Sprockets::Environment.new
|
9
|
-
app.set_default :
|
10
|
-
app.set_default :
|
11
|
-
app.set_default :
|
8
|
+
app.set_default :assets_paths, %w(assets)
|
9
|
+
app.set_default :assets_precompile, %w(app.js app.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
|
10
|
+
app.set_default :assets_public_path, -> { File.join(public_folder, "assets") }
|
12
11
|
app.set_default :assets_protocol, :http
|
13
12
|
app.set_default :assets_css_compressor, nil
|
14
13
|
app.set_default :assets_js_compressor, nil
|
15
14
|
app.set_default :assets_host, nil
|
15
|
+
app.set_default :assets_prefix, '/assets'
|
16
16
|
app.set_default :assets_digest, true
|
17
17
|
app.set_default :assets_debug, false
|
18
|
-
app.set_default :path_prefix, nil
|
19
18
|
|
20
19
|
app.set :static, :true
|
21
20
|
app.set :static_cache_control, [:public, :max_age => 60 * 60 * 24 * 365]
|
22
21
|
|
23
22
|
app.configure do
|
24
|
-
app.
|
25
|
-
|
26
|
-
paths.each { |path| app.sprockets.append_path path }
|
23
|
+
app.assets_paths.each do |path|
|
24
|
+
app.sprockets.append_path File.join(app.root, path)
|
27
25
|
end
|
28
26
|
|
29
27
|
Sprockets::Helpers.configure do |config|
|
30
28
|
config.environment = app.sprockets
|
31
29
|
config.digest = app.assets_digest
|
32
|
-
config.prefix = app.
|
30
|
+
config.prefix = app.assets_prefix unless app.assets_prefix.nil?
|
33
31
|
config.debug = app.assets_debug
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
35
|
app.configure :staging, :production do
|
38
36
|
Sprockets::Helpers.configure do |config|
|
39
|
-
config.manifest = Sprockets::Manifest.new(app.sprockets, app.
|
40
|
-
config.prefix = app.
|
37
|
+
config.manifest = Sprockets::Manifest.new(app.sprockets, app.assets_public_path)
|
38
|
+
config.prefix = app.assets_prefix unless app.assets_prefix.nil?
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
@@ -48,14 +46,14 @@ module Sinatra
|
|
48
46
|
Sprockets::Helpers.configure do |config|
|
49
47
|
config.protocol = app.assets_protocol
|
50
48
|
config.asset_host = app.assets_host unless app.assets_host.nil?
|
51
|
-
config.prefix = app.
|
49
|
+
config.prefix = app.assets_prefix unless app.assets_prefix.nil?
|
52
50
|
end
|
53
51
|
end
|
54
52
|
|
55
53
|
app.helpers Sprockets::Helpers
|
56
54
|
|
57
55
|
app.configure :test, :development do
|
58
|
-
app.get "#{
|
56
|
+
app.get "#{app.assets_prefix}/*" do |path|
|
59
57
|
env_sprockets = request.env.dup
|
60
58
|
env_sprockets['PATH_INFO'] = path
|
61
59
|
settings.sprockets.call env_sprockets
|
@@ -10,13 +10,13 @@ module Sinatra
|
|
10
10
|
desc "Precompile assets"
|
11
11
|
task :precompile do
|
12
12
|
environment = app_klass.sprockets
|
13
|
-
manifest = Sprockets::Manifest.new(environment.index, app_klass.
|
13
|
+
manifest = Sprockets::Manifest.new(environment.index, app_klass.assets_public_path)
|
14
14
|
manifest.compile(app_klass.assets_precompile)
|
15
15
|
end
|
16
16
|
|
17
17
|
desc "Clean assets"
|
18
18
|
task :clean do
|
19
|
-
FileUtils.rm_rf(app_klass.
|
19
|
+
FileUtils.rm_rf(app_klass.assets_public_path)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-asset-pipeline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joakim Ekberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '11.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '11.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sinatra
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,56 +44,42 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.4'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: coffee-script
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '2.
|
61
|
+
version: '2.4'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
68
|
+
version: '2.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sprockets
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '3.6'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: sprockets-sass
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.2'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.2'
|
82
|
+
version: '3.6'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: sprockets-helpers
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,14 +100,14 @@ dependencies:
|
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '3.
|
103
|
+
version: '3.5'
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '3.
|
110
|
+
version: '3.5'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: rack-test
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
168
154
|
version: '0'
|
169
155
|
requirements: []
|
170
156
|
rubyforge_project:
|
171
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.6.2
|
172
158
|
signing_key:
|
173
159
|
specification_version: 4
|
174
160
|
summary: An asset pipeline implementation for Sinatra.
|