Imported Upstream version 2.0.1
Christian Hofstaedtler
10 years ago
0 | rvm: | |
1 | - 1.9.3 | |
2 | - 2.0.0 | |
3 | ||
4 | gemfile: | |
5 | - test/gemfiles/Gemfile.rails-3.0.x | |
6 | - test/gemfiles/Gemfile.rails-3.1.x | |
7 | - test/gemfiles/Gemfile.rails-3.2.x | |
8 | - test/gemfiles/Gemfile.rails-4.0.x | |
9 | ||
10 | notifications: | |
11 | email: false |
0 | ### 2.0.1 | |
1 | ||
2 | * Allow keep value to be specified for `assets:clean` run with args | |
3 | for example `assets:clean[0]` will keep no old asset copies | |
4 | ||
5 | *Richard Schneeman* | |
6 | ||
7 | * Fix `javascript_include_tag`/`stylesheet_include_tag` helpers when `debug: => false` is used. | |
8 | ||
9 | *Guillermo Iguaran* | |
10 | ||
11 | * Fix issue when precompiling html.erb files. | |
12 | ||
13 | Fixes #45. | |
14 | ||
15 | *Zach Ohlgren* |
0 | source 'https://rubygems.org' | |
1 | gemspec | |
2 | ||
3 | # Roll w/ branch until 4.0 is cut | |
4 | gem 'actionpack', :github => 'rails/rails', branch: '4-0-stable' | |
5 | gem 'railties', :github => 'rails/rails', branch: '4-0-stable' |
0 | Copyright (c) 2012 Joshua Peek | |
1 | ||
2 | Permission is hereby granted, free of charge, to any person obtaining | |
3 | a copy of this software and associated documentation files (the | |
4 | "Software"), to deal in the Software without restriction, including | |
5 | without limitation the rights to use, copy, modify, merge, publish, | |
6 | distribute, sublicense, and/or sell copies of the Software, and to | |
7 | permit persons to whom the Software is furnished to do so, subject to | |
8 | the following conditions: | |
9 | ||
10 | The above copyright notice and this permission notice shall be | |
11 | included in all copies or substantial portions of the Software. | |
12 | ||
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
14 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
15 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
16 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
17 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
19 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
45 | 45 | |
46 | 46 | Each asset task will invoke `assets:environment` first. By default this loads the Rails environment. You can override this task to add or remove dependencies for your specific compilation environment. |
47 | 47 | |
48 | Also see [Sprockest::Rails::Task](https://github.com/josh/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb). | |
48 | Also see [Sprockets::Rails::Task](https://github.com/josh/sprockets-rails/blob/master/lib/sprockets/rails/task.rb) and [Rake::SprocketsTask](https://github.com/sstephenson/sprockets/blob/master/lib/rake/sprocketstask.rb). | |
49 | 49 | |
50 | 50 | |
51 | 51 | ### Initializer options |
82 | 82 | |
83 | 83 | **`config.assets.compile`** |
84 | 84 | |
85 | Enables Sprockest compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`. | |
85 | Enables Sprockets compile environment. If disabled, `Rails.application.assets` will be unavailable to any ActionView helpers. View helpers will depend on assets being precompiled to `public/assets` in order to link to them. You can still access the environment by directly calling `Rails.application.assets`. | |
86 | 86 | |
87 | 87 | **`config.assets.configure`** |
88 | 88 |
0 | require 'rake/testtask' | |
1 | ||
2 | require 'bundler/gem_tasks' | |
3 | ||
4 | task :default => :test | |
5 | ||
6 | task :test do | |
7 | exec "testrb test/test_*.rb" | |
8 | end |
6 | 6 | module Helper |
7 | 7 | if defined? ActionView::Helpers::AssetUrlHelper |
8 | 8 | include ActionView::Helpers::AssetUrlHelper |
9 | include ActionView::Helpers::AssetTagHelper | |
9 | 10 | else |
10 | 11 | require 'sprockets/rails/legacy_asset_tag_helper' |
11 | 12 | require 'sprockets/rails/legacy_asset_url_helper' |
21 | 22 | klass.class_eval do |
22 | 23 | alias_method :assets_environment, :environment |
23 | 24 | def assets_manifest; end |
24 | class_attribute :config, :assets_prefix, :digest_assets | |
25 | class_attribute :config, :assets_prefix, :digest_assets, :debug_assets | |
25 | 26 | end |
26 | 27 | else |
27 | 28 | klass.class_attribute(*VIEW_ACCESSORS) |
84 | 85 | def javascript_include_tag(*sources) |
85 | 86 | options = sources.extract_options!.stringify_keys |
86 | 87 | |
87 | if request_debug_assets? | |
88 | if options["debug"] != false && request_debug_assets? | |
88 | 89 | sources.map { |source| |
89 | 90 | if asset = lookup_asset_for_path(source, :type => :javascript) |
90 | 91 | asset.to_a.map do |a| |
106 | 107 | def stylesheet_link_tag(*sources) |
107 | 108 | options = sources.extract_options!.stringify_keys |
108 | 109 | |
109 | if request_debug_assets? | |
110 | if options["debug"] != false && request_debug_assets? | |
110 | 111 | sources.map { |source| |
111 | 112 | if asset = lookup_asset_for_path(source, :type => :stylesheet) |
112 | 113 | asset.to_a.map do |a| |
127 | 128 | # and replaced by source maps in Sprockets 3.x. |
128 | 129 | def request_debug_assets? |
129 | 130 | debug_assets || (defined?(controller) && controller && params[:debug_assets]) |
131 | rescue | |
132 | return false | |
130 | 133 | end |
131 | 134 | |
132 | 135 | # Internal method to support multifile debugging. Will |
61 | 61 | end |
62 | 62 | |
63 | 63 | desc "Remove old compiled assets" |
64 | task :clean => :environment do | |
64 | task :clean, [:keep] => :environment do |t, args| | |
65 | keep = Integer(args.keep || 2) | |
65 | 66 | with_logger do |
66 | 67 | manifest.clean(keep) |
67 | 68 | end |
35 | 35 | |
36 | 36 | module Sprockets |
37 | 37 | class Railtie < ::Rails::Railtie |
38 | LOOSE_APP_ASSETS = lambda do |path, filename| | |
39 | filename =~ /app\/assets/ && !%w(.js .css).include?(File.extname(path)) | |
38 | LOOSE_APP_ASSETS = lambda do |filename, path| | |
39 | path =~ /app\/assets/ && !%w(.js .css).include?(File.extname(filename)) | |
40 | 40 | end |
41 | 41 | |
42 | 42 | class OrderedOptions < ActiveSupport::OrderedOptions |
0 | --- !ruby/object:Gem::Specification | |
1 | name: sprockets-rails | |
2 | version: !ruby/object:Gem::Version | |
3 | version: 2.0.0 | |
4 | platform: ruby | |
5 | authors: | |
6 | - Joshua Peek | |
7 | autorequire: | |
8 | bindir: bin | |
9 | cert_chain: [] | |
10 | date: 2013-06-11 00:00:00.000000000 Z | |
11 | dependencies: | |
12 | - !ruby/object:Gem::Dependency | |
13 | name: sprockets | |
14 | requirement: !ruby/object:Gem::Requirement | |
15 | requirements: | |
16 | - - ~> | |
17 | - !ruby/object:Gem::Version | |
18 | version: '2.8' | |
19 | type: :runtime | |
20 | prerelease: false | |
21 | version_requirements: !ruby/object:Gem::Requirement | |
22 | requirements: | |
23 | - - ~> | |
24 | - !ruby/object:Gem::Version | |
25 | version: '2.8' | |
26 | - !ruby/object:Gem::Dependency | |
27 | name: actionpack | |
28 | requirement: !ruby/object:Gem::Requirement | |
29 | requirements: | |
30 | - - '>=' | |
31 | - !ruby/object:Gem::Version | |
32 | version: '3.0' | |
33 | type: :runtime | |
34 | prerelease: false | |
35 | version_requirements: !ruby/object:Gem::Requirement | |
36 | requirements: | |
37 | - - '>=' | |
38 | - !ruby/object:Gem::Version | |
39 | version: '3.0' | |
40 | - !ruby/object:Gem::Dependency | |
41 | name: activesupport | |
42 | requirement: !ruby/object:Gem::Requirement | |
43 | requirements: | |
44 | - - '>=' | |
45 | - !ruby/object:Gem::Version | |
46 | version: '3.0' | |
47 | type: :runtime | |
48 | prerelease: false | |
49 | version_requirements: !ruby/object:Gem::Requirement | |
50 | requirements: | |
51 | - - '>=' | |
52 | - !ruby/object:Gem::Version | |
53 | version: '3.0' | |
54 | - !ruby/object:Gem::Dependency | |
55 | name: rake | |
56 | requirement: !ruby/object:Gem::Requirement | |
57 | requirements: | |
58 | - - '>=' | |
59 | - !ruby/object:Gem::Version | |
60 | version: '0' | |
61 | type: :development | |
62 | prerelease: false | |
63 | version_requirements: !ruby/object:Gem::Requirement | |
64 | requirements: | |
65 | - - '>=' | |
66 | - !ruby/object:Gem::Version | |
67 | version: '0' | |
68 | description: | |
69 | email: josh@joshpeek.com | |
70 | executables: [] | |
71 | extensions: [] | |
72 | extra_rdoc_files: [] | |
73 | files: | |
74 | - README.md | |
75 | - lib/sprockets/rails/helper.rb | |
76 | - lib/sprockets/rails/legacy_asset_tag_helper.rb | |
77 | - lib/sprockets/rails/legacy_asset_url_helper.rb | |
78 | - lib/sprockets/rails/task.rb | |
79 | - lib/sprockets/rails.rb | |
80 | - lib/sprockets/railtie.rb | |
81 | homepage: https://github.com/rails/sprockets-rails | |
82 | licenses: [] | |
83 | metadata: {} | |
84 | post_install_message: | |
85 | rdoc_options: [] | |
86 | require_paths: | |
87 | - lib | |
88 | required_ruby_version: !ruby/object:Gem::Requirement | |
89 | requirements: | |
90 | - - '>=' | |
91 | - !ruby/object:Gem::Version | |
92 | version: '0' | |
93 | required_rubygems_version: !ruby/object:Gem::Requirement | |
94 | requirements: | |
95 | - - '>=' | |
96 | - !ruby/object:Gem::Version | |
97 | version: '0' | |
98 | requirements: [] | |
99 | rubyforge_project: | |
100 | rubygems_version: 2.0.2 | |
101 | signing_key: | |
102 | specification_version: 4 | |
103 | summary: Sprockets Rails integration | |
104 | test_files: [] |
0 | Gem::Specification.new do |s| | |
1 | s.name = "sprockets-rails" | |
2 | s.version = "2.0.1" | |
3 | ||
4 | s.homepage = "https://github.com/rails/sprockets-rails" | |
5 | s.summary = "Sprockets Rails integration" | |
6 | s.license = "MIT" | |
7 | ||
8 | s.files = Dir["README.md", "lib/**/*.rb", "LICENSE"] | |
9 | ||
10 | s.add_dependency "sprockets", "~> 2.8" | |
11 | s.add_dependency "actionpack", ">= 3.0" | |
12 | s.add_dependency "activesupport", ">= 3.0" | |
13 | s.add_development_dependency "rake" | |
14 | ||
15 | s.author = "Joshua Peek" | |
16 | s.email = "josh@joshpeek.com" | |
17 | end |
0 | /*= require foo */ |
0 | //= require foo |
0 | /* dependency */ |
0 | // dependency |
0 | //= require dependency |
0 | //= require dependency |
0 | .foo {} |
0 | var Foo;⏎ |
0 | p { background: url(<%= image_path "logo.png" %>); } |
0 | var url = '<%= javascript_path :foo %>'; |
0 | source 'https://rubygems.org' | |
1 | gemspec :path => "./../.." | |
2 | ||
3 | gem "actionpack", "~> 3.0.0" | |
4 | gem "railties", "~> 3.0.0" |
0 | source 'https://rubygems.org' | |
1 | gemspec :path => "./../.." | |
2 | ||
3 | # Patch 3-1-stable to allow new sprockets | |
4 | gem "actionpack", "~> 3.1.0", :github => "josh/rails", :branch => "3-1-stable-sprockets" | |
5 | gem "railties", "~> 3.1.0", :github => "josh/rails", :branch => "3-1-stable-sprockets" | |
6 | gem "tzinfo" |
0 | source 'https://rubygems.org' | |
1 | gemspec :path => "./../.." | |
2 | ||
3 | # Patch 3-2-stable to allow new sprockets | |
4 | gem "actionpack", "~> 3.2.0", :github => "josh/rails", :branch => "3-2-stable-sprockets" | |
5 | gem "railties", "~> 3.2.0", :github => "josh/rails", :branch => "3-2-stable-sprockets" | |
6 | gem "tzinfo" |
0 | source 'https://rubygems.org' | |
1 | gemspec :path => "./../.." | |
2 | ||
3 | gem "actionpack", "~> 4.0.0" | |
4 | gem "railties", "~> 4.0.0" |
0 | require 'test/unit' | |
1 | ||
2 | require 'action_view' | |
3 | require 'sprockets' | |
4 | require 'sprockets/rails/helper' | |
5 | ||
6 | class HelperTest < Test::Unit::TestCase | |
7 | FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) | |
8 | ||
9 | # class ActionView::Base | |
10 | # include ::Sprockets::Rails::Helper | |
11 | # end | |
12 | ||
13 | def setup | |
14 | assets = @assets = Sprockets::Environment.new | |
15 | @assets.append_path FIXTURES_PATH | |
16 | @assets.context_class.class_eval do | |
17 | include ::Sprockets::Rails::Helper | |
18 | end | |
19 | ||
20 | @view = ActionView::Base.new | |
21 | @view.extend ::Sprockets::Rails::Helper | |
22 | @view.assets_environment = @assets | |
23 | @view.assets_prefix = "/assets" | |
24 | ||
25 | # Rails 2.x | |
26 | unless @view.respond_to?(:config) | |
27 | @view.class_eval { attr_accessor :config } | |
28 | @view.config = Struct.new(:asset_host).new | |
29 | end | |
30 | ||
31 | @assets.context_class.assets_prefix = @view.assets_prefix | |
32 | @assets.context_class.config = @view.config | |
33 | ||
34 | @foo_js_digest = @assets['foo.js'].digest | |
35 | @foo_css_digest = @assets['foo.css'].digest | |
36 | end | |
37 | ||
38 | def test_truth | |
39 | end | |
40 | end | |
41 | ||
42 | class NoHostHelperTest < HelperTest | |
43 | def test_javascript_include_tag | |
44 | assert_equal %(<script src="/javascripts/static.js"></script>), | |
45 | @view.javascript_include_tag("static") | |
46 | assert_equal %(<script src="/javascripts/static.js"></script>), | |
47 | @view.javascript_include_tag("static.js") | |
48 | assert_equal %(<script src="/javascripts/static.js"></script>), | |
49 | @view.javascript_include_tag(:static) | |
50 | ||
51 | assert_equal %(<script src="/elsewhere.js"></script>), | |
52 | @view.javascript_include_tag("/elsewhere.js") | |
53 | assert_equal %(<script src="/script1.js"></script>\n<script src="/javascripts/script2.js"></script>), | |
54 | @view.javascript_include_tag("/script1.js", "script2.js") | |
55 | ||
56 | assert_equal %(<script src="http://example.com/script"></script>), | |
57 | @view.javascript_include_tag("http://example.com/script") | |
58 | assert_equal %(<script src="http://example.com/script.js"></script>), | |
59 | @view.javascript_include_tag("http://example.com/script.js") | |
60 | assert_equal %(<script src="//example.com/script.js"></script>), | |
61 | @view.javascript_include_tag("//example.com/script.js") | |
62 | ||
63 | assert_equal %(<script defer="defer" src="/javascripts/static.js"></script>), | |
64 | @view.javascript_include_tag("static", :defer => "defer") | |
65 | assert_equal %(<script async="async" src="/javascripts/static.js"></script>), | |
66 | @view.javascript_include_tag("static", :async => "async") | |
67 | end | |
68 | ||
69 | def test_stylesheet_link_tag | |
70 | assert_equal %(<link href="/stylesheets/static.css" media="screen" rel="stylesheet" />), | |
71 | @view.stylesheet_link_tag("static") | |
72 | assert_equal %(<link href="/stylesheets/static.css" media="screen" rel="stylesheet" />), | |
73 | @view.stylesheet_link_tag("static.css") | |
74 | assert_equal %(<link href="/stylesheets/static.css" media="screen" rel="stylesheet" />), | |
75 | @view.stylesheet_link_tag(:static) | |
76 | ||
77 | assert_equal %(<link href="/elsewhere.css" media="screen" rel="stylesheet" />), | |
78 | @view.stylesheet_link_tag("/elsewhere.css") | |
79 | assert_equal %(<link href="/style1.css" media="screen" rel="stylesheet" />\n<link href="/stylesheets/style2.css" media="screen" rel="stylesheet" />), | |
80 | @view.stylesheet_link_tag("/style1.css", "style2.css") | |
81 | ||
82 | assert_equal %(<link href="http://www.example.com/styles/style" media="screen" rel="stylesheet" />), | |
83 | @view.stylesheet_link_tag("http://www.example.com/styles/style") | |
84 | assert_equal %(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" />), | |
85 | @view.stylesheet_link_tag("http://www.example.com/styles/style.css") | |
86 | assert_equal %(<link href="//www.example.com/styles/style.css" media="screen" rel="stylesheet" />), | |
87 | @view.stylesheet_link_tag("//www.example.com/styles/style.css") | |
88 | ||
89 | assert_equal %(<link href="/stylesheets/print.css" media="print" rel="stylesheet" />), | |
90 | @view.stylesheet_link_tag("print", :media => "print") | |
91 | assert_equal %(<link href="/stylesheets/print.css" media="<hax>" rel="stylesheet" />), | |
92 | @view.stylesheet_link_tag("print", :media => "<hax>") | |
93 | end | |
94 | ||
95 | def test_javascript_path | |
96 | assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr") | |
97 | assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js") | |
98 | assert_equal "/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr") | |
99 | assert_equal "/super/xmlhr.js", @view.javascript_path("/super/xmlhr") | |
100 | ||
101 | assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1") | |
102 | assert_equal "/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1") | |
103 | assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash") | |
104 | assert_equal "/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash") | |
105 | assert_equal "/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash") | |
106 | end | |
107 | ||
108 | def test_stylesheet_path | |
109 | assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank") | |
110 | assert_equal "/stylesheets/bank.css", @view.stylesheet_path("bank.css") | |
111 | assert_equal "/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir") | |
112 | assert_equal "/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css") | |
113 | ||
114 | assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1") | |
115 | assert_equal "/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1") | |
116 | assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash") | |
117 | assert_equal "/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash") | |
118 | assert_equal "/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash") | |
119 | end | |
120 | end | |
121 | ||
122 | class RelativeHostHelperTest < HelperTest | |
123 | def setup | |
124 | super | |
125 | ||
126 | @view.config.asset_host = "assets.example.com" | |
127 | end | |
128 | ||
129 | def test_javascript_path | |
130 | assert_equal "//assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr") | |
131 | assert_equal "//assets.example.com/javascripts/xmlhr.js", @view.javascript_path("xmlhr.js") | |
132 | assert_equal "//assets.example.com/javascripts/super/xmlhr.js", @view.javascript_path("super/xmlhr") | |
133 | assert_equal "//assets.example.com/super/xmlhr.js", @view.javascript_path("/super/xmlhr") | |
134 | ||
135 | assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr.js?foo=1") | |
136 | assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1", @view.javascript_path("xmlhr?foo=1") | |
137 | assert_equal "//assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr.js#hash") | |
138 | assert_equal "//assets.example.com/javascripts/xmlhr.js#hash", @view.javascript_path("xmlhr#hash") | |
139 | assert_equal "//assets.example.com/javascripts/xmlhr.js?foo=1#hash", @view.javascript_path("xmlhr.js?foo=1#hash") | |
140 | ||
141 | assert_equal %(<script src="//assets.example.com/assets/foo.js"></script>), | |
142 | @view.javascript_include_tag("foo") | |
143 | assert_equal %(<script src="//assets.example.com/assets/foo.js"></script>), | |
144 | @view.javascript_include_tag("foo.js") | |
145 | assert_equal %(<script src="//assets.example.com/assets/foo.js"></script>), | |
146 | @view.javascript_include_tag(:foo) | |
147 | end | |
148 | ||
149 | def test_stylesheet_path | |
150 | assert_equal "//assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank") | |
151 | assert_equal "//assets.example.com/stylesheets/bank.css", @view.stylesheet_path("bank.css") | |
152 | assert_equal "//assets.example.com/stylesheets/subdir/subdir.css", @view.stylesheet_path("subdir/subdir") | |
153 | assert_equal "//assets.example.com/subdir/subdir.css", @view.stylesheet_path("/subdir/subdir.css") | |
154 | ||
155 | assert_equal "//assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank.css?foo=1") | |
156 | assert_equal "//assets.example.com/stylesheets/bank.css?foo=1", @view.stylesheet_path("bank?foo=1") | |
157 | assert_equal "//assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank.css#hash") | |
158 | assert_equal "//assets.example.com/stylesheets/bank.css#hash", @view.stylesheet_path("bank#hash") | |
159 | assert_equal "//assets.example.com/stylesheets/bank.css?foo=1#hash", @view.stylesheet_path("bank.css?foo=1#hash") | |
160 | ||
161 | assert_equal %(<link href="//assets.example.com/assets/foo.css" media="screen" rel="stylesheet" />), | |
162 | @view.stylesheet_link_tag("foo") | |
163 | assert_equal %(<link href="//assets.example.com/assets/foo.css" media="screen" rel="stylesheet" />), | |
164 | @view.stylesheet_link_tag("foo.css") | |
165 | assert_equal %(<link href="//assets.example.com/assets/foo.css" media="screen" rel="stylesheet" />), | |
166 | @view.stylesheet_link_tag(:foo) | |
167 | end | |
168 | ||
169 | def test_asset_url | |
170 | assert_equal "var url = '//assets.example.com/assets/foo.js';\n", @assets["url.js"].to_s | |
171 | assert_equal "p { background: url(//assets.example.com/images/logo.png); }\n", @assets["url.css"].to_s | |
172 | end | |
173 | end | |
174 | ||
175 | ||
176 | class NoDigestHelperTest < NoHostHelperTest | |
177 | def setup | |
178 | super | |
179 | @view.digest_assets = false | |
180 | @assets.context_class.digest_assets = false | |
181 | end | |
182 | ||
183 | def test_javascript_include_tag | |
184 | super | |
185 | ||
186 | assert_equal %(<script src="/assets/foo.js"></script>), | |
187 | @view.javascript_include_tag("foo") | |
188 | assert_equal %(<script src="/assets/foo.js"></script>), | |
189 | @view.javascript_include_tag("foo.js") | |
190 | assert_equal %(<script src="/assets/foo.js"></script>), | |
191 | @view.javascript_include_tag(:foo) | |
192 | end | |
193 | ||
194 | def test_stylesheet_link_tag | |
195 | super | |
196 | ||
197 | assert_equal %(<link href="/assets/foo.css" media="screen" rel="stylesheet" />), | |
198 | @view.stylesheet_link_tag("foo") | |
199 | assert_equal %(<link href="/assets/foo.css" media="screen" rel="stylesheet" />), | |
200 | @view.stylesheet_link_tag("foo.css") | |
201 | assert_equal %(<link href="/assets/foo.css" media="screen" rel="stylesheet" />), | |
202 | @view.stylesheet_link_tag(:foo) | |
203 | end | |
204 | ||
205 | def test_javascript_path | |
206 | super | |
207 | ||
208 | assert_equal "/assets/foo.js", @view.javascript_path("foo") | |
209 | end | |
210 | ||
211 | def test_stylesheet_path | |
212 | super | |
213 | ||
214 | assert_equal "/assets/foo.css", @view.stylesheet_path("foo") | |
215 | end | |
216 | ||
217 | def test_asset_digest | |
218 | assert_equal nil, @view.asset_digest("foo.js") | |
219 | assert_equal nil, @view.asset_digest("foo.css") | |
220 | end | |
221 | ||
222 | def test_asset_url | |
223 | assert_equal "var url = '/assets/foo.js';\n", @assets["url.js"].to_s | |
224 | assert_equal "p { background: url(/images/logo.png); }\n", @assets["url.css"].to_s | |
225 | end | |
226 | end | |
227 | ||
228 | class DigestHelperTest < NoHostHelperTest | |
229 | def setup | |
230 | super | |
231 | @view.digest_assets = true | |
232 | @assets.context_class.digest_assets = true | |
233 | end | |
234 | ||
235 | def test_javascript_include_tag | |
236 | super | |
237 | ||
238 | assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>), | |
239 | @view.javascript_include_tag("foo") | |
240 | assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>), | |
241 | @view.javascript_include_tag("foo.js") | |
242 | assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>), | |
243 | @view.javascript_include_tag(:foo) | |
244 | end | |
245 | ||
246 | def test_stylesheet_link_tag | |
247 | super | |
248 | ||
249 | assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />), | |
250 | @view.stylesheet_link_tag("foo") | |
251 | assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />), | |
252 | @view.stylesheet_link_tag("foo.css") | |
253 | assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />), | |
254 | @view.stylesheet_link_tag(:foo) | |
255 | end | |
256 | ||
257 | def test_javascript_path | |
258 | super | |
259 | ||
260 | assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo") | |
261 | end | |
262 | ||
263 | def test_stylesheet_path | |
264 | super | |
265 | ||
266 | assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo") | |
267 | end | |
268 | ||
269 | def test_asset_digest | |
270 | assert_equal @foo_js_digest, @view.asset_digest("foo.js") | |
271 | assert_equal @foo_css_digest, @view.asset_digest("foo.css") | |
272 | end | |
273 | ||
274 | def test_asset_digest_path | |
275 | assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js") | |
276 | assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css") | |
277 | end | |
278 | ||
279 | def test_asset_url | |
280 | assert_equal "var url = '/assets/foo-#{@foo_js_digest}.js';\n", @assets["url.js"].to_s | |
281 | assert_equal "p { background: url(/images/logo.png); }\n", @assets["url.css"].to_s | |
282 | end | |
283 | end | |
284 | ||
285 | class DebugHelperTest < NoHostHelperTest | |
286 | def setup | |
287 | super | |
288 | @view.debug_assets = true | |
289 | end | |
290 | ||
291 | def test_javascript_include_tag | |
292 | super | |
293 | ||
294 | assert_equal %(<script src="/assets/foo.js?body=1"></script>), | |
295 | @view.javascript_include_tag(:foo) | |
296 | assert_equal %(<script src="/assets/foo.js?body=1"></script>\n<script src="/assets/bar.js?body=1"></script>), | |
297 | @view.javascript_include_tag(:bar) | |
298 | assert_equal %(<script src="/assets/dependency.js?body=1"></script>\n<script src="/assets/file1.js?body=1"></script>\n<script src="/assets/file2.js?body=1"></script>), | |
299 | @view.javascript_include_tag(:file1, :file2) | |
300 | end | |
301 | ||
302 | def test_stylesheet_link_tag | |
303 | super | |
304 | ||
305 | assert_equal %(<link href="/assets/foo.css?body=1" media="screen" rel="stylesheet" />), | |
306 | @view.stylesheet_link_tag(:foo) | |
307 | assert_equal %(<link href="/assets/foo.css?body=1" media="screen" rel="stylesheet" />\n<link href="/assets/bar.css?body=1" media="screen" rel="stylesheet" />), | |
308 | @view.stylesheet_link_tag(:bar) | |
309 | assert_equal %(<link href="/assets/dependency.css?body=1" media="screen" rel="stylesheet" />\n<link href="/assets/file1.css?body=1" media="screen" rel="stylesheet" />\n<link href="/assets/file2.css?body=1" media="screen" rel="stylesheet" />), | |
310 | @view.stylesheet_link_tag(:file1, :file2) | |
311 | end | |
312 | ||
313 | def test_javascript_path | |
314 | super | |
315 | ||
316 | assert_equal "/assets/foo.js", @view.javascript_path("foo") | |
317 | end | |
318 | ||
319 | def test_stylesheet_path | |
320 | super | |
321 | ||
322 | assert_equal "/assets/foo.css", @view.stylesheet_path("foo") | |
323 | end | |
324 | end | |
325 | ||
326 | class ManifestHelperTest < NoHostHelperTest | |
327 | def setup | |
328 | super | |
329 | ||
330 | @manifest = Sprockets::Manifest.new(@assets, FIXTURES_PATH) | |
331 | @manifest.assets["foo.js"] = "foo-#{@foo_js_digest}.js" | |
332 | @manifest.assets["foo.css"] = "foo-#{@foo_css_digest}.css" | |
333 | ||
334 | @view.digest_assets = true | |
335 | @view.assets_environment = nil | |
336 | @view.assets_manifest = @manifest | |
337 | end | |
338 | ||
339 | def test_javascript_include_tag | |
340 | super | |
341 | ||
342 | assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>), | |
343 | @view.javascript_include_tag("foo") | |
344 | assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>), | |
345 | @view.javascript_include_tag("foo.js") | |
346 | assert_equal %(<script src="/assets/foo-#{@foo_js_digest}.js"></script>), | |
347 | @view.javascript_include_tag(:foo) | |
348 | end | |
349 | ||
350 | def test_stylesheet_link_tag | |
351 | super | |
352 | ||
353 | assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />), | |
354 | @view.stylesheet_link_tag("foo") | |
355 | assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />), | |
356 | @view.stylesheet_link_tag("foo.css") | |
357 | assert_equal %(<link href="/assets/foo-#{@foo_css_digest}.css" media="screen" rel="stylesheet" />), | |
358 | @view.stylesheet_link_tag(:foo) | |
359 | end | |
360 | ||
361 | def test_javascript_path | |
362 | super | |
363 | ||
364 | assert_equal "/assets/foo-#{@foo_js_digest}.js", @view.javascript_path("foo") | |
365 | end | |
366 | ||
367 | def test_stylesheet_path | |
368 | super | |
369 | ||
370 | assert_equal "/assets/foo-#{@foo_css_digest}.css", @view.stylesheet_path("foo") | |
371 | end | |
372 | ||
373 | def test_asset_digest_path | |
374 | assert_equal "foo-#{@foo_js_digest}.js", @view.asset_digest_path("foo.js") | |
375 | assert_equal "foo-#{@foo_css_digest}.css", @view.asset_digest_path("foo.css") | |
376 | end | |
377 | ||
378 | def test_asset_digest | |
379 | assert_equal @foo_js_digest, @view.asset_digest("foo.js") | |
380 | assert_equal @foo_css_digest, @view.asset_digest("foo.css") | |
381 | end | |
382 | end |
0 | require 'test/unit' | |
1 | require 'active_support' | |
2 | require 'active_support/testing/isolation' | |
3 | ||
4 | class TestBoot < Test::Unit::TestCase | |
5 | include ActiveSupport::Testing::Isolation | |
6 | ||
7 | ROOT = File.expand_path("../../tmp/app", __FILE__) | |
8 | FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) | |
9 | ||
10 | attr_reader :app | |
11 | ||
12 | def setup | |
13 | require 'rails' | |
14 | # Can't seem to get initialize to run w/o this | |
15 | require 'action_controller/railtie' | |
16 | require 'active_support/dependencies' | |
17 | require 'tzinfo' | |
18 | ||
19 | ENV['RAILS_ENV'] = 'test' | |
20 | ||
21 | FileUtils.mkdir_p ROOT | |
22 | Dir.chdir ROOT | |
23 | ||
24 | @app = Class.new(Rails::Application) | |
25 | # Get bitched at if you don't set these | |
26 | @app.config.eager_load = false | |
27 | @app.config.time_zone = 'UTC' | |
28 | @app.config.middleware ||= Rails::Configuration::MiddlewareStackProxy.new | |
29 | @app.config.active_support.deprecation = :notify | |
30 | end | |
31 | ||
32 | def test_initialize | |
33 | app.initialize! | |
34 | end | |
35 | end | |
36 | ||
37 | class TestRailtie < TestBoot | |
38 | def setup | |
39 | require 'sprockets/railtie' | |
40 | super | |
41 | end | |
42 | ||
43 | def test_defaults | |
44 | app.initialize! | |
45 | ||
46 | assert env = app.assets | |
47 | assert_kind_of Sprockets::Environment, env | |
48 | ||
49 | assert_equal ROOT, env.root | |
50 | assert_equal "test", env.version | |
51 | assert env.cache | |
52 | assert_equal [], env.paths | |
53 | assert_nil env.js_compressor | |
54 | assert_nil env.css_compressor | |
55 | end | |
56 | ||
57 | def test_app_asset_available_when_compile | |
58 | assert_equal true, app.config.assets.compile | |
59 | ||
60 | app.initialize! | |
61 | ||
62 | assert env = app.assets | |
63 | end | |
64 | ||
65 | def test_app_asset_available_when_no_compile | |
66 | app.configure do | |
67 | config.assets.compile = false | |
68 | end | |
69 | ||
70 | assert_equal false, app.config.assets.compile | |
71 | ||
72 | app.initialize! | |
73 | ||
74 | assert env = app.assets | |
75 | end | |
76 | ||
77 | def test_copies_paths | |
78 | app.configure do | |
79 | config.assets.paths << "javascripts" | |
80 | config.assets.paths << "stylesheets" | |
81 | end | |
82 | app.initialize! | |
83 | ||
84 | assert env = app.assets | |
85 | assert_equal ["#{ROOT}/javascripts", "#{ROOT}/stylesheets"], | |
86 | env.paths.sort | |
87 | end | |
88 | ||
89 | def test_compressors | |
90 | app.configure do | |
91 | config.assets.js_compressor = :uglifier | |
92 | config.assets.css_compressor = :sass | |
93 | end | |
94 | app.initialize! | |
95 | ||
96 | assert env = app.assets | |
97 | assert_equal Sprockets::UglifierCompressor, env.js_compressor | |
98 | assert_equal Sprockets::SassCompressor, env.css_compressor | |
99 | end | |
100 | ||
101 | def test_version | |
102 | app.configure do | |
103 | config.assets.version = 'v2' | |
104 | end | |
105 | app.initialize! | |
106 | ||
107 | assert env = app.assets | |
108 | assert_equal "test-v2", env.version | |
109 | end | |
110 | ||
111 | def test_configure | |
112 | app.configure do | |
113 | config.assets.configure do |env| | |
114 | env.append_path "javascripts" | |
115 | end | |
116 | config.assets.configure do |env| | |
117 | env.append_path "stylesheets" | |
118 | end | |
119 | end | |
120 | app.initialize! | |
121 | ||
122 | assert env = app.assets | |
123 | assert_equal ["#{ROOT}/javascripts", "#{ROOT}/stylesheets"], | |
124 | env.paths.sort | |
125 | end | |
126 | ||
127 | def test_environment_is_frozen_if_caching_classes | |
128 | app.configure do | |
129 | config.cache_classes = true | |
130 | end | |
131 | app.initialize! | |
132 | ||
133 | assert env = app.assets | |
134 | assert_kind_of Sprockets::Index, env | |
135 | end | |
136 | ||
137 | def test_action_view_helper | |
138 | app.configure do | |
139 | config.assets.paths << FIXTURES_PATH | |
140 | end | |
141 | app.initialize! | |
142 | ||
143 | assert app.assets.paths.include?(FIXTURES_PATH) | |
144 | ||
145 | assert_equal false, ActionView::Base.debug_assets | |
146 | assert_equal false, ActionView::Base.digest_assets | |
147 | assert_equal "/assets", ActionView::Base.assets_prefix | |
148 | assert_equal app.assets, ActionView::Base.assets_environment | |
149 | assert_match %r{public/assets/manifest-.*.json}, ActionView::Base.assets_manifest.path | |
150 | ||
151 | @view = ActionView::Base.new | |
152 | assert_equal "/javascripts/xmlhr.js", @view.javascript_path("xmlhr") | |
153 | assert_equal "/assets/foo.js", @view.javascript_path("foo") | |
154 | end | |
155 | ||
156 | def test_sprockets_context_helper | |
157 | app.initialize! | |
158 | ||
159 | assert env = app.assets | |
160 | assert_equal "/assets", env.context_class.assets_prefix | |
161 | assert_equal false, env.context_class.digest_assets | |
162 | assert_equal nil, env.context_class.config.asset_host | |
163 | end | |
164 | end |
0 | require 'test/unit' | |
1 | require 'tmpdir' | |
2 | ||
3 | require 'sprockets' | |
4 | require 'sprockets/rails/task' | |
5 | ||
6 | class TestTask < Test::Unit::TestCase | |
7 | FIXTURES_PATH = File.expand_path("../fixtures", __FILE__) | |
8 | ||
9 | def setup | |
10 | @rake = Rake::Application.new | |
11 | Rake.application = @rake | |
12 | ||
13 | @assets = Sprockets::Environment.new | |
14 | @assets.append_path FIXTURES_PATH | |
15 | ||
16 | @dir = File.join(Dir::tmpdir, 'rails/task') | |
17 | ||
18 | @manifest = Sprockets::Manifest.new(@assets, @dir) | |
19 | ||
20 | @environment_ran = false | |
21 | # Stub Rails environment task | |
22 | @rake.define_task Rake::Task, :environment do | |
23 | @environment_ran = true | |
24 | end | |
25 | ||
26 | Sprockets::Rails::Task.new do |t| | |
27 | t.environment = @assets | |
28 | t.manifest = @manifest | |
29 | t.assets = ['foo.js', 'foo-modified.js'] | |
30 | t.log_level = :fatal | |
31 | end | |
32 | end | |
33 | ||
34 | def teardown | |
35 | Rake.application = nil | |
36 | ||
37 | FileUtils.rm_rf(@dir) | |
38 | assert Dir["#{@dir}/*"].empty? | |
39 | end | |
40 | ||
41 | def test_precompile | |
42 | assert !@environment_ran | |
43 | ||
44 | digest_path = @assets['foo.js'].digest_path | |
45 | assert !File.exist?("#{@dir}/#{digest_path}") | |
46 | ||
47 | @rake['assets:precompile'].invoke | |
48 | ||
49 | assert @environment_ran | |
50 | assert Dir["#{@dir}/manifest-*.json"].first | |
51 | assert File.exist?("#{@dir}/#{digest_path}") | |
52 | end | |
53 | ||
54 | def test_clobber | |
55 | assert !@environment_ran | |
56 | digest_path = @assets['foo.js'].digest_path | |
57 | ||
58 | @rake['assets:precompile'].invoke | |
59 | assert File.exist?("#{@dir}/#{digest_path}") | |
60 | ||
61 | assert @environment_ran | |
62 | ||
63 | @rake['assets:clobber'].invoke | |
64 | assert !File.exist?("#{@dir}/#{digest_path}") | |
65 | end | |
66 | ||
67 | def test_clean | |
68 | assert !@environment_ran | |
69 | digest_path = @assets['foo.js'].digest_path | |
70 | ||
71 | @rake['assets:precompile'].invoke | |
72 | assert File.exist?("#{@dir}/#{digest_path}") | |
73 | ||
74 | assert @environment_ran | |
75 | ||
76 | @rake['assets:clean'].invoke | |
77 | assert File.exist?("#{@dir}/#{digest_path}") | |
78 | end | |
79 | ||
80 | def test_clean_with_keep_specified | |
81 | assert !@environment_ran | |
82 | path = @assets['foo.js'].pathname | |
83 | new_path = path.join("../foo-modified.js") | |
84 | ||
85 | FileUtils.cp(path, new_path) | |
86 | ||
87 | assert File.exist?(new_path) | |
88 | digest_path = @assets['foo-modified.js'].digest_path | |
89 | ||
90 | @rake['assets:precompile'].invoke | |
91 | assert File.exist?("#{@dir}/#{digest_path}") | |
92 | assert @environment_ran | |
93 | ||
94 | # clean environment | |
95 | setup | |
96 | ||
97 | # modify file | |
98 | File.open(new_path, "a") {|f| f.write("var Bar;") } | |
99 | @rake['assets:precompile'].invoke | |
100 | old_digest_path = digest_path | |
101 | digest_path = @assets['foo-modified.js'].digest_path | |
102 | ||
103 | refute_equal old_digest_path, digest_path | |
104 | assert File.exist?("#{@dir}/#{old_digest_path}") | |
105 | assert File.exist?("#{@dir}/#{digest_path}") | |
106 | ||
107 | @rake['assets:clean'].invoke(0) | |
108 | assert File.exist?("#{@dir}/#{digest_path}") | |
109 | refute File.exist?("#{@dir}/#{old_digest_path}") | |
110 | ensure | |
111 | FileUtils.rm(new_path) if new_path | |
112 | end | |
113 | end |