classy_assets 0.10.0 → 0.11.0

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
  SHA1:
3
- metadata.gz: 7ae68f4846cdfc63757cd698e09ccb68299ba1e1
4
- data.tar.gz: bfcadb8dbf17457e24675413a9c4c77941ec3fb5
3
+ metadata.gz: 26174ebc523413bc8b6a44a4bf0cbc678d268875
4
+ data.tar.gz: c51ecdc69a290e271c5302c0bf2d36b0a9c3c667
5
5
  SHA512:
6
- metadata.gz: 61802ad99b6dadbd523bcd0a69f84ef66f56f496f974914b2b88dae310e0d85fd95dc3ea65f883653d689a7f7a4bb8464ee596f6416246ef6f61e9299640537a
7
- data.tar.gz: 83a22842adb3bcb5fe5aadc093a898211179f15ec1ed94876855a2fc28464d778c70eb2b04c59b7ba571e6045e1ac860592b53ae441bb9b15a77560b7849aeed
6
+ metadata.gz: 44d6352fd0cd68dd6fce74e9485005c77a84a2c74a2fd3819a80abd888de4d95d01ae182f76ab0f54961d797f736fedb563f2f46623b6331e783044ae448abea
7
+ data.tar.gz: 639ee59717f6e78c4ecae87dcf03f1a8d1bd03111aed6097ad0fb5b8c233ea15447d999afc08021e20c00989263bbd55a21ab07882b4df4aeb20fc106ad428f6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ClassyAssets
2
2
 
3
- Classy Assets (powered by Sprockets) for Sinatra and Rack apps
3
+ Sprockets-powered asset pipeline for classy Sinatra and/or Rack apps.
4
4
 
5
5
  ## Installation
6
6
 
@@ -14,18 +14,27 @@ And then execute:
14
14
 
15
15
  ## Usage
16
16
 
17
- ClassyAssets is available as Rack Middleware or a Sintra Extension. The Sinatra Extension version integrates the [sprockets-helpers](https://github.com/petebrowne/sprockets-helpers) to provide helper methods for generating asset paths.
17
+ ClassyAssets consists of a **Rack Middleware**, which integrates your app with [Sprockets](https://github.com/sstephenson/sprockets) to serve your assets, and a **Sintra Extension**, which provides helper methods for generating asset paths.
18
18
 
19
- Use the Rack Middleware directly:
19
+ Configure your environment:
20
20
 
21
21
  ````ruby
22
- require 'rack/classy_assets'
23
- class ClassyApp < Sinatra::Base
24
- use Rack::ClassyAssets, root: 'path/to/your/app/root/directory'
22
+ require 'classy_assets'
23
+ ClassyAssets.config do |config|
24
+ config.asset_root = File.expand_path('../../', __FILE__)
25
+ # asset_root is required and must be set.
26
+ # See below for complete list of options.
25
27
  end
26
28
  ````
27
29
 
28
- Use the Sinatra Extension:
30
+ Install the Rack Middleware (usually in `config.ru`):
31
+
32
+ ````ruby
33
+ require 'rack/classy_assets'
34
+ use Rack::ClassyAssets
35
+ ````
36
+
37
+ Install the Sinatra Extension:
29
38
 
30
39
  ````ruby
31
40
  require 'sinatra/classy_assets'
@@ -34,30 +43,27 @@ class ClassyApp < Sinatra::Base
34
43
  end
35
44
  ````
36
45
 
37
- Both the middleware and extension assume your assets are stored in the `root` directory, in the following layout:
38
-
39
- /assets
40
- |_ images
41
- |_ stylesheets
42
- |_ javascripts
43
-
44
- Sass and CoffeeScript are fully supported.
45
-
46
- Available Options:
47
-
48
- Pass these in via the options hash if you're using the rack middleware.
49
- If you're using the sinatra extension, then configure your app's `settings` after the `register Sintra::ClassyAssets` statement to override the defaults
46
+ Available Configuration Options:
50
47
 
51
48
  ````ruby
52
- :root # => path to root of the application. set by default in Sinatra apps, but must be explictly passed to the rack middleware, if used directly
53
- :public_folder # => path to public folder for the application. (default: File.join(root, 'public') )
54
- :assets_prefix # => currently does nothing useful (default: 'assets')
55
- :asset_host # => used by Sprockets::Helpers to return asset path prefixed by asset_host uri (default: nil)
56
- :digest_assets # => enable digest version of assets? true or false (default: false)
57
- :css_compressor # => instance of a sprokets compatible css compressor class (default: ::YUI::CssCompressor.new)
58
- :js_compressor # => instance of a sprokets compatible js compressor class (default: ::Uglifier.new)
59
- :sprockets # => instance of Sprockets::Environment. Should almost never need to be set manually. (default: Sprockets::Environment.new(root) )
49
+ :asset_root # => (String) path to root of the application (required, must be set before configuring other options)
50
+ :asset_cache # => (Boolean) enable/disable Sprockets environment caching (default: true in production, false in all other environments)
51
+ :asset_compress # => (Boolean) enable/disable asset compression (default: nil)
52
+ :asset_debug # => (Boolean) enable/disable asset debugging (default: true in development, false in all other environments)
53
+ :asset_digest # => (Boolean) enable/disable asset digests (default: nil)
54
+ :asset_host # => (String) CDN hostname to use when building asset urls (default: nil)
55
+ :asset_manifest_path # => (String) path to output Sprockets manifest file (default: asset_precompile_path + "manifest.json")
56
+ :asset_paths # => (Array) array of paths to add to the Sprockets environment (default: all paths under File.join(asset_root, asset_prefix))
57
+ :asset_precompile # => (Array) array of files to precompile. Globs and Regular Expressions are allowed. (default: [/\w+\.(?!js|css).+/, /application.(css|js)$/])
58
+ :asset_precompile_keep # => (Integer) number of precompiled asset versions to keep (default: 2)
59
+ :asset_precompile_path # => (String) path to output precompiled assets to (default: File.join(asset_public_path, asset_prefix))
60
+ :asset_prefix # => (String) name of the directory assets should be stored/served under (default: 'assets')
61
+ :asset_public_path # => (String) path to your app's public folder (default: File.join(asset_root, 'public'))
62
+ :asset_version # => (String) arbitrary asset version, used by Sprockets (default: the version of ClassyAssets in use)
63
+ :css_compressor # => (Symbol) name of a css compressor registered with Sprockets (default: :yui)
64
+ :js_compressor # => (Symbol) name of a javascript compressor registered with Sprockets (default: :uglifier)
60
65
  ````
66
+
61
67
  ## Project Status
62
68
 
63
69
  - Build: [![Build Status](https://secure.travis-ci.org/styleseek/classy_assets.png?branch=master)](https://travis-ci.org/styleseek/classy_assets)
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = ClassyAssets::VERSION
9
9
  gem.authors = ['StyleSeek Engineering']
10
10
  gem.email = ['engineering@styleseek.com']
11
- gem.description = %q{Asset Pipeline for classy Sinatra apps}
12
- gem.summary = %q{Classy Assets (powered by Sprockets) for Sinatra and Rack apps}
11
+ gem.description = %q{Asset Pipeline for classy Sinatra (and/or Rack) apps}
12
+ gem.summary = %q{Sprockets-powered asset pipeline for classy Sinatra and/or Rack apps.}
13
13
  gem.homepage = 'https://github.com/styleseek/classy_assets'
14
14
  gem.license = 'MIT'
15
15
 
@@ -1,3 +1,3 @@
1
1
  module ClassyAssets
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -1,20 +1,84 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'classy_assets'
4
- require 'rack/builder'
4
+ require 'rack/file'
5
+ require 'rack/utils'
6
+ require 'rack/mime'
5
7
 
6
8
  module Rack
7
9
  class ClassyAssets
8
10
  def initialize(app)
9
11
  @app = app
12
+ @file_server = ::Rack::File.new(::ClassyAssets.config.asset_public_path, { 'Cache-Control' => 'public, max-age=31536000' })
10
13
  end
11
14
 
12
15
  def call(env)
13
- if env['PATH_INFO'] =~ /\/#{::ClassyAssets.config.asset_prefix}\//
14
- Rack::URLMap.new("/#{::ClassyAssets.config.asset_prefix}" => ::ClassyAssets.sprockets).call(env)
16
+ if %w(GET HEAD).include?(env['REQUEST_METHOD']) and env['PATH_INFO'].start_with?("/#{::ClassyAssets.config.asset_prefix}")
17
+ puts "ClassyAssets: GET or HEAD request"
18
+ request = Rack::Request.new(env)
19
+ encoding = Rack::Utils.select_best_encoding(%w(gzip identity), request.accept_encoding)
20
+ if encoding == 'gzip'
21
+ puts "ClassyAssets: encoding == gzip"
22
+ return serve_gzipped_asset(env)
23
+ else
24
+ puts "ClassyAssets: encoding != gzip"
25
+ return serve_asset(env)
26
+ end
27
+ end
28
+
29
+ status, headers, body = @app.call(env)
30
+ body.close if body.respond_to?(:close)
31
+ [status, headers, body]
32
+ end
33
+
34
+ private
35
+
36
+ def asset_path_exists?(path)
37
+ full_path = ::File.join(::ClassyAssets.config.asset_public_path, path)
38
+ ::File.exists?(full_path)
39
+ end
40
+
41
+ def serve_gzipped_asset(env)
42
+ compressed_path = env['PATH_INFO'] + '.gz'
43
+ if asset_path_exists?(compressed_path)
44
+ puts "ClassyAssets: gzip asset path exists"
45
+ env["PATH_INFO"] = compressed_path
46
+ status, headers, body = @file_server.call(env)
47
+ path = env["PATH_INFO"] = env["PATH_INFO"].chomp('.gz')
48
+
49
+ vary = headers["Vary"].to_s.split(",").map { |v| v.strip }
50
+ unless vary.include?("*") || vary.include?("Accept-Encoding")
51
+ headers["Vary"] = vary.push("Accept-Encoding").join(",")
52
+ end
53
+
54
+ headers['Content-Encoding'] = 'gzip'
55
+ headers['Content-Type'] = Rack::Mime.mime_type(File.extname(path), 'text/plain')
56
+ headers.delete('Content-Length')
57
+
58
+ if headers.has_key? 'Cache-Control'
59
+ headers['Cache-Control'] += ', no-transform' unless headers['Cache-Control'].include?('no-transform')
60
+ else
61
+ headers['Cache-Control'] = 'no-transform'
62
+ end
63
+ else
64
+ puts "ClassyAssets: gzip asset path not found"
65
+ env["PATH_INFO"].gsub!("/#{::ClassyAssets.config.asset_prefix}", '')
66
+ status, headers, body = ::ClassyAssets.sprockets.call(env)
67
+ end
68
+
69
+ [status, headers, body]
70
+ end
71
+
72
+ def serve_asset(env)
73
+ if asset_path_exists?(env['PATH_INFO'])
74
+ puts "ClassyAssets: asset path exists"
75
+ status, headers, body = @file_server.call(env)
15
76
  else
16
- @app.call(env)
77
+ puts "ClassyAssets: asset path not found"
78
+ status, headers, body = ::ClassyAssets.sprockets.call(env)
17
79
  end
80
+
81
+ [status, headers, body]
18
82
  end
19
83
  end
20
84
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - StyleSeek Engineering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2013-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sprockets
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
- description: Asset Pipeline for classy Sinatra apps
97
+ description: Asset Pipeline for classy Sinatra (and/or Rack) apps
98
98
  email:
99
99
  - engineering@styleseek.com
100
100
  executables:
@@ -164,7 +164,7 @@ rubyforge_project:
164
164
  rubygems_version: 2.0.5
165
165
  signing_key:
166
166
  specification_version: 4
167
- summary: Classy Assets (powered by Sprockets) for Sinatra and Rack apps
167
+ summary: Sprockets-powered asset pipeline for classy Sinatra and/or Rack apps.
168
168
  test_files:
169
169
  - spec/classy_assets/config_spec.rb
170
170
  - spec/classy_assets/sprockets_spec.rb