sinatra-assetpack 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sinatra-assetpack (0.1.2)
4
+ sinatra-assetpack (0.1.3)
5
5
  jsmin
6
6
  rack-test
7
7
  sinatra
@@ -29,9 +29,9 @@ GEM
29
29
  metaclass (0.0.1)
30
30
  mocha (0.13.2)
31
31
  metaclass (~> 0.0.1)
32
- multi_json (1.5.0)
32
+ multi_json (1.6.0)
33
33
  open4 (1.3.0)
34
- rack (1.5.0)
34
+ rack (1.5.2)
35
35
  rack-protection (1.3.2)
36
36
  rack
37
37
  rack-test (0.6.2)
@@ -66,6 +66,6 @@ DEPENDENCIES
66
66
  rake
67
67
  sass
68
68
  sinatra-assetpack!
69
- stylus
69
+ stylus (< 0.7.1)
70
70
  uglifier
71
71
  yui-compressor
data/HISTORY.md CHANGED
@@ -1,3 +1,12 @@
1
+ v0.1.4 - Feb 12, 2013
2
+ ----------------------
3
+
4
+ ### Added
5
+ * Multiple asset hosts support. (#27)
6
+
7
+ ### Fixed
8
+ * Lock stylus to 0.7.0 until 0.7.1 is supported.
9
+
1
10
  v0.1.3 - Feb 3, 2013
2
11
  ----------------------
3
12
 
data/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  > Package your assets transparently in Sinatra.
4
4
 
5
- [![Build Status](https://travis-ci.org/rstacruz/sinatra-assetpack.png)](https://travis-ci.org/rstacruz/sinatra-assetpack)
5
+ [![Build Status](https://travis-ci.org/rstacruz/sinatra-assetpack.png?branch=master)](https://travis-ci.org/rstacruz/sinatra-assetpack)
6
+ [![Gem Version](https://badge.fury.io/rb/sinatra-assetpack.png)](http://badge.fury.io/rb/sinatra-assetpack)
6
7
  [![Dependency Status](https://gemnasium.com/rstacruz/sinatra-assetpack.png)](https://gemnasium.com/rstacruz/sinatra-assetpack)
7
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rstacruz/sinatra-assetpack)
8
+ [![Code Climate](https://codeclimate.com/github/rstacruz/sinatra-assetpack.png)](https://codeclimate.com/github/rstacruz/sinatra-assetpack)
8
9
 
9
10
  How it works
10
11
  ------------
@@ -26,7 +26,18 @@ class App < Sinatra::Base
26
26
  '/css/more/*.css'
27
27
  ]
28
28
 
29
- prebuild true
29
+ prebuild false
30
+
31
+ # Can set this as an environment variable like "HOST" or "CDN_HOST"
32
+ # This will add the domain name to the beginning of compiled assets
33
+ # Useful if you need to serve production assets from a CDN
34
+ asset_hosts [
35
+ '//cdn-0.example.org',
36
+ '//cdn-1.example.org',
37
+ '//cdn-2.example.org',
38
+ '//cdn-3.example.org'
39
+ ]
40
+
30
41
  end
31
42
 
32
43
  get '/' do
@@ -11,7 +11,7 @@ module Sinatra
11
11
  if options.to_s.include?('embed')
12
12
  to_data_uri(local)
13
13
  else
14
- BusterHelpers.add_cache_buster(file, local)
14
+ HtmlHelpers.get_file_uri(file, assets)
15
15
  end
16
16
  else
17
17
  path
@@ -15,7 +15,9 @@ module Sinatra
15
15
  local = settings.assets.local_file_for src
16
16
  if local
17
17
  i = Image[local]
18
- attrs[:src] = BusterHelpers.add_cache_buster(src, local)
18
+
19
+ attrs[:src] = HtmlHelpers.get_file_uri(src, settings.assets)
20
+
19
21
  if i.dimensions?
20
22
  attrs[:width] ||= i.width
21
23
  attrs[:height] ||= i.height
@@ -12,6 +12,18 @@ module Sinatra
12
12
  def kv(hash)
13
13
  hash.map { |k, v| " #{e k}='#{e v}'" }.join('')
14
14
  end
15
+
16
+ def get_file_uri(file, assets)
17
+ raise RuntimeError, "You must pass in an asset for a URI to be created for it." if file.nil?
18
+
19
+ local = assets.local_file_for file
20
+
21
+ if assets.asset_hosts.nil?
22
+ BusterHelpers.add_cache_buster(file, local)
23
+ else
24
+ assets.asset_hosts[Digest::MD5.hexdigest(file).to_i(16) % assets.asset_hosts.length]+BusterHelpers.add_cache_buster(file, local)
25
+ end
26
+ end
15
27
  end
16
28
  end
17
29
  end
@@ -153,6 +153,7 @@ module Sinatra
153
153
  attrib :js_compression # Symbol, compression method for JS
154
154
  attrib :css_compression # Symbol, compression method for CSS
155
155
  attrib :output_path # '/public'
156
+ attrib :asset_hosts # [ 'http://cdn0.example.org', 'http://cdn1.example.org' ]
156
157
 
157
158
  attrib :js_compression_options # Hash
158
159
  attrib :css_compression_options # Hash
@@ -110,10 +110,12 @@ module Sinatra
110
110
 
111
111
  private
112
112
  def link_tag(file, options={})
113
+ file_path = HtmlHelpers.get_file_uri(file, @assets)
114
+
113
115
  if js?
114
- "<script src='#{e file}'#{kv options}></script>"
116
+ "<script src='#{file_path}'#{kv options}></script>"
115
117
  elsif css?
116
- "<link rel='stylesheet' href='#{e file}'#{kv options} />"
118
+ "<link rel='stylesheet' href='#{file_path}'#{kv options} />"
117
119
  end
118
120
  end
119
121
  end
@@ -1,7 +1,7 @@
1
1
  module Sinatra
2
2
  module AssetPack
3
3
  def self.version
4
- "0.1.3"
4
+ "0.1.4"
5
5
  end
6
6
  end
7
7
  end
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency "coffee-script"
25
25
  s.add_development_dependency "contest"
26
26
  s.add_development_dependency "mocha"
27
- s.add_development_dependency "stylus"
27
+ s.add_development_dependency "stylus", "< 0.7.1"
28
28
  s.add_development_dependency "uglifier"
29
29
  s.add_development_dependency "rake"
30
30
  s.add_development_dependency "less"
data/test/glob_test.rb CHANGED
@@ -21,6 +21,7 @@ class GlobTest < UnitTest
21
21
  end
22
22
 
23
23
  should "match double-star globs recursively" do
24
+ app.stubs(:development?).returns(true)
24
25
  get '/a'
25
26
  assert body.include?("a/b/c1/hello.")
26
27
  assert body.include?("a/b/c2/hi.")
@@ -28,12 +29,14 @@ class GlobTest < UnitTest
28
29
  end
29
30
 
30
31
  should "match single-star globs in filenames" do
32
+ app.stubs(:development?).returns(true)
31
33
  get '/b'
32
34
  assert body.include?("a/b/c2/hi.")
33
35
  assert body.include?("a/b/c2/hola.")
34
36
  end
35
37
 
36
38
  should "match single-star globs in paths" do
39
+ app.stubs(:development?).returns(true)
37
40
  get '/c'
38
41
  assert body.include?("a/b/c1/hello.")
39
42
  assert body.include?("a/b/c2/hi.")
@@ -5,6 +5,7 @@ class RedundantTest < UnitTest
5
5
  Main.get("/helpers/css/redundant") { css :redundant }
6
6
 
7
7
  test "redundant" do
8
+ app.stubs(:development?).returns(true)
8
9
  get '/helpers/css/redundant'
9
10
  assert body.scan(/screen/).count == 1
10
11
  end
data/test/test_helper.rb CHANGED
@@ -8,6 +8,8 @@ require 'rack/test'
8
8
  require 'yaml'
9
9
  require 'mocha/setup'
10
10
 
11
+ ENV['RACK_ENV'] = 'test'
12
+
11
13
  require File.expand_path('../app/app.rb', __FILE__)
12
14
 
13
15
  class UnitTest < Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-assetpack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-09 00:00:00.000000000 Z
12
+ date: 2013-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tilt
@@ -176,16 +176,16 @@ dependencies:
176
176
  prerelease: false
177
177
  requirement: !ruby/object:Gem::Requirement
178
178
  requirements:
179
- - - ! '>='
179
+ - - <
180
180
  - !ruby/object:Gem::Version
181
- version: '0'
181
+ version: 0.7.1
182
182
  none: false
183
183
  type: :development
184
184
  version_requirements: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - ! '>='
186
+ - - <
187
187
  - !ruby/object:Gem::Version
188
- version: '0'
188
+ version: 0.7.1
189
189
  none: false
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: uglifier