sprockets 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sprockets might be problematic. Click here for more details.
- data/lib/sprockets/source_line.rb +20 -8
- data/lib/sprockets/version.rb +3 -3
- data/test/test_secretary.rb +7 -7
- data/test/test_source_file.rb +2 -1
- data/test/test_source_line.rb +4 -0
- metadata +3 -3
@@ -57,14 +57,26 @@ module Sprockets
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def to_s(constants = source_file.environment.constants)
|
60
|
-
line.chomp
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
else
|
65
|
-
raise UndefinedConstantError, "couldn't find constant `#{constant}' in #{inspect}"
|
66
|
-
end
|
67
|
-
end + $/
|
60
|
+
result = line.chomp
|
61
|
+
interpolate_constants!(result, constants)
|
62
|
+
strip_trailing_whitespace!(result)
|
63
|
+
result + $/
|
68
64
|
end
|
65
|
+
|
66
|
+
protected
|
67
|
+
def interpolate_constants!(result, constants)
|
68
|
+
result.gsub!(/<%=(.*?)%>/) do
|
69
|
+
constant = $1.strip
|
70
|
+
if value = constants[constant]
|
71
|
+
value
|
72
|
+
else
|
73
|
+
raise UndefinedConstantError, "couldn't find constant `#{constant}' in #{inspect}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def strip_trailing_whitespace!(result)
|
79
|
+
result.gsub!(/\s+$/, "")
|
80
|
+
end
|
69
81
|
end
|
70
82
|
end
|
data/lib/sprockets/version.rb
CHANGED
data/test/test_secretary.rb
CHANGED
@@ -3,7 +3,7 @@ require "test_helper"
|
|
3
3
|
class SecretaryTest < Test::Unit::TestCase
|
4
4
|
def test_load_locations_are_not_expanded_when_expand_paths_is_false
|
5
5
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
|
6
|
-
secretary.
|
6
|
+
secretary.add_load_location("src/**/", :expand_paths => false)
|
7
7
|
|
8
8
|
assert_equal [File.join(FIXTURES_PATH, "src/**"), FIXTURES_PATH],
|
9
9
|
secretary.environment.load_path.map { |pathname| pathname.absolute_location }
|
@@ -11,7 +11,7 @@ class SecretaryTest < Test::Unit::TestCase
|
|
11
11
|
|
12
12
|
def test_load_locations_are_expanded_when_expand_paths_is_true
|
13
13
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
|
14
|
-
secretary.
|
14
|
+
secretary.add_load_location("src/**/", :expand_paths => true)
|
15
15
|
|
16
16
|
assert_equal [File.join(FIXTURES_PATH, "src", "foo"), File.join(FIXTURES_PATH, "src"), FIXTURES_PATH],
|
17
17
|
secretary.environment.load_path.map { |pathname| pathname.absolute_location }
|
@@ -20,13 +20,13 @@ class SecretaryTest < Test::Unit::TestCase
|
|
20
20
|
def test_source_files_are_not_expanded_when_expand_paths_is_false
|
21
21
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
|
22
22
|
assert_raises(Sprockets::LoadError) do
|
23
|
-
secretary.
|
23
|
+
secretary.add_source_file("src/f*.js", :expand_paths => false)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_source_files_are_expanded_when_expand_paths_is_true
|
28
28
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
|
29
|
-
secretary.
|
29
|
+
secretary.add_source_file("src/f*.js", :expand_paths => true)
|
30
30
|
|
31
31
|
assert_equal [File.join(FIXTURES_PATH, "src", "foo.js")],
|
32
32
|
secretary.preprocessor.source_files.map { |source_file| source_file.pathname.absolute_location }
|
@@ -35,7 +35,7 @@ class SecretaryTest < Test::Unit::TestCase
|
|
35
35
|
def test_install_assets_into_empty_directory
|
36
36
|
with_temporary_directory do |temp|
|
37
37
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
|
38
|
-
secretary.
|
38
|
+
secretary.add_source_file("src/script_with_assets.js")
|
39
39
|
|
40
40
|
assert_equal [], Dir[File.join(temp, "**", "*")]
|
41
41
|
secretary.install_assets
|
@@ -50,7 +50,7 @@ class SecretaryTest < Test::Unit::TestCase
|
|
50
50
|
with_temporary_directory do |temp|
|
51
51
|
temp = File.join(temp, "assets")
|
52
52
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
|
53
|
-
secretary.
|
53
|
+
secretary.add_source_file("src/script_with_assets.js")
|
54
54
|
|
55
55
|
assert_equal [], Dir[File.join(temp, "**", "*")]
|
56
56
|
secretary.install_assets
|
@@ -64,7 +64,7 @@ class SecretaryTest < Test::Unit::TestCase
|
|
64
64
|
def test_install_assets_into_subdirectories_that_already_exist
|
65
65
|
with_temporary_directory do |temp|
|
66
66
|
secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
|
67
|
-
secretary.
|
67
|
+
secretary.add_source_file("src/script_with_assets.js")
|
68
68
|
|
69
69
|
FileUtils.mkdir_p(File.join(temp, "images", "script_with_assets"))
|
70
70
|
assert_equal paths_relative_to(temp, "images", "images/script_with_assets"), Dir[File.join(temp, "**", "*")]
|
data/test/test_source_file.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "enumerator"
|
3
|
+
Enumerator = Enumerable::Enumerator unless defined?(Enumerator) # for 1.9.1 compatibility
|
3
4
|
|
4
5
|
class SourceFileTest < Test::Unit::TestCase
|
5
6
|
def setup
|
@@ -7,7 +8,7 @@ class SourceFileTest < Test::Unit::TestCase
|
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_each_source_line
|
10
|
-
source_file_lines =
|
11
|
+
source_file_lines = Enumerator.new(source_file("src/foo/bar.js"), :each_source_line).to_a
|
11
12
|
assert_equal content_of_fixture("src/foo/bar.js"), source_file_lines.map { |line| line.line }.join
|
12
13
|
assert_equal 4, source_file_lines.length
|
13
14
|
end
|
data/test/test_source_line.rb
CHANGED
@@ -82,4 +82,8 @@ class SourceLineTest < Test::Unit::TestCase
|
|
82
82
|
source_line('<%= NONEXISTENT %>').to_s("VERSION" => "1.0")
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
def test_to_s_should_strip_trailing_whitespace_before_adding_line_ending
|
87
|
+
assert_equal "hello();\n", source_line("hello(); \t \r\n").to_s({})
|
88
|
+
end
|
85
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-17 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- test/test_source_file.rb
|
68
68
|
- test/test_source_line.rb
|
69
69
|
has_rdoc: false
|
70
|
-
homepage: http://
|
70
|
+
homepage: http://getsprockets.org/
|
71
71
|
post_install_message:
|
72
72
|
rdoc_options: []
|
73
73
|
|