sprockets 1.0.2 → 2.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.

Files changed (64) hide show
  1. data/LICENSE +21 -0
  2. data/README.md +356 -0
  3. data/lib/sprockets.rb +26 -37
  4. data/lib/sprockets/asset.rb +212 -0
  5. data/lib/sprockets/asset_attributes.rb +158 -0
  6. data/lib/sprockets/base.rb +163 -0
  7. data/lib/sprockets/bundled_asset.rb +258 -0
  8. data/lib/sprockets/cache/file_store.rb +41 -0
  9. data/lib/sprockets/caching.rb +123 -0
  10. data/lib/sprockets/charset_normalizer.rb +41 -0
  11. data/lib/sprockets/context.rb +217 -0
  12. data/lib/sprockets/digest.rb +67 -0
  13. data/lib/sprockets/directive_processor.rb +380 -0
  14. data/lib/sprockets/eco_template.rb +38 -0
  15. data/lib/sprockets/ejs_template.rb +37 -0
  16. data/lib/sprockets/engines.rb +98 -0
  17. data/lib/sprockets/environment.rb +81 -40
  18. data/lib/sprockets/errors.rb +17 -0
  19. data/lib/sprockets/index.rb +79 -0
  20. data/lib/sprockets/jst_processor.rb +26 -0
  21. data/lib/sprockets/mime.rb +38 -0
  22. data/lib/sprockets/processing.rb +280 -0
  23. data/lib/sprockets/processor.rb +32 -0
  24. data/lib/sprockets/safety_colons.rb +28 -0
  25. data/lib/sprockets/server.rb +272 -0
  26. data/lib/sprockets/static_asset.rb +86 -0
  27. data/lib/sprockets/trail.rb +114 -0
  28. data/lib/sprockets/utils.rb +67 -0
  29. data/lib/sprockets/version.rb +1 -7
  30. metadata +212 -64
  31. data/Rakefile +0 -19
  32. data/bin/sprocketize +0 -54
  33. data/ext/nph-sprockets.cgi +0 -127
  34. data/lib/sprockets/concatenation.rb +0 -36
  35. data/lib/sprockets/error.rb +0 -5
  36. data/lib/sprockets/pathname.rb +0 -37
  37. data/lib/sprockets/preprocessor.rb +0 -91
  38. data/lib/sprockets/secretary.rb +0 -106
  39. data/lib/sprockets/source_file.rb +0 -54
  40. data/lib/sprockets/source_line.rb +0 -82
  41. data/test/fixtures/assets/images/script_with_assets/one.png +0 -1
  42. data/test/fixtures/assets/images/script_with_assets/two.png +0 -1
  43. data/test/fixtures/assets/stylesheets/script_with_assets.css +0 -1
  44. data/test/fixtures/constants.yml +0 -1
  45. data/test/fixtures/double_slash_comments_that_are_not_requires_should_be_ignored_when_strip_comments_is_false.js +0 -8
  46. data/test/fixtures/double_slash_comments_that_are_not_requires_should_be_removed_by_default.js +0 -2
  47. data/test/fixtures/multiline_comments_should_be_removed_by_default.js +0 -4
  48. data/test/fixtures/requiring_a_file_after_it_has_already_been_required_should_do_nothing.js +0 -5
  49. data/test/fixtures/requiring_a_file_that_does_not_exist_should_raise_an_error.js +0 -1
  50. data/test/fixtures/requiring_a_single_file_should_replace_the_require_comment_with_the_file_contents.js +0 -3
  51. data/test/fixtures/requiring_the_current_file_should_do_nothing.js +0 -1
  52. data/test/fixtures/src/constants.yml +0 -3
  53. data/test/fixtures/src/foo.js +0 -1
  54. data/test/fixtures/src/foo/bar.js +0 -4
  55. data/test/fixtures/src/foo/foo.js +0 -1
  56. data/test/fixtures/src/script_with_assets.js +0 -3
  57. data/test/test_concatenation.rb +0 -28
  58. data/test/test_environment.rb +0 -64
  59. data/test/test_helper.rb +0 -55
  60. data/test/test_pathname.rb +0 -43
  61. data/test/test_preprocessor.rb +0 -107
  62. data/test/test_secretary.rb +0 -83
  63. data/test/test_source_file.rb +0 -34
  64. data/test/test_source_line.rb +0 -89
@@ -1,83 +0,0 @@
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
@@ -1,34 +0,0 @@
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
@@ -1,89 +0,0 @@
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