classy_assets 0.3.2 → 0.4.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: 289abc558c8af9f0dba66ba6850276bed511c54e
4
- data.tar.gz: 542f4ea0c14dcf7eb4b2790374490838f86e48b0
3
+ metadata.gz: 16e0896b4b3b3115e122a6ef5eef0b9b2bc43884
4
+ data.tar.gz: f2cffb4da33ba1d3f2869dc2d8f1456482279407
5
5
  SHA512:
6
- metadata.gz: f0aff58ce2dd9efbf9c8bcc61f0013d8be824a1f978f56a2464608c2f05f4d05c7d9758117f316c76de4951abb446a68dd2a8e739b5ff743b2923daa78ced951
7
- data.tar.gz: 0b293667468c7392fbf363dd2e004c84bb8d56756ccb78c414677aca332e2d95673a207c383f2774457e684571300fd2c7d5bf80b16a3af272914ed8fc7b2f6a
6
+ metadata.gz: afa26b7e3ef4b4870911d234a9c0c64043aa6946a3246ed25276afa1fb8fdf89e1fb1317290c3f9529b831ea6d898428005d1ebabc8db00ce42fae7dd654f023
7
+ data.tar.gz: 047bcb382fb9f5141c7b471b5a33b85ecd1a77d7cb67d175b3d29294abd994c1b0b4460e0388e34b1774546594201c4dab015072e2ed9e9a3332a5210464a621
data/Gemfile CHANGED
@@ -1,4 +1,10 @@
1
1
  source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in classy_assets.gemspec
4
2
  gemspec
3
+
4
+ group :development, :test do
5
+ gem 'slim', require: false
6
+ gem 'minitest', require: false
7
+ gem 'minitest-spec-context', require: false
8
+ gem 'minitest-reporters', require: false
9
+ gem 'rack-test', require: false
10
+ end
@@ -30,8 +30,5 @@ Gem::Specification.new do |gem|
30
30
 
31
31
  gem.add_development_dependency 'bundler', '~> 1.3'
32
32
  gem.add_development_dependency 'rake'
33
- gem.add_development_dependency 'pry'
34
- gem.add_development_dependency 'minitest'
35
- gem.add_development_dependency 'minitest-reporters'
36
- gem.add_development_dependency 'rack-test'
33
+ gem.add_development_dependency 'gem-release'
37
34
  end
data/lib/classy_assets.rb CHANGED
@@ -6,107 +6,29 @@ require 'coffee_script'
6
6
  require 'sprockets'
7
7
  require 'sprockets-sass'
8
8
  require 'sinatra/base'
9
+ require 'classy_assets/configuration'
9
10
  require 'classy_assets/version'
10
11
 
11
12
  module ClassyAssets
12
- class Configuration
13
- def self.configure
14
- yield self
15
- end
16
-
17
- def self.asset_digest
18
- @asset_digest.nil? ? false : @asset_digest
19
- end
20
-
21
- def self.asset_digest=(digest)
22
- @asset_digest = digest
23
- end
24
-
25
- def self.asset_paths
26
- @asset_paths || build_asset_path(%w(fonts images javascripts stylesheets))
27
- end
28
-
29
- def self.asset_paths=(paths)
30
- @asset_paths = paths.to_a
31
- end
32
-
33
- def self.asset_host
34
- @asset_host
35
- end
36
-
37
- def self.asset_host=(host)
38
- @asset_host = host
39
- end
40
-
41
- def self.asset_host_protocol
42
- @asset_host_protocol || :relative
43
- end
44
-
45
- def self.asset_host_protocol=(protocol)
46
- @asset_host_protocol = protocol
47
- end
48
-
49
- def self.asset_prefix
50
- @asset_prefix || 'assets'
51
- end
52
-
53
- def self.asset_prefix=(prefix)
54
- @asset_prefix = prefix
55
- end
56
-
57
- def self.css_compressor
58
- @css_compressor || :yui
59
- end
60
-
61
- def self.css_compressor=(compressor)
62
- @css_compressor = compressor
63
- end
64
-
65
- def self.debug_mode
66
- @debug_mode.nil? ? (ENV['RACK_ENV'] == 'development') : @debug_mode
67
- end
68
-
69
- def self.debug_mode=(debug)
70
- @debug_mode = debug
71
- end
72
-
73
- def self.js_compressor
74
- @js_compressor || :uglifier
75
- end
76
-
77
- def self.js_compressor=(compressor)
78
- @js_compressor = compressor
79
- end
80
-
81
- def self.public_path
82
- @public_path || File.join(root_path, 'public')
83
- end
84
-
85
- def self.public_path=(path)
86
- @public_path = path
87
- end
88
-
89
- def self.root_path
90
- @root_path || '.'
91
- end
92
-
93
- def self.root_path=(path)
94
- @root_path = path
95
- end
13
+ def self.asset_url_for(asset)
14
+ asset = asset.instance_of?(::Sprockets::BundledAsset) ? asset : Configuration.sprockets[asset].logical_path
15
+ asset = build_digest_filename(asset) if Configuration.asset_digest
16
+ debug = (Configuration.debug_mode) ? '?body=1' : ''
17
+ "#{Configuration.asset_host}/#{Configuration.asset_prefix}/#{asset}#{debug}"
18
+ end
96
19
 
97
- def self.build_asset_path(dir_names)
98
- dir_names.map! do |dir_name|
99
- File.join(root_path, asset_prefix, dir_name)
100
- end
101
- dir_names
102
- end
20
+ def self.build_digest_filename(asset)
21
+ filename = asset.split(".")
22
+ ext = filename.pop
23
+ "#{filename.join('.')}-#{Configuration.sprockets.digest}.#{ext}"
24
+ end
103
25
 
104
- def self.sprockets
105
- @sprockets ||= ::Sprockets::Environment.new(root_path)
106
- asset_paths.each do |asset_path|
107
- @sprockets.append_path asset_path unless @sprockets.paths.include?(asset_path)
108
- end
109
- @sprockets
110
- end
26
+ def self.asset_tag_from(sources, ext)
27
+ sources = [sources] unless sources.is_a? Array
28
+ sources.map do |source|
29
+ source = "#{source}.#{ext}" unless source =~ /\.#{ext}$/
30
+ asset_url = (source =~ /\/|http/) ? source : ::ClassyAssets.asset_url_for(source)
31
+ yield(asset_url)
32
+ end.join('')
111
33
  end
112
34
  end
@@ -0,0 +1,94 @@
1
+ # encoding: utf-8
2
+
3
+ module ClassyAssets
4
+ class Configuration
5
+ def self.configure
6
+ yield self
7
+ end
8
+
9
+ def self.asset_digest
10
+ @asset_digest.nil? ? false : @asset_digest
11
+ end
12
+
13
+ def self.asset_digest=(digest)
14
+ @asset_digest = digest
15
+ end
16
+
17
+ def self.asset_host
18
+ @asset_host
19
+ end
20
+
21
+ def self.asset_host=(host)
22
+ @asset_host = host
23
+ end
24
+
25
+ def self.asset_paths
26
+ @asset_paths || build_asset_paths
27
+ end
28
+
29
+ def self.asset_paths=(paths)
30
+ @asset_paths = paths.to_a
31
+ end
32
+
33
+ def self.asset_prefix
34
+ @asset_prefix || 'assets'
35
+ end
36
+
37
+ def self.asset_prefix=(prefix)
38
+ @asset_prefix = prefix
39
+ end
40
+
41
+ def self.debug_mode
42
+ @debug_mode.nil? ? (ENV['RACK_ENV'] == 'development') : @debug_mode
43
+ end
44
+
45
+ def self.debug_mode=(debug)
46
+ @debug_mode = debug
47
+ end
48
+
49
+ def self.public_path
50
+ @public_path || File.join(root_path, 'public')
51
+ end
52
+
53
+ def self.public_path=(path)
54
+ @public_path = path
55
+ end
56
+
57
+ def self.root_path
58
+ @root_path || '.'
59
+ end
60
+
61
+ def self.root_path=(path)
62
+ @root_path = path
63
+ end
64
+
65
+ def self.sprockets
66
+ new_sprockets_environment
67
+ end
68
+
69
+ private
70
+
71
+ def self.build_asset_paths
72
+ Dir.glob(File.join(root_path, asset_prefix, '*'))
73
+ end
74
+
75
+ def self.new_sprockets_environment
76
+ @sprockets = ::Sprockets::Environment.new(root_path)
77
+ asset_paths.each do |asset_path|
78
+ unless @sprockets.paths.include?(asset_path)
79
+ @sprockets.append_path asset_path
80
+ end
81
+ end
82
+
83
+ @sprockets.context_class.class_eval do
84
+ def asset_path(path, options = {})
85
+ depend_on_asset(path)
86
+ asset = environment.find_asset(path)
87
+ ClassyAssets.asset_url_for(asset.logical_path)
88
+ end
89
+ end
90
+
91
+ @sprockets
92
+ end
93
+ end
94
+ end
@@ -1,3 +1,3 @@
1
1
  module ClassyAssets
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -4,53 +4,11 @@ require 'classy_assets'
4
4
 
5
5
  module Rack
6
6
  class ClassyAssets < Sinatra::Base
7
- def initialize(app)
8
- super(app)
9
- @sprockets = ::ClassyAssets::Configuration.sprockets
10
- end
11
-
12
- set :asset_prefix, ::ClassyAssets::Configuration.asset_prefix
13
-
14
- get "/#{settings.asset_prefix}/*.js" do |script|
15
- content_type("application/javascript")
16
- @sprockets["#{script}.js"] || halt(404)
17
- end
18
-
19
- get "/#{settings.asset_prefix}/*.css" do |stylesheet|
20
- content_type("text/css")
21
- @sprockets["#{stylesheet}.css"] || halt(404)
22
- end
23
-
24
- %w(jpeg jpg png gif webp).each do |format|
25
- get "/#{settings.asset_prefix}/*.#{format}" do |image|
26
- content_type("image/#{(format == 'jpg') ? 'jpeg' : format}")
27
- @sprockets["#{image}.#{format}"] || halt(404)
28
- end
29
- end
30
-
31
- get "/#{settings.asset_prefix}/*.ttf" do |font|
32
- content_type('application/x-font-truetype')
33
- @sprockets["#{font}.ttf"] || halt(404)
34
- end
35
-
36
- get "/#{settings.asset_prefix}/*.eot" do |font|
37
- content_type('application/vnd.ms-fontobject')
38
- @sprockets["#{font}.eot"] || halt(404)
39
- end
40
-
41
- get "/#{settings.asset_prefix}/*.svg" do |font|
42
- content_type('image/svg+xml')
43
- @sprockets["#{font}.svg"] || halt(404)
44
- end
45
-
46
- get "/#{settings.asset_prefix}/*.woff" do |font|
47
- content_type('application/x-font-woff')
48
- @sprockets["#{font}.woff"] || halt(404)
49
- end
50
-
51
- get "/#{settings.asset_prefix}/*.otf" do |font|
52
- content_type('application/x-font-opentype')
53
- @sprockets["#{font}.otf"] || halt(404)
54
- end
7
+ ::ClassyAssets::Configuration.sprockets.mime_types.each do |ext, content_type|
8
+ get "/#{::ClassyAssets::Configuration.asset_prefix}/*#{ext}" do |asset|
9
+ content_type content_type
10
+ ::ClassyAssets::Configuration.sprockets["#{asset}#{ext}"] || halt(404)
11
+ end
12
+ end
55
13
  end
56
14
  end
@@ -1,34 +1,28 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'rack/classy_assets'
4
- require 'sinatra/sprockets-helpers'
5
4
 
6
5
  module Sinatra
7
6
  module ClassyAssets
8
- def self.registered(app)
9
- app.use Rack::ClassyAssets
10
- app.register Sprockets::Helpers
11
- app.configure do
12
- ::Sprockets::Helpers.configure do |config|
13
- classy_config = ::ClassyAssets::Configuration
14
- manifest_file = ::File.join(config.public_path,
15
- classy_config.asset_prefix,
16
- 'manifset.json')
17
-
18
- config.asset_host = classy_config.asset_host
19
- config.debug = classy_config.debug_mode
20
- config.digest = classy_config.asset_digest
21
- config.environment = classy_config.sprockets
22
- config.public_path = classy_config.public_path
23
- config.prefix = "/#{classy_config.asset_prefix}"
24
- config.protocol = classy_config.asset_host_protocol
25
-
26
- if ::File.exists? manifest_file
27
- config.manifest = ::Sprockets::Manifest.new(config.environment, manifest_file)
28
- end
7
+ module Helpers
8
+ def stylesheet_tag(sources, options = {})
9
+ options = { media: 'screen' }.merge(options)
10
+ ::ClassyAssets.asset_tag_from(sources, 'css') do |asset_url|
11
+ %Q{<link href="#{asset_url}" media="#{options[:media]}" rel="stylesheet">}
12
+ end
13
+ end
14
+
15
+ def javascript_tag(sources)
16
+ ::ClassyAssets.asset_tag_from(sources, 'js') do |asset_url|
17
+ %Q{<script src="#{asset_url}"></script>}
29
18
  end
30
19
  end
31
20
  end
21
+
22
+ def self.registered(app)
23
+ app.use ::Rack::ClassyAssets
24
+ app.helpers Helpers
25
+ end
32
26
  end
33
27
  register ClassyAssets
34
28
  end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'classy_assets'
5
+
6
+ describe ClassyAssets::Configuration do
7
+ before do
8
+ @root_path = File.expand_path('../support', __FILE__)
9
+ ClassyAssets::Configuration.configure do |config|
10
+ config.root_path = @root_path
11
+ end
12
+ @configuration = ClassyAssets::Configuration
13
+ @public_path = File.expand_path('../support/public', __FILE__)
14
+ @asset_paths = Dir.glob(File.join(@configuration.root_path, @configuration.asset_prefix, '*'))
15
+ end
16
+
17
+ it "returns the configured root_path" do
18
+ @configuration.root_path.must_equal @root_path
19
+ end
20
+
21
+ it "returns the computed public_path" do
22
+ @configuration.public_path.must_equal @public_path
23
+ end
24
+
25
+ it "returns an array of asset paths" do
26
+ @configuration.asset_paths.must_equal @asset_paths
27
+ end
28
+
29
+ it "returns the asset digest setting" do
30
+ @configuration.asset_digest.must_equal false
31
+ end
32
+
33
+ it "returns the asset host" do
34
+ @configuration.asset_host.must_equal nil
35
+ end
36
+
37
+ it "returns the asset prefix" do
38
+ @configuration.asset_prefix.must_equal 'assets'
39
+ end
40
+
41
+ it "returns the debug mode setting" do
42
+ @configuration.debug_mode.must_equal false
43
+ end
44
+
45
+ it "returns the sprockets environment" do
46
+ @configuration.sprockets.must_be_kind_of Sprockets::Environment
47
+ end
48
+
49
+ it "returns the correct paths" do
50
+ @configuration.sprockets.paths.must_equal @configuration.asset_paths
51
+ end
52
+ end
@@ -3,77 +3,64 @@
3
3
  require 'spec_helper'
4
4
  require 'classy_assets'
5
5
 
6
- describe ClassyAssets::Configuration do
7
- subject { ClassyAssets::Configuration }
8
- after do
9
- ClassyAssets::Configuration.root_path = nil
10
- ClassyAssets::Configuration.public_path = nil
11
- ClassyAssets::Configuration.sprockets.clear_paths
12
- end
13
-
14
- it "returns an array of asset directories" do
15
- paths = %w(fonts images javascripts stylesheets)
16
- paths.map! { |dir_name| File.join(ClassyAssets::Configuration.root_path, ClassyAssets::Configuration.asset_prefix, dir_name) }
17
- subject.asset_paths.must_equal paths
18
- end
19
-
20
- it "returns the asset digest setting" do
21
- subject.asset_digest.must_equal false
6
+ describe ClassyAssets do
7
+ before do
8
+ @root_path = File.expand_path('../support', __FILE__)
9
+ ClassyAssets::Configuration.configure do |config|
10
+ config.root_path = @root_path
11
+ end
22
12
  end
23
13
 
24
- it "returns the asset host" do
25
- subject.asset_host.must_equal nil
14
+ context "default configuration" do
15
+ it "returns the url to the asset" do
16
+ asset_url = ClassyAssets.asset_url_for 'application.js'
17
+ asset_url.must_equal '/assets/application.js'
18
+ end
26
19
  end
27
20
 
28
- it "returns the asset prefix" do
29
- subject.asset_prefix.must_equal 'assets'
30
- end
21
+ context "debug mode" do
22
+ before do
23
+ ClassyAssets::Configuration.debug_mode = true
24
+ end
31
25
 
32
- it "returns the css compressor setting" do
33
- subject.css_compressor.must_equal :yui
34
- end
26
+ after do
27
+ ClassyAssets::Configuration.debug_mode = false
28
+ end
35
29
 
36
- it "returns the debug mode setting" do
37
- subject.debug_mode.must_equal false
38
- end
39
-
40
- it "returns the js compressor setting" do
41
- subject.js_compressor.must_equal :uglifier
30
+ it "returns the debug url to the asset" do
31
+ asset_url = ClassyAssets.asset_url_for 'application.js'
32
+ asset_url.must_equal '/assets/application.js?body=1'
33
+ end
42
34
  end
43
35
 
44
- it "returns the path to the public folder" do
45
- subject.public_path.must_equal './public'
46
- end
47
-
48
- it "returns the path to the root folder" do
49
- subject.root_path.must_equal '.'
50
- end
36
+ context "digest" do
37
+ before do
38
+ ClassyAssets::Configuration.asset_digest = true
39
+ @digest = ClassyAssets::Configuration.sprockets.digest
40
+ end
51
41
 
52
- it "returns the sprockets environment" do
53
- subject.sprockets.must_be_kind_of Sprockets::Environment
54
- end
42
+ after do
43
+ ClassyAssets::Configuration.asset_digest = false
44
+ end
55
45
 
56
- it "returns the correct asset paths" do
57
- subject.sprockets.paths.must_equal subject.asset_paths.map {|p| File.expand_path(p) }
46
+ it "returns the digest url to the asset" do
47
+ asset_url = ClassyAssets.asset_url_for 'application.js'
48
+ asset_url.must_equal "/assets/application-#{@digest}.js"
49
+ end
58
50
  end
59
51
 
60
- describe "configure" do
52
+ context "asset host" do
61
53
  before do
62
- @root_path = File.expand_path('../../support', __FILE__)
63
- @public_path = File.join(@root_path, 'public')
64
-
65
- ClassyAssets::Configuration.configure do |config|
66
- config.root_path = @root_path
67
- config.public_path = @public_path
68
- end
54
+ ClassyAssets::Configuration.asset_host = 'http://example.com'
69
55
  end
70
56
 
71
- it "returns the configured root_path" do
72
- ClassyAssets::Configuration.root_path.must_equal @root_path
57
+ after do
58
+ ClassyAssets::Configuration.asset_host = nil
73
59
  end
74
60
 
75
- it "returns the configured public_path" do
76
- ClassyAssets::Configuration.public_path.must_equal @public_path
61
+ it "returns the digest url to the asset" do
62
+ asset_url = ClassyAssets.asset_url_for 'application.js'
63
+ asset_url.must_equal "http://example.com/assets/application.js"
77
64
  end
78
65
  end
79
66
  end
@@ -3,28 +3,29 @@
3
3
  require 'spec_helper'
4
4
  require 'rack/classy_assets'
5
5
 
6
- class MiddlewareApp < Sinatra::Base
7
- use Rack::ClassyAssets
6
+ class ClassyApp < Sinatra::Base
7
+ configure do
8
+ ClassyAssets::Configuration.configure do |config|
9
+ config.root_path = File.expand_path('../../support', __FILE__)
10
+ end
11
+ end
12
+ use Rack::ClassyAssets
8
13
  end
9
14
 
10
15
  def app
11
- MiddlewareApp.new
16
+ ClassyApp.new
12
17
  end
13
18
 
14
- describe Rack::ClassyAssets do
15
- after do
16
- ClassyAssets::Configuration.sprockets.clear_paths
17
- end
18
-
19
- describe "stylesheets" do
20
- describe "css" do
21
- it "will respond sucessfully" do
19
+ describe Rack::ClassyAssets do
20
+ context "stylesheets" do
21
+ context "css" do
22
+ it "will respond sucessfully" do
22
23
  get '/assets/stylesheet.css'
23
24
  last_response.status.must_equal 200
24
25
  end
25
26
  end
26
27
 
27
- describe "sass" do
28
+ context "sass" do
28
29
  it "will respond sucessfully" do
29
30
  get '/assets/application.css'
30
31
  last_response.status.must_equal 200
@@ -32,15 +33,15 @@ describe Rack::ClassyAssets do
32
33
  end
33
34
  end
34
35
 
35
- describe "javascripts" do
36
- describe "js" do
36
+ context "javascripts" do
37
+ context "js" do
37
38
  it "will respond sucessfully" do
38
39
  get '/assets/javascript.js'
39
40
  last_response.status.must_equal 200
40
41
  end
41
42
  end
42
43
 
43
- describe "coffeescript" do
44
+ context "coffeescript" do
44
45
  it "will respond sucessfully" do
45
46
  get '/assets/application.js'
46
47
  last_response.status.must_equal 200
@@ -48,22 +49,22 @@ describe Rack::ClassyAssets do
48
49
  end
49
50
  end
50
51
 
51
- describe "images" do
52
- describe "gif" do
52
+ context "images" do
53
+ context "gif" do
53
54
  it "will respond sucessfully" do
54
55
  get '/assets/image.gif'
55
56
  last_response.status.must_equal 200
56
57
  end
57
58
  end
58
59
 
59
- describe "jpg" do
60
+ context "jpg" do
60
61
  it "will respond sucessfully" do
61
62
  get '/assets/image.jpg'
62
63
  last_response.status.must_equal 200
63
64
  end
64
65
  end
65
66
 
66
- describe "png" do
67
+ context "png" do
67
68
  it "will respond sucessfully" do
68
69
  get '/assets/image.png'
69
70
  last_response.status.must_equal 200
@@ -71,36 +72,36 @@ describe Rack::ClassyAssets do
71
72
  end
72
73
  end
73
74
 
74
- describe "fonts" do
75
- describe "eot" do
75
+ context "fonts" do
76
+ context "eot" do
76
77
  it "will respond sucessfully" do
77
78
  get '/assets/font.eot'
78
79
  last_response.status.must_equal 200
79
80
  end
80
81
  end
81
82
 
82
- describe "otf" do
83
+ context "otf" do
83
84
  it "will respond sucessfully" do
84
85
  get '/assets/font.otf'
85
86
  last_response.status.must_equal 200
86
87
  end
87
88
  end
88
89
 
89
- describe "svg" do
90
+ context "svg" do
90
91
  it "will respond sucessfully" do
91
92
  get '/assets/font.svg'
92
93
  last_response.status.must_equal 200
93
94
  end
94
95
  end
95
96
 
96
- describe "ttf" do
97
+ context "ttf" do
97
98
  it "will respond sucessfully" do
98
99
  get '/assets/font.ttf'
99
100
  last_response.status.must_equal 200
100
101
  end
101
102
  end
102
103
 
103
- describe "woff" do
104
+ context "woff" do
104
105
  it "will respond sucessfully" do
105
106
  get '/assets/font.woff'
106
107
  last_response.status.must_equal 200
@@ -3,108 +3,163 @@
3
3
  require 'spec_helper'
4
4
  require 'sinatra/classy_assets'
5
5
 
6
- class ExtensionApp < Sinatra::Base
6
+ class ClassyApp < Sinatra::Base
7
+ configure do
8
+ ClassyAssets::Configuration.configure do |config|
9
+ config.root_path = File.expand_path('../../support', __FILE__)
10
+ end
11
+ end
7
12
  register Sinatra::ClassyAssets
13
+
14
+ get "/with_css" do
15
+ slim :index, layout: :layout_css
16
+ end
17
+
18
+ get "/with_media_option" do
19
+ slim :index, layout: :layout_media
20
+ end
21
+
22
+ get "/with_js" do
23
+ slim :index, layout: :layout_js
24
+ end
25
+
26
+ template :layout_css do
27
+ "html\n\thead\n\t\t==stylesheet_tag('application')\n\tbody\n\t\t==yield\n"
28
+ end
29
+
30
+ template :layout_media do
31
+ "html\n\thead\n\t\t==stylesheet_tag('application', media: 'print')\n\tbody\n\t\t==yield\n"
32
+ end
33
+
34
+ template :layout_js do
35
+ "html\n\thead\n\tbody\n\t\t==javascript_tag('application')\n==yield\n"
36
+ end
37
+
38
+ template :index do
39
+ "| Classy Assets"
40
+ end
8
41
  end
9
42
 
10
43
  def app
11
- ExtensionApp.new
44
+ ClassyApp.new
12
45
  end
13
46
 
14
- describe Rack::ClassyAssets do
15
- after do
16
- ClassyAssets::Configuration.sprockets.clear_paths
47
+ describe Sinatra::ClassyAssets do
48
+ context "sprockets.context_class" do
49
+ it "resolves the url to the asset" do
50
+ get "/assets/application.css"
51
+ last_response.body.must_match(/background-url: "\/assets\/image.png";/)
52
+ end
17
53
  end
18
54
 
19
- describe "stylesheets" do
20
- describe "css" do
21
- it "will respond sucessfully" do
22
- get '/assets/stylesheet.css'
23
- last_response.status.must_equal 200
24
- end
25
- end
26
-
27
- describe "sass" do
28
- it "will respond sucessfully" do
29
- get '/assets/application.css'
30
- last_response.status.must_equal 200
31
- end
55
+ context "Helpers" do
56
+ it "outputs a stylesheet link tag" do
57
+ get "/with_css"
58
+ last_response.body.must_match(/<link href="\/assets\/application.css" media="screen" rel="stylesheet">/)
32
59
  end
33
- end
34
60
 
35
- describe "javascripts" do
36
- describe "js" do
37
- it "will respond sucessfully" do
38
- get '/assets/javascript.js'
39
- last_response.status.must_equal 200
40
- end
61
+ it "outputs the stylesheet tag with the correct media attribute" do
62
+ get "/with_media_option"
63
+ last_response.body.must_match(/<link href="\/assets\/application.css" media="print" rel="stylesheet">/)
41
64
  end
42
65
 
43
- describe "coffeescript" do
44
- it "will respond sucessfully" do
45
- get '/assets/application.js'
46
- last_response.status.must_equal 200
47
- end
66
+ it "outputs a javascript tag" do
67
+ get "/with_js"
68
+ last_response.body.must_match(/<script src="\/assets\/application.js"><\/script>/)
48
69
  end
49
70
  end
50
-
51
- describe "images" do
52
- describe "gif" do
53
- it "will respond sucessfully" do
54
- get '/assets/image.gif'
55
- last_response.status.must_equal 200
71
+
72
+ context "uses Rack::ClassyAssets middleware" do
73
+ describe "stylesheets" do
74
+ describe "css" do
75
+ it "will respond sucessfully" do
76
+ get '/assets/stylesheet.css'
77
+ last_response.status.must_equal 200
78
+ end
79
+ end
80
+
81
+ describe "sass" do
82
+ it "will respond sucessfully" do
83
+ get '/assets/application.css'
84
+ last_response.status.must_equal 200
85
+ end
56
86
  end
57
87
  end
58
88
 
59
- describe "jpg" do
60
- it "will respond sucessfully" do
61
- get '/assets/image.jpg'
62
- last_response.status.must_equal 200
89
+ describe "javascripts" do
90
+ describe "js" do
91
+ it "will respond sucessfully" do
92
+ get '/assets/javascript.js'
93
+ last_response.status.must_equal 200
94
+ end
95
+ end
96
+
97
+ describe "coffeescript" do
98
+ it "will respond sucessfully" do
99
+ get '/assets/application.js'
100
+ last_response.status.must_equal 200
101
+ end
63
102
  end
64
103
  end
65
104
 
66
- describe "png" do
67
- it "will respond sucessfully" do
68
- get '/assets/image.png'
69
- last_response.status.must_equal 200
105
+ describe "images" do
106
+ describe "gif" do
107
+ it "will respond sucessfully" do
108
+ get '/assets/image.gif'
109
+ last_response.status.must_equal 200
110
+ end
70
111
  end
71
- end
72
- end
73
112
 
74
- describe "fonts" do
75
- describe "eot" do
76
- it "will respond sucessfully" do
77
- get '/assets/font.eot'
78
- last_response.status.must_equal 200
113
+ describe "jpg" do
114
+ it "will respond sucessfully" do
115
+ get '/assets/image.jpg'
116
+ last_response.status.must_equal 200
117
+ end
118
+ end
119
+
120
+ describe "png" do
121
+ it "will respond sucessfully" do
122
+ get '/assets/image.png'
123
+ last_response.status.must_equal 200
124
+ end
79
125
  end
80
126
  end
81
127
 
82
- describe "otf" do
83
- it "will respond sucessfully" do
84
- get '/assets/font.otf'
85
- last_response.status.must_equal 200
128
+ describe "fonts" do
129
+ describe "eot" do
130
+ it "will respond sucessfully" do
131
+ get '/assets/font.eot'
132
+ last_response.status.must_equal 200
133
+ end
86
134
  end
87
- end
88
-
89
- describe "svg" do
90
- it "will respond sucessfully" do
91
- get '/assets/font.svg'
92
- last_response.status.must_equal 200
135
+
136
+ describe "otf" do
137
+ it "will respond sucessfully" do
138
+ get '/assets/font.otf'
139
+ last_response.status.must_equal 200
140
+ end
93
141
  end
94
- end
95
-
96
- describe "ttf" do
97
- it "will respond sucessfully" do
98
- get '/assets/font.ttf'
99
- last_response.status.must_equal 200
142
+
143
+ describe "svg" do
144
+ it "will respond sucessfully" do
145
+ get '/assets/font.svg'
146
+ last_response.status.must_equal 200
147
+ end
100
148
  end
101
- end
102
-
103
- describe "woff" do
104
- it "will respond sucessfully" do
105
- get '/assets/font.woff'
106
- last_response.status.must_equal 200
149
+
150
+ describe "ttf" do
151
+ it "will respond sucessfully" do
152
+ get '/assets/font.ttf'
153
+ last_response.status.must_equal 200
154
+ end
155
+ end
156
+
157
+ describe "woff" do
158
+ it "will respond sucessfully" do
159
+ get '/assets/font.woff'
160
+ last_response.status.must_equal 200
161
+ end
107
162
  end
108
163
  end
109
- end
164
+ end
110
165
  end
data/spec/spec_helper.rb CHANGED
@@ -3,10 +3,13 @@
3
3
  ENV['RACK_ENV'] = 'test'
4
4
  lib_path = File.expand_path('../lib', __FILE__)
5
5
  ($:.unshift lib_path) unless ($:.include? lib_path)
6
+ require 'bundler'
6
7
  Bundler.setup(:default, ENV['RACK_ENV'])
7
8
  require 'rack/test'
9
+ require 'slim'
8
10
  require 'classy_assets'
9
11
  require 'minitest/autorun'
12
+ require "minitest-spec-context"
10
13
  require 'minitest/reporters'
11
14
  MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
12
15
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ //= require stylesheet
2
+
3
+ .bg { background-url: asset_path('image.png'); }
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.3.2
4
+ version: 0.4.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-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coffee-script
@@ -165,49 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: pry
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - '>='
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - '>='
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: minitest
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - '>='
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - '>='
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: minitest-reporters
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - '>='
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - '>='
207
- - !ruby/object:Gem::Version
208
- version: '0'
209
- - !ruby/object:Gem::Dependency
210
- name: rack-test
168
+ name: gem-release
211
169
  requirement: !ruby/object:Gem::Requirement
212
170
  requirements:
213
171
  - - '>='
@@ -234,32 +192,34 @@ files:
234
192
  - LICENSE.txt
235
193
  - README.md
236
194
  - Rakefile
237
- - assets/fonts/font.eot
238
- - assets/fonts/font.otf
239
- - assets/fonts/font.svg
240
- - assets/fonts/font.ttf
241
- - assets/fonts/font.woff
242
- - assets/images/image.gif
243
- - assets/images/image.jpg
244
- - assets/images/image.png
245
- - assets/javascripts/application.coffee
246
- - assets/javascripts/javascript.js
247
- - assets/stylesheets/application.scss
248
- - assets/stylesheets/stylesheet.css
249
195
  - bin/.files/pre-commit.hook
250
196
  - bin/classy_assets
251
197
  - classy_assets.gemspec
252
198
  - lib/classy_assets.rb
253
199
  - lib/classy_assets/cli.rb
200
+ - lib/classy_assets/configuration.rb
254
201
  - lib/classy_assets/tasks.rb
255
202
  - lib/classy_assets/tasks/assets.rake
256
203
  - lib/classy_assets/version.rb
257
204
  - lib/rack/classy_assets.rb
258
205
  - lib/sinatra/classy_assets.rb
206
+ - spec/classy_assets/configuration_spec.rb
259
207
  - spec/classy_assets_spec.rb
260
208
  - spec/rack/classy_assets_spec.rb
261
209
  - spec/sinatra/classy_assets_spec.rb
262
210
  - spec/spec_helper.rb
211
+ - spec/support/assets/fonts/font.eot
212
+ - spec/support/assets/fonts/font.otf
213
+ - spec/support/assets/fonts/font.svg
214
+ - spec/support/assets/fonts/font.ttf
215
+ - spec/support/assets/fonts/font.woff
216
+ - spec/support/assets/images/image.gif
217
+ - spec/support/assets/images/image.jpg
218
+ - spec/support/assets/images/image.png
219
+ - spec/support/assets/javascripts/application.coffee
220
+ - spec/support/assets/javascripts/javascript.js
221
+ - spec/support/assets/stylesheets/application.scss
222
+ - spec/support/assets/stylesheets/stylesheet.css
263
223
  homepage: https://github.com/styleseek/classy_assets
264
224
  licenses:
265
225
  - MIT
@@ -285,7 +245,20 @@ signing_key:
285
245
  specification_version: 4
286
246
  summary: Classy Assets (powered by Sprockets) for Sinatra and Rack apps
287
247
  test_files:
248
+ - spec/classy_assets/configuration_spec.rb
288
249
  - spec/classy_assets_spec.rb
289
250
  - spec/rack/classy_assets_spec.rb
290
251
  - spec/sinatra/classy_assets_spec.rb
291
252
  - spec/spec_helper.rb
253
+ - spec/support/assets/fonts/font.eot
254
+ - spec/support/assets/fonts/font.otf
255
+ - spec/support/assets/fonts/font.svg
256
+ - spec/support/assets/fonts/font.ttf
257
+ - spec/support/assets/fonts/font.woff
258
+ - spec/support/assets/images/image.gif
259
+ - spec/support/assets/images/image.jpg
260
+ - spec/support/assets/images/image.png
261
+ - spec/support/assets/javascripts/application.coffee
262
+ - spec/support/assets/javascripts/javascript.js
263
+ - spec/support/assets/stylesheets/application.scss
264
+ - spec/support/assets/stylesheets/stylesheet.css
@@ -1 +0,0 @@
1
- //= require stylesheet