padrino-assets 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- # Version History
2
-
3
- ### 0.1.0 - (January 12, 2012)
1
+ # Version History
2
+
3
+ ### 0.2.0 - (January 17, 2012)
4
+ * The current `request` is now passed to **:assets_host** when a `Proc` is used
5
+ * Added the rake task `assets:compress` for [deflating](http://en.wikipedia.org/wiki/Gzip) assets
6
+ * Basic support for asset minification
7
+
8
+ ### 0.1.0 - (January 12, 2012)
4
9
  * Initial release
data/README.md CHANGED
@@ -28,6 +28,26 @@ map '/assets' do
28
28
  end
29
29
  ```
30
30
 
31
+ By default, Sprockets is configured to load assets from your project's `app/assets` and `lib/assets` directories. Any files stored in these directories are readily available to the included helpers and will be served by the Sprockets middleware.
32
+
33
+ The following directories are no longer used and will instead be served statically:
34
+
35
+ * `public/images`
36
+ * `public/stylesheets`
37
+ * `public/javascripts`
38
+
39
+ Because of this you should now be storing your assets in the following directories:
40
+
41
+ * `app/assets/images`
42
+ * `app/assets/stylesheets`
43
+ * `app/assets/javascripts`
44
+
45
+ Should your project need to add additional paths you can do so by adding the following line:
46
+
47
+ ``` ruby
48
+ Padrino::Assets.load_paths << 'path/to/my/assets'
49
+ ```
50
+
31
51
  ### Dependencies
32
52
 
33
53
  * [Padrino-Core](https://github.com/padrino/padrino-framework) and [Padrino-Helpers](https://github.com/padrino/padrino-framework)
@@ -36,7 +56,6 @@ end
36
56
 
37
57
  ### TODO
38
58
 
39
- * Support for CSS/Javascript minification
40
59
  * Additional documentation
41
60
  * Tests
42
61
 
@@ -15,6 +15,7 @@ module Padrino
15
15
  # @example
16
16
  # Padrino::Assets.load_paths << Padrino.root('vendor', '**', 'assets')
17
17
  #
18
+ # @since 0.1.0
18
19
  # @api public
19
20
  def load_paths
20
21
  @_load_paths ||= ['app/assets/**', 'lib/assets/**'].map do |file|
@@ -28,6 +29,7 @@ module Padrino
28
29
  # @return [Sprockets::Environment]
29
30
  # Sprockets environment
30
31
  #
32
+ # @since 0.1.0
31
33
  # @api public
32
34
  def environment
33
35
  @_environment
@@ -39,6 +41,7 @@ module Padrino
39
41
  # @return [Sprockets::Manifest]
40
42
  # Sprockets manifest
41
43
  #
44
+ # @since 0.1.0
42
45
  # @api public
43
46
  def manifest
44
47
  @_manifest
@@ -51,6 +54,8 @@ module Padrino
51
54
  app.set :assets_version, 1.0
52
55
  app.set :assets_host, nil
53
56
  app.set :compress_assets, true
57
+ app.set :js_compressor, nil
58
+ app.set :css_compressor, nil
54
59
  app.set :index_assets, -> { app.environment == :production }
55
60
  app.set :manifest_file, -> { File.join(app.public_folder, app.assets_prefix, 'manifest.json') }
56
61
  app.set :precompile_assets, [ /^.+\.(?!js|css).+$/i, /^application\.(js|css)$/i ]
@@ -66,6 +71,11 @@ module Padrino
66
71
  environment.cache = app.cache
67
72
  end
68
73
  end
74
+
75
+ if app.compress_assets?
76
+ environment.js_compressor = app.js_compressor
77
+ environment.css_compressor = app.css_compressor
78
+ end
69
79
  end
70
80
 
71
81
  load_paths.each { |path| environment.append_path(path) }
@@ -74,7 +74,7 @@
74
74
  # Returns an HTML image element with given sources and options
75
75
  #
76
76
  # @overload image(sources, options={})
77
- # @param [String] source
77
+ # @param [Array<String>] sources
78
78
  # Sources
79
79
  # @param [Hash] options
80
80
  # HTML options
@@ -206,7 +206,7 @@
206
206
 
207
207
  if sources.is_a?(Array)
208
208
  content_tag(:video, options) do
209
- sources.collect { |source| tag(:source, src: asset_path(source)) }.join
209
+ sources.collect { |source| tag(:source, src: asset_path(source)) }.join("\n")
210
210
  end
211
211
  else
212
212
  tag(:video, options.reverse_merge(src: asset_path(sources)))
@@ -265,7 +265,7 @@
265
265
 
266
266
  if sources.is_a?(Array)
267
267
  content_tag(:audio, options) do
268
- sources.collect { |source| tag(:source, src: asset_path(source)) }.join
268
+ sources.collect { |source| tag(:source, src: asset_path(source)) }.join("\n")
269
269
  end
270
270
  else
271
271
  tag(:audio, options.reverse_merge(src: asset_path(sources)))
@@ -363,9 +363,8 @@
363
363
 
364
364
  # @private
365
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
366
+ host = settings.assets_host rescue settings.assets_host(source, request)
367
+ host ? host + source : source
369
368
  end
370
369
  end
371
370
  end
@@ -1,5 +1,5 @@
1
1
  module Padrino
2
2
  module Assets
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -1,8 +1,8 @@
1
1
  namespace :assets do
2
2
  desc 'Removes backups for existing assets'
3
3
  task :cleanup, :quanity do |task, args|
4
- quanity = args['quanity'] || 2
5
- manifest = Padrino::Assets.manifest
6
- manifest.cleanup(quanity)
4
+ quanity = args['quanity'] || 2
5
+ manifest = Padrino::Assets.manifest
6
+ manifest.cleanup(quanity)
7
7
  end
8
8
  end
@@ -1,7 +1,7 @@
1
1
  namespace :assets do
2
2
  desc 'Deletes all compiled assets'
3
3
  task :clobber do
4
- manifest = Padrino::Assets.manifest
5
- manifest.clobber
4
+ manifest = Padrino::Assets.manifest
5
+ manifest.clobber
6
6
  end
7
7
  end
@@ -1 +1,14 @@
1
- 
1
+ namespace :assets do
2
+ desc 'Compresses all compiled assets'
3
+ task :compress do
4
+ environment = Padrino::Assets.environment
5
+ manifest = Padrino::Assets.manifest
6
+
7
+ manifest.assets.each do |asset, digested_asset|
8
+ if asset = environment[asset]
9
+ compressed_asset = File.join(manifest.dir, digested_asset)
10
+ asset.write_to(compressed_asset + '.gz') if compressed_asset =~ /\.(?:css|html|js|svg|txt|xml)$/
11
+ end
12
+ end
13
+ end
14
+ end
@@ -21,6 +21,10 @@
21
21
  manifest.compile(logical_path)
22
22
  end
23
23
  end
24
+
25
+ if app.compress_assets?
26
+ Rake::Task['assets:compress'].invoke
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.add_dependency 'sprockets', '~> 2.2.0'
20
-
19
+ s.add_dependency 'sprockets', '~> 2.3.0'
20
+
21
21
  s.add_dependency 'padrino-core'
22
22
  s.add_dependency 'padrino-helpers'
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-12 00:00:00.000000000Z
12
+ date: 2012-01-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
16
- requirement: &8494660 !ruby/object:Gem::Requirement
16
+ requirement: &9246510 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 2.2.0
21
+ version: 2.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *8494660
24
+ version_requirements: *9246510
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: padrino-core
27
- requirement: &8564010 !ruby/object:Gem::Requirement
27
+ requirement: &9246250 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *8564010
35
+ version_requirements: *9246250
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: padrino-helpers
38
- requirement: &8566720 !ruby/object:Gem::Requirement
38
+ requirement: &9245990 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *8566720
46
+ version_requirements: *9245990
47
47
  description: A plugin for the Padrino web framework which uses Sprockets to manage
48
48
  and compile assets
49
49
  email: