padrino-assets 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +2 -0
- data/LICENSE +19 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/examples/nginx.md +11 -0
- data/lib/padrino-assets.rb +81 -0
- data/lib/padrino-assets/helpers.rb +372 -0
- data/lib/padrino-assets/version.rb +5 -0
- data/lib/tasks/cleanup.rake +8 -0
- data/lib/tasks/clobber.rake +7 -0
- data/lib/tasks/compress.rake +1 -0
- data/lib/tasks/precompile.rake +26 -0
- data/padrino-assets.gemspec +23 -0
- metadata +96 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Benjamin Bloch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Padrino Assets
|
2
|
+
|
3
|
+
### Overview
|
4
|
+
|
5
|
+
Padrino assets is a plugin for the [Padrino](https://github.com/padrino/padrino-framework) web framework which makes use of the [Rack](https://github.com/rack/rack) plugin [Sprockets](https://github.com/sstephenson/sprockets) to manage and compile web assets.
|
6
|
+
|
7
|
+
### Setup & Installation
|
8
|
+
|
9
|
+
Include it in your project's `Gemfile` with Bundler:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem 'padrino-assets'
|
13
|
+
```
|
14
|
+
|
15
|
+
Modify your `app/app.rb` file to register the plugin:
|
16
|
+
|
17
|
+
``` ruby
|
18
|
+
class ExampleApplication < Padrino::Application
|
19
|
+
register Padrino::Assets
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
Modify your `config.ru` file to mount the environment:
|
24
|
+
|
25
|
+
``` ruby
|
26
|
+
map '/assets' do
|
27
|
+
run Padrino::Assets.environment
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
### Dependencies
|
32
|
+
|
33
|
+
* [Padrino-Core](https://github.com/padrino/padrino-framework) and [Padrino-Helpers](https://github.com/padrino/padrino-framework)
|
34
|
+
* [Ruby](http://www.ruby-lang.org/en) >= 1.9.2
|
35
|
+
* [Sprockets](https://github.com/sstephenson/sprockets)
|
36
|
+
|
37
|
+
### TODO
|
38
|
+
|
39
|
+
* Support for CSS/Javascript minification
|
40
|
+
* Additional documentation
|
41
|
+
* Tests
|
42
|
+
|
43
|
+
### Copyright
|
44
|
+
|
45
|
+
Copyright © 2012 Benjamin Bloch (Cirex). See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/examples/nginx.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'padrino-core'
|
2
|
+
require 'padrino-helpers'
|
3
|
+
|
4
|
+
FileSet.glob_require('padrino-assets/**/*.rb', __FILE__)
|
5
|
+
|
6
|
+
module Padrino
|
7
|
+
module Assets
|
8
|
+
class << self
|
9
|
+
##
|
10
|
+
# Returns a list of paths Sprockets will use in order to find assets used by the project
|
11
|
+
#
|
12
|
+
# @return [Array]
|
13
|
+
# List of assets paths
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# Padrino::Assets.load_paths << Padrino.root('vendor', '**', 'assets')
|
17
|
+
#
|
18
|
+
# @api public
|
19
|
+
def load_paths
|
20
|
+
@_load_paths ||= ['app/assets/**', 'lib/assets/**'].map do |file|
|
21
|
+
Dir[Padrino.root(file)]
|
22
|
+
end.flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Returns the configured Sprockets environment
|
27
|
+
#
|
28
|
+
# @return [Sprockets::Environment]
|
29
|
+
# Sprockets environment
|
30
|
+
#
|
31
|
+
# @api public
|
32
|
+
def environment
|
33
|
+
@_environment
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Returns a compiled manifest of our assets
|
38
|
+
#
|
39
|
+
# @return [Sprockets::Manifest]
|
40
|
+
# Sprockets manifest
|
41
|
+
#
|
42
|
+
# @api public
|
43
|
+
def manifest
|
44
|
+
@_manifest
|
45
|
+
end
|
46
|
+
|
47
|
+
# @private
|
48
|
+
def registered(app)
|
49
|
+
app.helpers Helpers
|
50
|
+
app.set :assets_prefix, '/assets'
|
51
|
+
app.set :assets_version, 1.0
|
52
|
+
app.set :assets_host, nil
|
53
|
+
app.set :compress_assets, true
|
54
|
+
app.set :index_assets, -> { app.environment == :production }
|
55
|
+
app.set :manifest_file, -> { File.join(app.public_folder, app.assets_prefix, 'manifest.json') }
|
56
|
+
app.set :precompile_assets, [ /^.+\.(?!js|css).+$/i, /^application\.(js|css)$/i ]
|
57
|
+
|
58
|
+
require 'sprockets'
|
59
|
+
|
60
|
+
Padrino.after_load do
|
61
|
+
@_environment = Sprockets::Environment.new(app.root) do |environment|
|
62
|
+
environment.logger = app.logger
|
63
|
+
environment.version = app.assets_version
|
64
|
+
if defined?(Padrino::Cache)
|
65
|
+
if app.respond_to?(:caching) && app.caching?
|
66
|
+
environment.cache = app.cache
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
load_paths.each { |path| environment.append_path(path) }
|
72
|
+
|
73
|
+
@_environment = environment.index if app.index_assets?
|
74
|
+
@_manifest = Sprockets::Manifest.new(environment, app.manifest_file)
|
75
|
+
end
|
76
|
+
|
77
|
+
Padrino::Tasks.files << Dir[File.dirname(__FILE__) + '/tasks/**/*.{rake,rb}']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,372 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Assets
|
3
|
+
module Helpers
|
4
|
+
##
|
5
|
+
# Returns an HTML stylesheet link tag for the specified sources
|
6
|
+
#
|
7
|
+
# @overload include_stylesheet(sources, options = {})
|
8
|
+
# @param [Array<String, Symbol>] sources
|
9
|
+
# Sources
|
10
|
+
# @param [Hash] options
|
11
|
+
# HTML options
|
12
|
+
# @option options [String] :media ('screen')
|
13
|
+
# Specifies the type of device the linked document is optimized for
|
14
|
+
#
|
15
|
+
# @return [String]
|
16
|
+
# Stylesheet link tag for +sources+ with specified +options+.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# include_stylesheets :application, :theme
|
20
|
+
# # => <link href="/assets/application.css" media="screen" rel="stylesheet" type="text/css">
|
21
|
+
# # => <link href="/assets/theme.css" media="screen" rel="stylesheet" type="text/css">
|
22
|
+
#
|
23
|
+
# include_stylesheet :handheld, media: 'handheld'
|
24
|
+
# # => <link href="/assets/handheld.css" media="handheld" rel="stylesheet" type="text/css">
|
25
|
+
#
|
26
|
+
# include_stylesheet 'http://www.example.com/style.css'
|
27
|
+
# # => <link href="http://www.example.com/style.css" media="screen" rel="stylesheet" type="text/css">
|
28
|
+
#
|
29
|
+
# @since 0.1.0
|
30
|
+
# @api public
|
31
|
+
def include_stylesheet(*sources)
|
32
|
+
options = sources.extract_options!.symbolize_keys
|
33
|
+
options.reverse_merge!(media: 'screen', rel: 'stylesheet', type: 'text/css')
|
34
|
+
sources.collect do |source|
|
35
|
+
tag(:link, options.reverse_merge(href: asset_path(source, :css)))
|
36
|
+
end.join("\n")
|
37
|
+
end
|
38
|
+
alias_method :include_stylesheets, :include_stylesheet
|
39
|
+
alias_method :stylesheet_include_tag, :include_stylesheet
|
40
|
+
|
41
|
+
##
|
42
|
+
# Returns an HTML script tag for the specified sources
|
43
|
+
#
|
44
|
+
# @overload include_javascript(sources, options={})
|
45
|
+
# @param [Array<String, Symbol>] sources
|
46
|
+
# Sources
|
47
|
+
# @param [Hash] options
|
48
|
+
# HTML options
|
49
|
+
#
|
50
|
+
# @return [String]
|
51
|
+
# Script tag for +sources+ with specified +options+.
|
52
|
+
#
|
53
|
+
# @example
|
54
|
+
# include_javascript :application, :jquery
|
55
|
+
# # => <script type="text/javascript" src="/assets/application.js"></script>
|
56
|
+
# # => <script type="text/javascript" src="/assets/jquery.js"></script>
|
57
|
+
#
|
58
|
+
# include_javascript 'http://www.example.com/application.js'
|
59
|
+
# # => <script type="text/javascript" src="http://www.example.com/application.js"></script>
|
60
|
+
#
|
61
|
+
# @since 0.1.0
|
62
|
+
# @api public
|
63
|
+
def include_javascript(*sources)
|
64
|
+
options = sources.extract_options!.symbolize_keys
|
65
|
+
options.reverse_merge!(type: 'text/javascript', content: '')
|
66
|
+
sources.collect do |source|
|
67
|
+
tag(:script, options.reverse_merge(src: asset_path(source, :js)))
|
68
|
+
end.join("\n")
|
69
|
+
end
|
70
|
+
alias_method :include_javascripts, :include_javascript
|
71
|
+
alias_method :javascript_include_tag, :include_javascript
|
72
|
+
|
73
|
+
##
|
74
|
+
# Returns an HTML image element with given sources and options
|
75
|
+
#
|
76
|
+
# @overload image(sources, options={})
|
77
|
+
# @param [String] source
|
78
|
+
# Sources
|
79
|
+
# @param [Hash] options
|
80
|
+
# HTML options
|
81
|
+
# @option options [String] :id
|
82
|
+
# Specifies the identifier of the image
|
83
|
+
# @option options [String] :class
|
84
|
+
# Specifies the class of the image
|
85
|
+
# @option options [String] :size
|
86
|
+
# Specifies the width and height of the image
|
87
|
+
# @option options [Integer] :width
|
88
|
+
# Specifies the width of the image
|
89
|
+
# @option options [Integer] :height
|
90
|
+
# Specifies the height of the image
|
91
|
+
# @option options [String] :alt
|
92
|
+
# Specifies an alternate text for an image
|
93
|
+
#
|
94
|
+
# @return [String]
|
95
|
+
# Image tag with +url+ and specified +options+.
|
96
|
+
#
|
97
|
+
# @example
|
98
|
+
# image 'example.png'
|
99
|
+
# # => <img src="/assets/example.png" alt="Example" />
|
100
|
+
#
|
101
|
+
# image 'example.png', size: '40x40'
|
102
|
+
# # => <img src="/assets/example.png" width="40" height="40" alt="Example" />
|
103
|
+
#
|
104
|
+
# image 'example.png', width: 40
|
105
|
+
# # => <img src="/assets/example.png" width="40" alt="Example" />
|
106
|
+
#
|
107
|
+
# image 'example.png', height: 40
|
108
|
+
# # => <img src="/assets/example.png" height="40" alt="Example" />
|
109
|
+
#
|
110
|
+
# image 'example.png', alt: 'My Little Pony'
|
111
|
+
# # => <img src="/assets/example.png" alt="My Little Pony" />
|
112
|
+
#
|
113
|
+
# image 'http://www.example.com/example.png'
|
114
|
+
# # => <img src="http://www.example.com/example.png" />
|
115
|
+
#
|
116
|
+
# images 'example.png', 'example.jpg'
|
117
|
+
# # => <img src="/assets/example.png" alt="Example" />
|
118
|
+
# # => <img src="/assets/example.jpg" alt="Example" />
|
119
|
+
#
|
120
|
+
# @since 0.1.0
|
121
|
+
# @api public
|
122
|
+
def image(*sources)
|
123
|
+
options = sources.extract_options!.symbolize_keys
|
124
|
+
|
125
|
+
if size = options.delete(:size)
|
126
|
+
options[:width], options[:height] = size.split('x') if size =~ /^[0-9]+x[0-9]+$/
|
127
|
+
end
|
128
|
+
|
129
|
+
sources.collect do |source|
|
130
|
+
tag(:img, options.reverse_merge(src: asset_path(source)))
|
131
|
+
end.join("\n")
|
132
|
+
end
|
133
|
+
alias_method :images, :image
|
134
|
+
alias_method :image_tag, :image
|
135
|
+
|
136
|
+
##
|
137
|
+
# Return an HTML video element with given sources and options
|
138
|
+
#
|
139
|
+
# @overload video(sources, options={})
|
140
|
+
# @param [Array<String>] sources
|
141
|
+
# Sources
|
142
|
+
# @param [Hash] options
|
143
|
+
# HTML options
|
144
|
+
# @option options [String] :id
|
145
|
+
# Specifies the identifier of the video
|
146
|
+
# @option options [String] :class
|
147
|
+
# Specifies the class of the video
|
148
|
+
# @option options [String] :size
|
149
|
+
# Specifies the width and height of the video
|
150
|
+
# @option options [Integer] :width
|
151
|
+
# Specifies the width of the video
|
152
|
+
# @option options [Integer] :height
|
153
|
+
# Specifies the height of the video
|
154
|
+
# @option options [String] :preload
|
155
|
+
# Specifies the method the web browser should use to preload the video
|
156
|
+
# @option options [String] :poster
|
157
|
+
# Specifies an image to be shown while the video is downloading, or until the user hits the play button
|
158
|
+
# @option options [Boolean] :controls
|
159
|
+
# Should the video controls be shown if present
|
160
|
+
# @option options [Boolean] :muted
|
161
|
+
# Should the video automatically start off muted
|
162
|
+
# @option options [Boolean] :autoplay
|
163
|
+
# Should the video automatically play when it's ready
|
164
|
+
# @option options [Boolean] :loop
|
165
|
+
# Should the video automatically loop when it's done
|
166
|
+
#
|
167
|
+
# @return [String]
|
168
|
+
# Video tag with +url+ and specified +options+
|
169
|
+
#
|
170
|
+
# @example
|
171
|
+
# video 'example.webm'
|
172
|
+
# # => <video src="/assets/example.webm" />
|
173
|
+
#
|
174
|
+
# video 'example.webm', controls: true, autoplay: true
|
175
|
+
# # => <video src="/assets/example.webm" controls="controls" autoplay="autoplay" />
|
176
|
+
#
|
177
|
+
# video 'example.webm', loop: true
|
178
|
+
# # => <video src="/assets/example.webm" loop="loop" />
|
179
|
+
#
|
180
|
+
# video 'example.webm', size: '40x40'
|
181
|
+
# # => <video src="/assets/example.webm" width="40" height="40" />
|
182
|
+
#
|
183
|
+
# video 'example.webm', height: 40
|
184
|
+
# # => <video src="/assets/example.webm" height="40" />
|
185
|
+
#
|
186
|
+
# video 'example.webm', width: 40
|
187
|
+
# # => <video src="/assets/example.webm" width="40" />
|
188
|
+
#
|
189
|
+
# video 'http://www.example.com/example.webm'
|
190
|
+
# # => <video src="http://www.example.com/example.webm" />
|
191
|
+
#
|
192
|
+
# videos 'example.webm', 'example.mov'
|
193
|
+
# # => <video>
|
194
|
+
# # => <source src="/assets/example.webm" />
|
195
|
+
# # => <source src="/assets/example.mov" />
|
196
|
+
# # => </video>
|
197
|
+
#
|
198
|
+
# @since 0.1.0
|
199
|
+
# @api public
|
200
|
+
def video(*sources)
|
201
|
+
options = sources.extract_options!.symbolize_keys
|
202
|
+
|
203
|
+
if size = options.delete(:size)
|
204
|
+
options[:width], options[:height] = size.split('x') if size =~ /^[0-9]+x[0-9]+$/
|
205
|
+
end
|
206
|
+
|
207
|
+
if sources.is_a?(Array)
|
208
|
+
content_tag(:video, options) do
|
209
|
+
sources.collect { |source| tag(:source, src: asset_path(source)) }.join
|
210
|
+
end
|
211
|
+
else
|
212
|
+
tag(:video, options.reverse_merge(src: asset_path(sources)))
|
213
|
+
end
|
214
|
+
end
|
215
|
+
alias_method :videos, :video
|
216
|
+
alias_method :video_tag, :video
|
217
|
+
|
218
|
+
##
|
219
|
+
# Returns an HTML audio element with given sources and options
|
220
|
+
#
|
221
|
+
# @overload audio(sources, options={})
|
222
|
+
# @param [Array<String>] sources
|
223
|
+
# Sources
|
224
|
+
# @param [Hash] options
|
225
|
+
# HTML options
|
226
|
+
# @option options [String] :id
|
227
|
+
# Specifies the identifier of the audio
|
228
|
+
# @option options [String] :class
|
229
|
+
# Specifies the class of the audio
|
230
|
+
# @option options [String] :preload
|
231
|
+
# Specifies the method the web browser should use to preload the audio
|
232
|
+
# @option options [Boolean] :controls
|
233
|
+
# Should the audio controls be shown if present
|
234
|
+
# @option options [Boolean] :autoplay
|
235
|
+
# Should the audio automatically play when it's ready
|
236
|
+
# @option options [Boolean] :loop
|
237
|
+
# Should the audio automatically loop when it's done
|
238
|
+
#
|
239
|
+
# @return [String]
|
240
|
+
# Audio tag with +url+ and specified +options+
|
241
|
+
#
|
242
|
+
# @example
|
243
|
+
# audio 'example.ogg'
|
244
|
+
# # => <audio src="/assets/example.ogg" />
|
245
|
+
#
|
246
|
+
# audio 'example.ogg', controls: true, autoplay: true
|
247
|
+
# # => <audio src="/assets/example.ogg" controls="controls" autoplay="autoplay" />
|
248
|
+
#
|
249
|
+
# audio 'example.ogg', loop: true
|
250
|
+
# # => <audio src="/assets/example.ogg" loop="loop" />
|
251
|
+
#
|
252
|
+
# audio 'http://www.example.com/example.ogg'
|
253
|
+
# # => <audio src="http://www.example.com/example.ogg" />
|
254
|
+
#
|
255
|
+
# audios 'example.ogg', 'example.mp4'
|
256
|
+
# # => <audio>
|
257
|
+
# # => <source src="/assets/example.ogg" />
|
258
|
+
# # => <source src="/assets/example.mp4" />
|
259
|
+
# # => </audio>
|
260
|
+
#
|
261
|
+
# @since 0.1.0
|
262
|
+
# @api public
|
263
|
+
def audio(*sources)
|
264
|
+
options = sources.extract_options!.symbolize_keys
|
265
|
+
|
266
|
+
if sources.is_a?(Array)
|
267
|
+
content_tag(:audio, options) do
|
268
|
+
sources.collect { |source| tag(:source, src: asset_path(source)) }.join
|
269
|
+
end
|
270
|
+
else
|
271
|
+
tag(:audio, options.reverse_merge(src: asset_path(sources)))
|
272
|
+
end
|
273
|
+
end
|
274
|
+
alias_method :audios, :audio
|
275
|
+
alias_method :audio_tag, :audio
|
276
|
+
|
277
|
+
##
|
278
|
+
# Determines whether or not the provided source is a valid URI
|
279
|
+
#
|
280
|
+
# @param [String] source
|
281
|
+
# URI Source
|
282
|
+
#
|
283
|
+
# @return [Boolean]
|
284
|
+
#
|
285
|
+
# @example
|
286
|
+
# is_uri?('http://www.example.com')
|
287
|
+
# # => true
|
288
|
+
#
|
289
|
+
# is_uri?('www.example.com')
|
290
|
+
# # => false
|
291
|
+
#
|
292
|
+
# is_uri?('//example.com')
|
293
|
+
# # => true
|
294
|
+
#
|
295
|
+
# is_uri?('/example/example.css')
|
296
|
+
# # => true
|
297
|
+
#
|
298
|
+
# @since 0.1.0
|
299
|
+
# @api public
|
300
|
+
def is_uri?(source)
|
301
|
+
!!(source =~ %r(^[a-z]+://|^//?))
|
302
|
+
end
|
303
|
+
|
304
|
+
##
|
305
|
+
# Returns a modified asset source based on the current application settings
|
306
|
+
#
|
307
|
+
# @overload asset_path(source, extension = nil)
|
308
|
+
# @param [String] source
|
309
|
+
# Source
|
310
|
+
# @param [Symbol] extension (nil)
|
311
|
+
# File extension
|
312
|
+
#
|
313
|
+
# @return [String]
|
314
|
+
# Modified source based on application settings
|
315
|
+
#
|
316
|
+
# @example
|
317
|
+
# asset_path('example.webm')
|
318
|
+
# # => '/assets/example.webm'
|
319
|
+
#
|
320
|
+
# asset_path('stylesheet', :css)
|
321
|
+
# # => '/assets/stylesheet.css'
|
322
|
+
#
|
323
|
+
# asset_path('http://www.example.com/stylesheet.css')
|
324
|
+
# # => 'http://www.example.com/stylesheet.css'
|
325
|
+
#
|
326
|
+
# @since 0.1.0
|
327
|
+
# @api public
|
328
|
+
def asset_path(source, extension = nil)
|
329
|
+
return source if is_uri?(source)
|
330
|
+
source = source.to_s
|
331
|
+
source = rewrite_extension(source, extension)
|
332
|
+
source = rewrite_asset(source)
|
333
|
+
source = rewrite_asset_path(source)
|
334
|
+
source = rewrite_asset_host(source)
|
335
|
+
source
|
336
|
+
end
|
337
|
+
|
338
|
+
private
|
339
|
+
|
340
|
+
# @private
|
341
|
+
def rewrite_extension(source, extension)
|
342
|
+
if extension && File.extname(source).empty?
|
343
|
+
"#{source}.#{extension}"
|
344
|
+
else
|
345
|
+
source
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
349
|
+
# @private
|
350
|
+
def rewrite_asset(source)
|
351
|
+
if settings.index_assets? && asset = Assets.manifest.assets[source]
|
352
|
+
source = asset
|
353
|
+
end
|
354
|
+
source
|
355
|
+
end
|
356
|
+
|
357
|
+
# @private
|
358
|
+
def rewrite_asset_path(source)
|
359
|
+
source = File.join(settings.assets_prefix, source)
|
360
|
+
source = "/#{source}" unless source[0] == ?/
|
361
|
+
source
|
362
|
+
end
|
363
|
+
|
364
|
+
# @private
|
365
|
+
def rewrite_asset_host(source)
|
366
|
+
host = settings.assets_host
|
367
|
+
host = host.call(source) if host.respond_to?(:call)
|
368
|
+
host ? "#{host}#{source}" : source
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
namespace :assets do
|
2
|
+
desc 'Compiles all assets'
|
3
|
+
task :precompile do
|
4
|
+
environment = Padrino::Assets.environment
|
5
|
+
manifest = Padrino::Assets.manifest
|
6
|
+
apps = Padrino.mounted_apps
|
7
|
+
apps.each do |app|
|
8
|
+
app = app.app_obj
|
9
|
+
|
10
|
+
app.precompile_assets.each do |path|
|
11
|
+
environment.each_logical_path.each do |logical_path|
|
12
|
+
case path
|
13
|
+
when Regexp
|
14
|
+
next unless path.match(logical_path)
|
15
|
+
when Proc
|
16
|
+
next unless path.call(logical_path)
|
17
|
+
else
|
18
|
+
next unless File.fnmatch(path.to_s, logical_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
manifest.compile(logical_path)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'padrino-assets/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'padrino-assets'
|
7
|
+
s.version = Padrino::Assets::VERSION
|
8
|
+
s.authors = ['Benjamin Bloch']
|
9
|
+
s.email = ['cirex@gamesol.org']
|
10
|
+
s.homepage = 'https://github.com/Cirex/padrino-assets'
|
11
|
+
s.description = 'A plugin for the Padrino web framework which uses Sprockets to manage and compile assets'
|
12
|
+
s.summary = s.description
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
|
19
|
+
s.add_dependency 'sprockets', '~> 2.2.0'
|
20
|
+
|
21
|
+
s.add_dependency 'padrino-core'
|
22
|
+
s.add_dependency 'padrino-helpers'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: padrino-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Bloch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-12 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sprockets
|
16
|
+
requirement: &8494660 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *8494660
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: padrino-core
|
27
|
+
requirement: &8564010 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *8564010
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: padrino-helpers
|
38
|
+
requirement: &8566720 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *8566720
|
47
|
+
description: A plugin for the Padrino web framework which uses Sprockets to manage
|
48
|
+
and compile assets
|
49
|
+
email:
|
50
|
+
- cirex@gamesol.org
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- CHANGELOG.md
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- examples/nginx.md
|
62
|
+
- lib/padrino-assets.rb
|
63
|
+
- lib/padrino-assets/helpers.rb
|
64
|
+
- lib/padrino-assets/version.rb
|
65
|
+
- lib/tasks/cleanup.rake
|
66
|
+
- lib/tasks/clobber.rake
|
67
|
+
- lib/tasks/compress.rake
|
68
|
+
- lib/tasks/precompile.rake
|
69
|
+
- padrino-assets.gemspec
|
70
|
+
homepage: https://github.com/Cirex/padrino-assets
|
71
|
+
licenses: []
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.15
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: A plugin for the Padrino web framework which uses Sprockets to manage and
|
94
|
+
compile assets
|
95
|
+
test_files: []
|
96
|
+
has_rdoc:
|