amiel-sprockets 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. data/Rakefile +26 -0
  2. data/ext/nph-sprockets.cgi +127 -0
  3. data/lib/sprockets.rb +42 -0
  4. data/lib/sprockets/concatenation.rb +36 -0
  5. data/lib/sprockets/environment.rb +52 -0
  6. data/lib/sprockets/error.rb +5 -0
  7. data/lib/sprockets/pathname.rb +37 -0
  8. data/lib/sprockets/preprocessor.rb +92 -0
  9. data/lib/sprockets/secretary.rb +110 -0
  10. data/lib/sprockets/source_file.rb +54 -0
  11. data/lib/sprockets/source_line.rb +86 -0
  12. data/lib/sprockets/version.rb +9 -0
  13. data/test/fixtures/assets/images/script_with_assets/one.png +1 -0
  14. data/test/fixtures/assets/images/script_with_assets/two.png +1 -0
  15. data/test/fixtures/assets/stylesheets/script_with_assets.css +1 -0
  16. data/test/fixtures/constants.yml +1 -0
  17. data/test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js +8 -0
  18. data/test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js +2 -0
  19. data/test/fixtures/multiline_comments_should_be_removed_by_default.js +4 -0
  20. data/test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js +5 -0
  21. data/test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js +1 -0
  22. data/test/fixtures/requiring_a_file_with_css_style_comments_should_replace_the_require_comment_with_file_contents.css +4 -0
  23. data/test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js +3 -0
  24. data/test/fixtures/requiring_the_current_file_should_do_nothing.js +1 -0
  25. data/test/fixtures/src/constants.yml +3 -0
  26. data/test/fixtures/src/foo.css +1 -0
  27. data/test/fixtures/src/foo.js +1 -0
  28. data/test/fixtures/src/foo/bar.js +4 -0
  29. data/test/fixtures/src/foo/foo.js +1 -0
  30. data/test/fixtures/src/script_with_assets.js +3 -0
  31. data/test/test_concatenation.rb +28 -0
  32. data/test/test_environment.rb +64 -0
  33. data/test/test_helper.rb +55 -0
  34. data/test/test_pathname.rb +43 -0
  35. data/test/test_preprocessor.rb +116 -0
  36. data/test/test_secretary.rb +83 -0
  37. data/test/test_source_file.rb +34 -0
  38. data/test/test_source_line.rb +89 -0
  39. metadata +50 -4
@@ -0,0 +1,83 @@
1
+ require "test_helper"
2
+
3
+ class SecretaryTest < Test::Unit::TestCase
4
+ def test_load_locations_are_not_expanded_when_expand_paths_is_false
5
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
6
+ secretary.add_load_location("src/**/", :expand_paths => false)
7
+
8
+ assert_equal [File.join(FIXTURES_PATH, "src/**"), FIXTURES_PATH],
9
+ secretary.environment.load_path.map { |pathname| pathname.absolute_location }
10
+ end
11
+
12
+ def test_load_locations_are_expanded_when_expand_paths_is_true
13
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
14
+ secretary.add_load_location("src/**/", :expand_paths => true)
15
+
16
+ assert_equal [File.join(FIXTURES_PATH, "src", "foo"), File.join(FIXTURES_PATH, "src"), FIXTURES_PATH],
17
+ secretary.environment.load_path.map { |pathname| pathname.absolute_location }
18
+ end
19
+
20
+ def test_source_files_are_not_expanded_when_expand_paths_is_false
21
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
22
+ assert_raises(Sprockets::LoadError) do
23
+ secretary.add_source_file("src/f*.js", :expand_paths => false)
24
+ end
25
+ end
26
+
27
+ def test_source_files_are_expanded_when_expand_paths_is_true
28
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH)
29
+ secretary.add_source_file("src/f*.js", :expand_paths => true)
30
+
31
+ assert_equal [File.join(FIXTURES_PATH, "src", "foo.js")],
32
+ secretary.preprocessor.source_files.map { |source_file| source_file.pathname.absolute_location }
33
+ end
34
+
35
+ def test_install_assets_into_empty_directory
36
+ with_temporary_directory do |temp|
37
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
38
+ secretary.add_source_file("src/script_with_assets.js")
39
+
40
+ assert_equal [], Dir[File.join(temp, "**", "*")]
41
+ secretary.install_assets
42
+ assert_equal paths_relative_to(temp,
43
+ "images", "images/script_with_assets", "images/script_with_assets/one.png",
44
+ "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
45
+ Dir[File.join(temp, "**", "*")].sort
46
+ end
47
+ end
48
+
49
+ def test_install_assets_into_nonexistent_directory
50
+ with_temporary_directory do |temp|
51
+ temp = File.join(temp, "assets")
52
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
53
+ secretary.add_source_file("src/script_with_assets.js")
54
+
55
+ assert_equal [], Dir[File.join(temp, "**", "*")]
56
+ secretary.install_assets
57
+ assert_equal paths_relative_to(temp,
58
+ "images", "images/script_with_assets", "images/script_with_assets/one.png",
59
+ "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
60
+ Dir[File.join(temp, "**", "*")].sort
61
+ end
62
+ end
63
+
64
+ def test_install_assets_into_subdirectories_that_already_exist
65
+ with_temporary_directory do |temp|
66
+ secretary = Sprockets::Secretary.new(:root => FIXTURES_PATH, :asset_root => temp)
67
+ secretary.add_source_file("src/script_with_assets.js")
68
+
69
+ FileUtils.mkdir_p(File.join(temp, "images", "script_with_assets"))
70
+ assert_equal paths_relative_to(temp, "images", "images/script_with_assets"), Dir[File.join(temp, "**", "*")]
71
+ secretary.install_assets
72
+ assert_equal paths_relative_to(temp,
73
+ "images", "images/script_with_assets", "images/script_with_assets/one.png",
74
+ "images/script_with_assets/two.png", "stylesheets", "stylesheets/script_with_assets.css"),
75
+ Dir[File.join(temp, "**", "*")].sort
76
+ end
77
+ end
78
+
79
+ protected
80
+ def paths_relative_to(root, *paths)
81
+ paths.map { |path| File.join(root, path) }
82
+ end
83
+ end
@@ -0,0 +1,34 @@
1
+ require "test_helper"
2
+ require "enumerator"
3
+ Enumerator = Enumerable::Enumerator unless defined?(Enumerator) # for 1.9.1 compatibility
4
+
5
+ class SourceFileTest < Test::Unit::TestCase
6
+ def setup
7
+ @environment = environment_for_fixtures
8
+ end
9
+
10
+ def test_each_source_line
11
+ source_file_lines = Enumerator.new(source_file("src/foo/bar.js"), :each_source_line).to_a
12
+ assert_equal content_of_fixture("src/foo/bar.js"), source_file_lines.map { |line| line.line }.join
13
+ assert_equal 4, source_file_lines.length
14
+ end
15
+
16
+ def test_find_should_return_pathname_for_file_relative_to_the_current_pathname
17
+ assert_absolute_location_ends_with "test/fixtures/src/foo/bar.js", source_file("src/foo/foo.js").find("bar.js")
18
+ end
19
+
20
+ def test_find_should_return_nil_for_nonexistent_file
21
+ assert_nil source_file("src/foo/foo.js").find("nonexistent.js")
22
+ end
23
+
24
+ def test_equality_of_source_files
25
+ assert_equal source_file("src/foo/foo.js"), source_file("src/foo/foo.js")
26
+ assert_equal source_file("src/foo/foo.js"), source_file("src/foo/../foo/foo.js")
27
+ assert_not_equal source_file("src/foo/foo.js"), source_file("src/foo.js")
28
+ assert_not_equal source_file("src/foo/foo.js"), source_file("src/foo/bar.js")
29
+ end
30
+
31
+ def test_mtime_should_return_now_if_file_does_not_exist
32
+ assert source_file("src/foo/nonexistent.js").mtime.instance_of?(Time)
33
+ end
34
+ end
@@ -0,0 +1,89 @@
1
+ require "test_helper"
2
+
3
+ class SourceLineTest < Test::Unit::TestCase
4
+ def test_line_that_begins_with_double_slash_should_be_a_comment
5
+ assert source_line("//").comment?
6
+ assert source_line("//test").comment?
7
+ assert source_line("//= require").comment?
8
+ assert source_line("//= require <foo>").comment?
9
+ assert source_line(" //").comment?
10
+ assert source_line("\t//").comment?
11
+ end
12
+
13
+ def test_line_that_begins_a_multiline_comment
14
+ assert source_line(" /*").begins_multiline_comment?
15
+ assert source_line(" /**").begins_multiline_comment?
16
+ end
17
+
18
+ def test_line_that_begins_a_pdoc_comment
19
+ assert !source_line(" /*").begins_pdoc_comment?
20
+ assert source_line(" /**").begins_pdoc_comment?
21
+ end
22
+
23
+ def test_line_that_ends_a_multiline_comment
24
+ assert source_line(" */").ends_multiline_comment?
25
+ assert source_line(" **/").ends_multiline_comment?
26
+ end
27
+
28
+ def test_line_that_ends_a_pdoc_comment
29
+ assert !source_line(" */").ends_pdoc_comment?
30
+ assert source_line(" **/").ends_pdoc_comment?
31
+ end
32
+
33
+ def test_line_that_contains_but_does_not_begin_with_double_slash_should_not_be_a_comment
34
+ assert !source_line("f //").comment?
35
+ assert !source_line("f //= require <foo>").comment?
36
+ end
37
+
38
+ def test_comment_should_be_extracted_from_comment_lines
39
+ assert_equal "test", source_line("//test").comment
40
+ assert_equal " test", source_line("// test").comment
41
+ assert_equal nil, source_line("f //test").comment
42
+ end
43
+
44
+ def test_line_that_contains_require_comment_should_be_a_require
45
+ assert source_line("//= require <foo>").require?
46
+ assert !source_line("//= require<foo>").require?
47
+ assert source_line("//= require \"foo\"").require?
48
+ assert !source_line("//= require <foo> f").require?
49
+ end
50
+
51
+ def test_require_should_be_extracted_from_require_lines
52
+ assert_nil source_line("//= require").require
53
+ assert_equal "<foo>", source_line("//= require <foo>").require
54
+ assert_equal "<foo>", source_line("//= require <foo> ").require
55
+ assert_equal "\"foo\"", source_line("//= require \"foo\"").require
56
+ end
57
+
58
+ def test_line_that_contains_a_provide_comment_should_be_a_provide
59
+ assert source_line("//= provide \"../assets\"").provide?
60
+ assert !source_line("//= provide").provide?
61
+ assert !source_line("//= provide <../assets>").provide?
62
+ end
63
+
64
+ def test_provide_should_be_extracted_from_provide_lines
65
+ assert_nil source_line("//= provide").provide
66
+ assert_equal "../assets", source_line("//= provide \"../assets\"").provide
67
+ end
68
+
69
+ def test_inspect_should_include_source_file_location_and_line_number
70
+ environment = environment_for_fixtures
71
+ pathname = Sprockets::Pathname.new(environment, "/a/b/c.js")
72
+ source_file = Sprockets::SourceFile.new(environment, pathname)
73
+ assert_equal "line 25 of #{File.expand_path("/a/b/c.js")}", source_line("hello", source_file, 25).inspect
74
+ end
75
+
76
+ def test_interpolation_of_constants
77
+ assert_equal %(var VERSION = "1.0";\n), source_line('var VERSION = "<%= VERSION %>";').to_s("VERSION" => "1.0")
78
+ end
79
+
80
+ def test_interpolation_of_missing_constant_raises_undefined_constant_error
81
+ assert_raises(Sprockets::UndefinedConstantError) do
82
+ source_line('<%= NONEXISTENT %>').to_s("VERSION" => "1.0")
83
+ end
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
89
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amiel-sprockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
@@ -22,8 +22,54 @@ extensions: []
22
22
 
23
23
  extra_rdoc_files: []
24
24
 
25
- files: []
26
-
25
+ files:
26
+ - Rakefile
27
+ - bin/sprocketize
28
+ - lib/sprockets
29
+ - lib/sprockets/concatenation.rb
30
+ - lib/sprockets/environment.rb
31
+ - lib/sprockets/error.rb
32
+ - lib/sprockets/pathname.rb
33
+ - lib/sprockets/preprocessor.rb
34
+ - lib/sprockets/secretary.rb
35
+ - lib/sprockets/source_file.rb
36
+ - lib/sprockets/source_line.rb
37
+ - lib/sprockets/version.rb
38
+ - lib/sprockets.rb
39
+ - test/fixtures
40
+ - test/fixtures/assets
41
+ - test/fixtures/assets/images
42
+ - test/fixtures/assets/images/script_with_assets
43
+ - test/fixtures/assets/images/script_with_assets/one.png
44
+ - test/fixtures/assets/images/script_with_assets/two.png
45
+ - test/fixtures/assets/stylesheets
46
+ - test/fixtures/assets/stylesheets/script_with_assets.css
47
+ - test/fixtures/constants.yml
48
+ - test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js
49
+ - test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js
50
+ - test/fixtures/multiline_comments_should_be_removed_by_default.js
51
+ - test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js
52
+ - test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js
53
+ - test/fixtures/requiring_a_file_with_css_style_comments_should_replace_the_require_comment_with_file_contents.css
54
+ - test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js
55
+ - test/fixtures/requiring_the_current_file_should_do_nothing.js
56
+ - test/fixtures/src
57
+ - test/fixtures/src/constants.yml
58
+ - test/fixtures/src/foo
59
+ - test/fixtures/src/foo/bar.js
60
+ - test/fixtures/src/foo/foo.js
61
+ - test/fixtures/src/foo.css
62
+ - test/fixtures/src/foo.js
63
+ - test/fixtures/src/script_with_assets.js
64
+ - test/test_concatenation.rb
65
+ - test/test_environment.rb
66
+ - test/test_helper.rb
67
+ - test/test_pathname.rb
68
+ - test/test_preprocessor.rb
69
+ - test/test_secretary.rb
70
+ - test/test_source_file.rb
71
+ - test/test_source_line.rb
72
+ - ext/nph-sprockets.cgi
27
73
  has_rdoc: false
28
74
  homepage: http://getsprockets.org/
29
75
  post_install_message:
@@ -45,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
91
  version:
46
92
  requirements: []
47
93
 
48
- rubyforge_project:
94
+ rubyforge_project: sprockets
49
95
  rubygems_version: 1.2.0
50
96
  signing_key:
51
97
  specification_version: 2