bpm 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/.gitmodules +3 -0
  2. data/Gemfile +0 -13
  3. data/TODO.md +1 -0
  4. data/bpm.gemspec +8 -3
  5. data/lib/bpm/cli/base.rb +22 -20
  6. data/lib/bpm/generator.rb +3 -3
  7. data/lib/bpm/libgems_ext/dependency_installer.rb +4 -4
  8. data/lib/bpm/libgems_ext/installer.rb +1 -1
  9. data/lib/bpm/package.rb +13 -9
  10. data/lib/bpm/pipeline/generated_asset.rb +30 -3
  11. data/lib/bpm/pipeline/transport_processor.rb +20 -12
  12. data/lib/bpm/pipeline.rb +17 -9
  13. data/lib/bpm/project.rb +42 -10
  14. data/lib/bpm/server.rb +5 -0
  15. data/lib/bpm/version.rb +1 -1
  16. data/lib/bpm.rb +2 -0
  17. data/lib/vendored_sprockets.rb +7 -0
  18. data/spec/cli/add_spec.rb +40 -37
  19. data/spec/cli/build_spec.rb +5 -5
  20. data/spec/cli/new_spec.rb +49 -23
  21. data/spec/cli/push_spec.rb +5 -5
  22. data/spec/cli/unpack_spec.rb +14 -14
  23. data/spec/fixtures/{badrake-0.8.7.spd → badrake-0.8.7.bpkg} +0 -0
  24. data/spec/fixtures/{builder-3.0.0.spd → builder-3.0.0.bpkg} +0 -0
  25. data/spec/fixtures/{bundler-1.1.pre.spd → bundler-1.1.pre.bpkg} +0 -0
  26. data/spec/fixtures/{coffee-1.0.1.pre.spd → coffee-1.0.1.pre.bpkg} +0 -0
  27. data/spec/fixtures/{core-test-0.4.9.spd → core-test-0.4.9.bpkg} +0 -0
  28. data/spec/fixtures/{custom_generator-1.0.spd → custom_generator-1.0.bpkg} +0 -0
  29. data/spec/fixtures/custom_name/MyProject.json +4 -0
  30. data/spec/fixtures/hello_world/css/dummy.css +3 -0
  31. data/spec/fixtures/{highline-1.6.1.spd → highline-1.6.1.bpkg} +0 -0
  32. data/spec/fixtures/{ivory-0.0.1.spd → ivory-0.0.1.bpkg} +0 -0
  33. data/spec/fixtures/{jquery-1.4.3.spd → jquery-1.4.3.bpkg} +0 -0
  34. data/spec/fixtures/minitest/assets/bpm_packages.js +1 -0
  35. data/spec/fixtures/minitest/assets/bpm_styles.css +0 -0
  36. data/spec/fixtures/minitest/assets/minitest/app_package.js +1 -0
  37. data/spec/fixtures/minitest/lib/main.js +1 -0
  38. data/spec/fixtures/minitest/minitest.json +22 -0
  39. data/spec/fixtures/minitest/packages/uglyduck/lib/main.js +1 -0
  40. data/spec/fixtures/minitest/packages/uglyduck/minifier/main.js +4 -0
  41. data/spec/fixtures/minitest/packages/uglyduck/package.json +21 -0
  42. data/spec/fixtures/{optparse-1.0.1.spd → optparse-1.0.1.bpkg} +0 -0
  43. data/spec/fixtures/{rake-0.8.6.spd → rake-0.8.6.bpkg} +0 -0
  44. data/spec/fixtures/{rake-0.8.7.spd → rake-0.8.7.bpkg} +0 -0
  45. data/spec/fixtures/{spade-0.5.0.spd → spade-0.5.0.bpkg} +0 -0
  46. data/spec/fixtures/transporter/packages/transport/lib/main.js +1 -0
  47. data/spec/fixtures/transporter/packages/transport/package.json +1 -1
  48. data/spec/fixtures/transporter/packages/transport/transports/wrapper.js +5 -0
  49. data/spec/gauntlet_spec.rb +2 -2
  50. data/spec/package_spec.rb +3 -3
  51. data/spec/pipeline_spec.rb +175 -54
  52. data/spec/project_spec.rb +19 -3
  53. data/spec/support/fake_gem_server.rb +4 -4
  54. data/templates/init/project.json +3 -1
  55. data/templates/project/index.html +1 -1
  56. data/vendor/sprockets/.gitignore +7 -0
  57. data/vendor/sprockets/.travis.yml +6 -0
  58. data/vendor/sprockets/Gemfile +8 -0
  59. data/vendor/sprockets/LICENSE +20 -0
  60. data/vendor/sprockets/README.md +22 -0
  61. data/vendor/sprockets/Rakefile +8 -0
  62. data/vendor/sprockets/lib/sprockets/asset.rb +203 -0
  63. data/vendor/sprockets/lib/sprockets/asset_attributes.rb +161 -0
  64. data/vendor/sprockets/lib/sprockets/base.rb +147 -0
  65. data/vendor/sprockets/lib/sprockets/bundled_asset.rb +222 -0
  66. data/vendor/sprockets/lib/sprockets/cache/file_store.rb +41 -0
  67. data/vendor/sprockets/lib/sprockets/caching.rb +121 -0
  68. data/vendor/sprockets/lib/sprockets/charset_normalizer.rb +41 -0
  69. data/vendor/sprockets/lib/sprockets/context.rb +191 -0
  70. data/vendor/sprockets/lib/sprockets/digest.rb +73 -0
  71. data/vendor/sprockets/lib/sprockets/directive_processor.rb +380 -0
  72. data/vendor/sprockets/lib/sprockets/eco_template.rb +39 -0
  73. data/vendor/sprockets/lib/sprockets/ejs_template.rb +38 -0
  74. data/vendor/sprockets/lib/sprockets/engines.rb +92 -0
  75. data/vendor/sprockets/lib/sprockets/environment.rb +93 -0
  76. data/vendor/sprockets/lib/sprockets/errors.rb +17 -0
  77. data/vendor/sprockets/lib/sprockets/index.rb +80 -0
  78. data/vendor/sprockets/lib/sprockets/jst_processor.rb +26 -0
  79. data/vendor/sprockets/lib/sprockets/processing.rb +310 -0
  80. data/vendor/sprockets/lib/sprockets/processor.rb +32 -0
  81. data/vendor/sprockets/lib/sprockets/safety_colons.rb +28 -0
  82. data/vendor/sprockets/lib/sprockets/server.rb +270 -0
  83. data/vendor/sprockets/lib/sprockets/static_asset.rb +87 -0
  84. data/vendor/sprockets/lib/sprockets/static_compilation.rb +82 -0
  85. data/vendor/sprockets/lib/sprockets/trail.rb +122 -0
  86. data/vendor/sprockets/lib/sprockets/utils.rb +67 -0
  87. data/vendor/sprockets/lib/sprockets/version.rb +3 -0
  88. data/vendor/sprockets/lib/sprockets.rb +31 -0
  89. data/vendor/sprockets/sprockets.gemspec +30 -0
  90. data/vendor/sprockets/test/fixtures/asset/POW.png +0 -0
  91. data/vendor/sprockets/test/fixtures/asset/application.js +6 -0
  92. data/vendor/sprockets/test/fixtures/asset/bar-utf8.css +2 -0
  93. data/vendor/sprockets/test/fixtures/asset/charset.css +2 -0
  94. data/vendor/sprockets/test/fixtures/asset/circle/a.js +2 -0
  95. data/vendor/sprockets/test/fixtures/asset/circle/b.js +2 -0
  96. data/vendor/sprockets/test/fixtures/asset/circle/c.js +2 -0
  97. data/vendor/sprockets/test/fixtures/asset/compat.js +4 -0
  98. data/vendor/sprockets/test/fixtures/asset/constants.js +2 -0
  99. data/vendor/sprockets/test/fixtures/asset/constants.yml +1 -0
  100. data/vendor/sprockets/test/fixtures/asset/default_mime_type.js +1 -0
  101. data/vendor/sprockets/test/fixtures/asset/filename.js.erb +1 -0
  102. data/vendor/sprockets/test/fixtures/asset/foo-utf8.css +2 -0
  103. data/vendor/sprockets/test/fixtures/asset/included_header.js +4 -0
  104. data/vendor/sprockets/test/fixtures/asset/jquery.tmpl.min.js +1 -0
  105. data/vendor/sprockets/test/fixtures/asset/mismatch.js +1 -0
  106. data/vendor/sprockets/test/fixtures/asset/multiple.js +2 -0
  107. data/vendor/sprockets/test/fixtures/asset/multipleengine.js +1 -0
  108. data/vendor/sprockets/test/fixtures/asset/noengine.js +1 -0
  109. data/vendor/sprockets/test/fixtures/asset/noformat.coffee +1 -0
  110. data/vendor/sprockets/test/fixtures/asset/one.css +1 -0
  111. data/vendor/sprockets/test/fixtures/asset/oneengine.js +1 -0
  112. data/vendor/sprockets/test/fixtures/asset/project.css +1 -0
  113. data/vendor/sprockets/test/fixtures/asset/project.js.erb +4 -0
  114. data/vendor/sprockets/test/fixtures/asset/relative/include.js +4 -0
  115. data/vendor/sprockets/test/fixtures/asset/relative/require.js +1 -0
  116. data/vendor/sprockets/test/fixtures/asset/relative/require_outside_path.js +1 -0
  117. data/vendor/sprockets/test/fixtures/asset/require_self.css +9 -0
  118. data/vendor/sprockets/test/fixtures/asset/require_self_twice.css +8 -0
  119. data/vendor/sprockets/test/fixtures/asset/semicolons/bar.js +1 -0
  120. data/vendor/sprockets/test/fixtures/asset/semicolons/index.js +5 -0
  121. data/vendor/sprockets/test/fixtures/asset/sprite.css.erb +12 -0
  122. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/d.js +2 -0
  123. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/e.js +1 -0
  124. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c.js +1 -0
  125. data/vendor/sprockets/test/fixtures/asset/tree/all/b.css +2 -0
  126. data/vendor/sprockets/test/fixtures/asset/tree/all/b.js.erb +1 -0
  127. data/vendor/sprockets/test/fixtures/asset/tree/all/d/c.js.coffee +1 -0
  128. data/vendor/sprockets/test/fixtures/asset/tree/all/d/e.js +1 -0
  129. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require.js +7 -0
  130. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_directory.js +1 -0
  131. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_tree.js +2 -0
  132. data/vendor/sprockets/test/fixtures/asset/tree/directory/application.js +2 -0
  133. data/vendor/sprockets/test/fixtures/asset/tree/directory/bar.js +1 -0
  134. data/vendor/sprockets/test/fixtures/asset/tree/directory/foo.js +1 -0
  135. data/vendor/sprockets/test/fixtures/asset/tree/tree/application.js +2 -0
  136. data/vendor/sprockets/test/fixtures/asset/tree/tree/bar.js +1 -0
  137. data/vendor/sprockets/test/fixtures/asset/tree/tree/foo.js +1 -0
  138. data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/a/a.js +1 -0
  139. data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/require_tree_with_logical_path.js +1 -0
  140. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/a.js +1 -0
  141. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/b.js +1 -0
  142. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/require_tree_without_argument.js +1 -0
  143. data/vendor/sprockets/test/fixtures/asset/two.css +1 -0
  144. data/vendor/sprockets/test/fixtures/asset/unicode.js +2 -0
  145. data/vendor/sprockets/test/fixtures/asset/unknownexts.min.js +2 -0
  146. data/vendor/sprockets/test/fixtures/asset/users.js.erb.str +4 -0
  147. data/vendor/sprockets/test/fixtures/context/POW.png +0 -0
  148. data/vendor/sprockets/test/fixtures/context/application.js.yml +3 -0
  149. data/vendor/sprockets/test/fixtures/context/bar.js +1 -0
  150. data/vendor/sprockets/test/fixtures/context/foo.js +2 -0
  151. data/vendor/sprockets/test/fixtures/context/helpers.css.erb +3 -0
  152. data/vendor/sprockets/test/fixtures/context/properties.js.erb +7 -0
  153. data/vendor/sprockets/test/fixtures/context/require_glob.js +1 -0
  154. data/vendor/sprockets/test/fixtures/context/resolve_content_type.js.erb +4 -0
  155. data/vendor/sprockets/test/fixtures/context/sprite.css.embed +3 -0
  156. data/vendor/sprockets/test/fixtures/default/application.js.coffee +4 -0
  157. data/vendor/sprockets/test/fixtures/default/coffee/foo.coffee +1 -0
  158. data/vendor/sprockets/test/fixtures/default/coffee/index.js +3 -0
  159. data/vendor/sprockets/test/fixtures/default/empty +0 -0
  160. data/vendor/sprockets/test/fixtures/default/gallery.css.erb +3 -0
  161. data/vendor/sprockets/test/fixtures/default/gallery.js +1 -0
  162. data/vendor/sprockets/test/fixtures/default/goodbye.jst.eco +1 -0
  163. data/vendor/sprockets/test/fixtures/default/hello.jst.ejs +1 -0
  164. data/vendor/sprockets/test/fixtures/default/hello.txt +1 -0
  165. data/vendor/sprockets/test/fixtures/default/interpolation.js +1 -0
  166. data/vendor/sprockets/test/fixtures/default/missing_require.js +1 -0
  167. data/vendor/sprockets/test/fixtures/default/mobile/a.js +1 -0
  168. data/vendor/sprockets/test/fixtures/default/mobile/b.js +1 -0
  169. data/vendor/sprockets/test/fixtures/default/mobile/c.css +1 -0
  170. data/vendor/sprockets/test/fixtures/default/mobile/d.css +1 -0
  171. data/vendor/sprockets/test/fixtures/default/mobile/index.css +3 -0
  172. data/vendor/sprockets/test/fixtures/default/mobile/index.js +1 -0
  173. data/vendor/sprockets/test/fixtures/default/noreturn.js +1 -0
  174. data/vendor/sprockets/test/fixtures/default/project.js.coffee.erb +2 -0
  175. data/vendor/sprockets/test/fixtures/directives/code_before_comment +3 -0
  176. data/vendor/sprockets/test/fixtures/directives/comment_without_directives +6 -0
  177. data/vendor/sprockets/test/fixtures/directives/directive_word_splitting +6 -0
  178. data/vendor/sprockets/test/fixtures/directives/directives_after_header +16 -0
  179. data/vendor/sprockets/test/fixtures/directives/double_slash +9 -0
  180. data/vendor/sprockets/test/fixtures/directives/hash +8 -0
  181. data/vendor/sprockets/test/fixtures/directives/no_header +2 -0
  182. data/vendor/sprockets/test/fixtures/directives/slash_star +10 -0
  183. data/vendor/sprockets/test/fixtures/directives/slash_star_single +4 -0
  184. data/vendor/sprockets/test/fixtures/directives/space_between_directive_word +2 -0
  185. data/vendor/sprockets/test/fixtures/directives/triple_hash +10 -0
  186. data/vendor/sprockets/test/fixtures/encoding/ascii.js +1 -0
  187. data/vendor/sprockets/test/fixtures/encoding/ascii_utf8.js +2 -0
  188. data/vendor/sprockets/test/fixtures/encoding/utf16.js +0 -0
  189. data/vendor/sprockets/test/fixtures/encoding/utf8.js +1 -0
  190. data/vendor/sprockets/test/fixtures/encoding/utf8_bom.js +1 -0
  191. data/vendor/sprockets/test/fixtures/engines/hello.alert +1 -0
  192. data/vendor/sprockets/test/fixtures/engines/moo.js.str +1 -0
  193. data/vendor/sprockets/test/fixtures/public/compiled-digest-0aa2105d29558f3eb790d411d7d8fb66.js +3 -0
  194. data/vendor/sprockets/test/fixtures/public/compiled-digest-1c41eb0cf934a0c76babe875f982f9d1.js +1 -0
  195. data/vendor/sprockets/test/fixtures/server/app/javascripts/application.js +5 -0
  196. data/vendor/sprockets/test/fixtures/server/app/javascripts/bar.js +1 -0
  197. data/vendor/sprockets/test/fixtures/server/app/javascripts/foo.js +1 -0
  198. data/vendor/sprockets/test/fixtures/server/app/javascripts/hello.txt +2 -0
  199. data/vendor/sprockets/test/fixtures/server/app/javascripts/tree.js +1 -0
  200. data/vendor/sprockets/test/fixtures/server/vendor/javascripts/missing_require.js +1 -0
  201. data/vendor/sprockets/test/fixtures/server/vendor/stylesheets/missing_require.css +1 -0
  202. data/vendor/sprockets/test/sprockets_test.rb +56 -0
  203. data/vendor/sprockets/test/test_asset.rb +593 -0
  204. data/vendor/sprockets/test/test_asset_attributes.rb +86 -0
  205. data/vendor/sprockets/test/test_caching.rb +62 -0
  206. data/vendor/sprockets/test/test_context.rb +115 -0
  207. data/vendor/sprockets/test/test_directive_processor.rb +124 -0
  208. data/vendor/sprockets/test/test_encoding.rb +65 -0
  209. data/vendor/sprockets/test/test_engines.rb +73 -0
  210. data/vendor/sprockets/test/test_environment.rb +610 -0
  211. data/vendor/sprockets/test/test_server.rb +227 -0
  212. metadata +258 -54
  213. data/spec/fixtures/transporter/packages/transport/lib/wrapper.js +0 -5
@@ -0,0 +1,86 @@
1
+ require 'sprockets_test'
2
+
3
+ class TestAssetAttributes < Sprockets::TestCase
4
+ test "basename with extensions" do
5
+ assert_equal "empty",
6
+ pathname("empty").basename_without_extensions.to_s
7
+ assert_equal "gallery",
8
+ pathname("gallery.js").basename_without_extensions.to_s
9
+ assert_equal "application",
10
+ pathname("application.js.coffee").basename_without_extensions.to_s
11
+ assert_equal "project",
12
+ pathname("project.js.coffee.erb").basename_without_extensions.to_s
13
+ assert_equal "gallery",
14
+ pathname("gallery.css.erb").basename_without_extensions.to_s
15
+ end
16
+
17
+ test "extensions" do
18
+ assert_equal [],
19
+ pathname("empty").extensions
20
+ assert_equal [".js"],
21
+ pathname("gallery.js").extensions
22
+ assert_equal [".js", ".coffee"],
23
+ pathname("application.js.coffee").extensions
24
+ assert_equal [".js", ".coffee", ".erb"],
25
+ pathname("project.js.coffee.erb").extensions
26
+ assert_equal [".css", ".erb"],
27
+ pathname("gallery.css.erb").extensions
28
+ end
29
+
30
+ test "format_extension" do
31
+ assert_equal nil, pathname("empty").format_extension
32
+ assert_equal ".js", pathname("gallery.js").format_extension
33
+ assert_equal ".js", pathname("application.js.coffee").format_extension
34
+ assert_equal ".js", pathname("project.js.coffee.erb").format_extension
35
+ assert_equal ".css", pathname("gallery.css.erb").format_extension
36
+ assert_equal nil, pathname("gallery.erb").format_extension
37
+ assert_equal nil, pathname("gallery.foo").format_extension
38
+ assert_equal ".js", pathname("jquery.js").format_extension
39
+ assert_equal ".js", pathname("jquery.min.js").format_extension
40
+ assert_equal ".js", pathname("jquery.tmpl.js").format_extension
41
+ assert_equal ".js", pathname("jquery.tmpl.min.js").format_extension
42
+ end
43
+
44
+ test "engine_extensions" do
45
+ assert_equal [], pathname("empty").engine_extensions
46
+ assert_equal [], pathname("gallery.js").engine_extensions
47
+ assert_equal [".coffee"],
48
+ pathname("application.js.coffee").engine_extensions
49
+ assert_equal [".coffee", ".erb"],
50
+ pathname("project.js.coffee.erb").engine_extensions
51
+ assert_equal [".erb"], pathname("gallery.css.erb").engine_extensions
52
+ assert_equal [".erb"], pathname("gallery.erb").engine_extensions
53
+ assert_equal [], pathname("jquery.js").engine_extensions
54
+ assert_equal [], pathname("jquery.min.js").engine_extensions
55
+ assert_equal [], pathname("jquery.tmpl.min.js").engine_extensions
56
+ assert_equal [".erb"], pathname("jquery.js.erb").engine_extensions
57
+ assert_equal [".erb"], pathname("jquery.min.js.erb").engine_extensions
58
+ assert_equal [".coffee"],
59
+ pathname("jquery.min.coffee").engine_extensions
60
+ end
61
+
62
+ test "content_type" do
63
+ assert_equal "application/octet-stream",
64
+ pathname("empty").content_type
65
+ assert_equal "application/javascript",
66
+ pathname("gallery.js").content_type
67
+ assert_equal "application/javascript",
68
+ pathname("application.js.coffee").content_type
69
+ assert_equal "application/javascript",
70
+ pathname("project.js.coffee.erb").content_type
71
+ assert_equal "text/css",
72
+ pathname("gallery.css.erb").content_type
73
+ assert_equal "application/javascript",
74
+ pathname("jquery.tmpl.min.js").content_type
75
+
76
+ if Tilt::CoffeeScriptTemplate.respond_to?(:default_mime_type)
77
+ assert_equal "application/javascript",
78
+ pathname("application.coffee").content_type
79
+ end
80
+ end
81
+
82
+ private
83
+ def pathname(path)
84
+ Sprockets::Environment.new.attributes_for(path)
85
+ end
86
+ end
@@ -0,0 +1,62 @@
1
+ require 'sprockets_test'
2
+
3
+ class TestCaching < Sprockets::TestCase
4
+ def setup
5
+ @cache = {}
6
+
7
+ @env1 = Sprockets::Environment.new(fixture_path('default')) do |env|
8
+ env.append_path(".")
9
+ env.cache = @cache
10
+ end
11
+
12
+ @env2 = Sprockets::Environment.new(fixture_path('symlink')) do |env|
13
+ env.append_path(".")
14
+ env.cache = @cache
15
+ end
16
+ end
17
+
18
+ test "environment digests are the same for different roots" do
19
+ assert_equal @env1.digest, @env2.digest
20
+ end
21
+
22
+ test "shared cache objects are eql" do
23
+ asset1 = @env1['gallery.js']
24
+ asset2 = @env2['gallery.js']
25
+
26
+ assert asset1
27
+ assert asset2
28
+
29
+ assert asset1.eql?(asset2)
30
+ assert asset2.eql?(asset1)
31
+ assert !asset1.equal?(asset2)
32
+ end
33
+
34
+ test "stale cached asset isn't loaded if file is remove" do
35
+ filename = fixture_path("default/tmp.js")
36
+
37
+ sandbox filename do
38
+ File.open(filename, 'w') { |f| f.puts "foo;" }
39
+ assert_equal "foo;\n", @env1["tmp.js"].to_s
40
+
41
+ File.unlink(filename)
42
+ assert_nil @env2["tmp.js"]
43
+ end
44
+ end
45
+
46
+ test "stale cached asset isn't loaded if depedency is changed and removed" do
47
+ foo = fixture_path("default/foo-tmp.js")
48
+ bar = fixture_path("default/bar-tmp.js")
49
+
50
+ sandbox foo, bar do
51
+ File.open(foo, 'w') { |f| f.puts "//= require bar-tmp\nfoo;" }
52
+ File.open(bar, 'w') { |f| f.puts "bar;" }
53
+ assert_equal "bar;\nfoo;\n", @env1["foo-tmp.js"].to_s
54
+ assert_equal "bar;\n", @env1["bar-tmp.js"].to_s
55
+
56
+ File.open(foo, 'w') { |f| f.puts "foo;" }
57
+ File.unlink(bar)
58
+ assert_equal "foo;\n", @env1["foo-tmp.js"].to_s
59
+ assert_nil @env2["bar-tmp.js"]
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,115 @@
1
+ require 'sprockets_test'
2
+ require 'tilt'
3
+ require 'yaml'
4
+
5
+ class TestContext < Sprockets::TestCase
6
+ def setup
7
+ @env = Sprockets::Environment.new(".")
8
+ @env.append_path(fixture_path('context'))
9
+ end
10
+
11
+ test "source file properties are exposed in context" do
12
+ json = @env["properties.js"].to_s.chomp.chop
13
+ assert_equal({
14
+ 'pathname' => fixture_path("context/properties.js.erb"),
15
+ '__FILE__' => fixture_path("context/properties.js.erb"),
16
+ 'root_path' => fixture_path("context"),
17
+ 'logical_path' => "properties",
18
+ 'content_type' => "application/javascript"
19
+ }, YAML.load(json))
20
+ end
21
+
22
+ test "extend context" do
23
+ @env.context_class.class_eval do
24
+ def datauri(path)
25
+ require 'base64'
26
+ Base64.encode64(File.open(path, "rb") { |f| f.read })
27
+ end
28
+ end
29
+
30
+ assert_equal ".pow {\n background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZoAAAEsCAMAAADNS4U5AAAAGXRFWHRTb2Z0\n",
31
+ @env["helpers.css"].to_s.lines.to_a[0..1].join
32
+ assert_equal 58240, @env["helpers.css"].length
33
+ end
34
+ end
35
+
36
+ class TestCustomProcessor < Sprockets::TestCase
37
+ def setup
38
+ @env = Sprockets::Environment.new
39
+ @env.append_path(fixture_path('context'))
40
+ end
41
+
42
+ class YamlProcessor < Tilt::Template
43
+ def initialize_engine
44
+ require 'yaml'
45
+ end
46
+
47
+ def prepare
48
+ @manifest = YAML.load(data)
49
+ end
50
+
51
+ def evaluate(context, locals)
52
+ @manifest['require'].each do |logical_path|
53
+ context.require_asset(logical_path)
54
+ end
55
+ ""
56
+ end
57
+ end
58
+
59
+ test "custom processor using Context#require" do
60
+ @env.register_engine :yml, YamlProcessor
61
+
62
+ assert_equal "var Foo = {};\n\nvar Bar = {};\n", @env['application.js'].to_s
63
+ end
64
+
65
+ class DataUriProcessor < Tilt::Template
66
+ def initialize_engine
67
+ require 'base64'
68
+ end
69
+
70
+ def prepare
71
+ end
72
+
73
+ def evaluate(context, locals)
74
+ data.gsub(/url\(\"(.+?)\"\)/) do
75
+ path = context.resolve($1)
76
+ context.depend_on(path)
77
+ data = Base64.encode64(File.open(path, "rb") { |f| f.read })
78
+ "url(data:image/png;base64,#{data})"
79
+ end
80
+ end
81
+ end
82
+
83
+ test "custom processor using Context#resolve and Context#depend_on" do
84
+ @env.register_engine :embed, DataUriProcessor
85
+
86
+ assert_equal ".pow {\n background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZoAAAEsCAMAAADNS4U5AAAAGXRFWHRTb2Z0\n",
87
+ @env["sprite.css"].to_s.lines.to_a[0..1].join
88
+ assert_equal 58240, @env["sprite.css"].length
89
+ end
90
+
91
+ test "block custom processor" do
92
+ require 'base64'
93
+
94
+ @env.register_preprocessor 'text/css', :data_uris do |context, data|
95
+ data.gsub(/url\(\"(.+?)\"\)/) do
96
+ path = context.resolve($1)
97
+ context.depend_on(path)
98
+ data = Base64.encode64(File.open(path, "rb") { |f| f.read })
99
+ "url(data:image/png;base64,#{data})"
100
+ end
101
+ end
102
+
103
+ assert_equal ".pow {\n background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZoAAAEsCAMAAADNS4U5AAAAGXRFWHRTb2Z0\n",
104
+ @env["sprite.css.embed"].to_s.lines.to_a[0..1].join
105
+ assert_equal 58240, @env["sprite.css.embed"].length
106
+ end
107
+
108
+ test "resolve with content type" do
109
+ assert_equal [fixture_path("context/foo.js"),
110
+ fixture_path("context/foo.js"),
111
+ fixture_path("context/foo.js"),
112
+ "foo.js is 'application/javascript', not 'text/css';"
113
+ ].join(",\n"), @env["resolve_content_type.js"].to_s.strip
114
+ end
115
+ end
@@ -0,0 +1,124 @@
1
+ require "sprockets_test"
2
+
3
+ class DirectiveProcessorTest < Sprockets::TestCase
4
+ test "parsing double-slash comments" do
5
+ directive_parser("double_slash").tap do |parser|
6
+ assert_equal "// Header\n//\n//\n(function() {\n})();\n", parser.processed_source
7
+ assert_equal directives, parser.directives
8
+ end
9
+ end
10
+
11
+ test "parsing hash comments" do
12
+ directive_parser("hash").tap do |parser|
13
+ assert_equal "# Header\n#\n#\n(->)()\n", parser.processed_source
14
+ assert_equal directives, parser.directives
15
+ end
16
+ end
17
+
18
+ test "parsing slash-star comments" do
19
+ directive_parser("slash_star").tap do |parser|
20
+ assert_equal "/* Header\n *\n *\n */\n\n(function() {\n})();\n", parser.processed_source
21
+ assert_equal directives, parser.directives
22
+ end
23
+ end
24
+
25
+ test "parsing single line slash-star comments" do
26
+ directive_parser("slash_star_single").tap do |parser|
27
+ assert_equal "\n\n(function() {\n})();\n", parser.processed_source
28
+ assert_equal [[1, "require", "a"]], parser.directives
29
+ end
30
+ end
31
+
32
+ test "parsing triple-hash comments" do
33
+ directive_parser("triple_hash").tap do |parser|
34
+ assert_equal "###\nHeader\n\n\n###\n\n(->)()\n", parser.processed_source
35
+ assert_equal directives(1), parser.directives
36
+ end
37
+ end
38
+
39
+ test "header comment without directives is unmodified" do
40
+ directive_parser("comment_without_directives").tap do |parser|
41
+ assert_equal "/*\n * Comment\n */\n\n(function() {\n})();\n", parser.processed_source
42
+ assert_equal [], parser.directives
43
+ end
44
+ end
45
+
46
+ test "directives in comment after header are not parsed" do
47
+ directive_parser("directives_after_header").tap do |parser|
48
+ assert_equal "/*\n * Header\n */\n\n\n\n/* Not a directive */\n\n(function() {\n})();\n\n/*= require e */\n", parser.processed_source
49
+ assert_equal [
50
+ [3, "require", "a"],
51
+ [6, "require", "b"],
52
+ [7, "require", "c"],
53
+ [9, "require", "d"]
54
+ ], parser.directives
55
+ end
56
+ end
57
+
58
+ test "headers must occur at the beginning of the file" do
59
+ directive_parser("code_before_comment").tap do |parser|
60
+ assert_equal "", parser.processed_header
61
+ assert_equal directive_fixture("code_before_comment"), parser.processed_source
62
+ end
63
+ end
64
+
65
+ test "no header" do
66
+ directive_parser("no_header").tap do |parser|
67
+ assert_equal directive_fixture("no_header"), parser.processed_source
68
+ assert_equal [], parser.directives
69
+ end
70
+ end
71
+
72
+ test "directive word splitting" do
73
+ directive_parser("directive_word_splitting").tap do |parser|
74
+ assert_equal [
75
+ [1, "one"],
76
+ [2, "one", "two"],
77
+ [3, "one", "two", "three"],
78
+ [4, "one", "two three"],
79
+ [6, "six", "seven"]
80
+ ], parser.directives
81
+ end
82
+ end
83
+
84
+ test "space between = and directive word" do
85
+ directive_parser("space_between_directive_word").tap do |parser|
86
+ assert_equal "var foo;\n", parser.processed_source
87
+ assert_equal [[1, "require", "foo"]], parser.directives
88
+ end
89
+ end
90
+
91
+ def directive_parser(fixture_name)
92
+ Sprockets::DirectiveProcessor.new(fixture_path("directives/#{fixture_name}"))
93
+ end
94
+
95
+ def directive_fixture(name)
96
+ fixture("directives/#{name}")
97
+ end
98
+
99
+ def directives(offset = 0)
100
+ [[3 + offset, "require", "a"], [4 + offset, "require", "b"], [6 + offset, "require", "c"]]
101
+ end
102
+ end
103
+
104
+ class TestCustomDirectiveProcessor < Sprockets::TestCase
105
+ def setup
106
+ @env = Sprockets::Environment.new
107
+ @env.append_path(fixture_path('context'))
108
+ end
109
+
110
+ class TestDirectiveProcessor < Sprockets::DirectiveProcessor
111
+ def process_require_glob_directive(glob)
112
+ Dir["#{pathname.dirname}/#{glob}"].sort.each do |filename|
113
+ context.require_asset(filename)
114
+ end
115
+ end
116
+ end
117
+
118
+ test "custom processor using Context#sprockets_resolve and Context#sprockets_depend" do
119
+ @env.unregister_preprocessor('application/javascript', Sprockets::DirectiveProcessor)
120
+ @env.register_preprocessor('application/javascript', TestDirectiveProcessor)
121
+
122
+ assert_equal "var Foo = {};\n\n", @env["require_glob.js"].to_s
123
+ end
124
+ end
@@ -0,0 +1,65 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "sprockets_test"
3
+
4
+ class EncodingTest < Sprockets::TestCase
5
+ def setup
6
+ @env = Sprockets::Environment.new
7
+ @env.append_path(fixture_path('encoding'))
8
+ end
9
+
10
+ if "".respond_to?(:encoding)
11
+ test "read ASCII asset" do
12
+ data = @env['ascii.js'].to_s
13
+ assert_equal "var foo = \"bar\";\n", data
14
+ assert_equal Encoding.find('ASCII'), data.encoding
15
+ end
16
+
17
+ test "read UTF-8 asset" do
18
+ data = @env['utf8.js'].to_s
19
+ assert_equal "var snowman = \"☃\";\n", data
20
+ assert_equal Encoding.find('UTF-8'), data.encoding
21
+ end
22
+
23
+ test "read UTF-8 asset with BOM" do
24
+ data = @env['utf8_bom.js'].to_s
25
+ assert_equal "var snowman = \"☃\";\n", data.encode("UTF-8")
26
+ assert_equal Encoding.find('UTF-8'), data.encoding
27
+ end
28
+
29
+ test "read UTF-16 asset" do
30
+ assert_raise Sprockets::EncodingError do
31
+ @env['utf16.js'].to_s
32
+ end
33
+ end
34
+
35
+ test "read ASCII + UTF-8 concatation asset" do
36
+ data = @env['ascii_utf8.js'].to_s
37
+ assert_equal "var foo = \"bar\";\nvar snowman = \"\342\230\203\";\n",
38
+ data
39
+ assert_equal Encoding.find('UTF-8'), data.encoding
40
+ end
41
+ else
42
+ test "read ASCII asset" do
43
+ assert_equal "var foo = \"bar\";\n", @env['ascii.js'].to_s
44
+ end
45
+
46
+ test "read UTF-8 asset" do
47
+ assert_equal "var snowman = \"\342\230\203\";\n", @env['utf8.js'].to_s
48
+ end
49
+
50
+ test "read UTF-8 asset with BOM" do
51
+ assert_equal "var snowman = \"\342\230\203\";\n", @env['utf8_bom.js'].to_s
52
+ end
53
+
54
+ test "read UTF-16 asset" do
55
+ assert_raise Sprockets::EncodingError do
56
+ @env['utf16.js'].to_s
57
+ end
58
+ end
59
+
60
+ test "read ASCII + UTF-8 concatation asset" do
61
+ assert_equal "var foo = \"bar\";\nvar snowman = \"\342\230\203\";\n",
62
+ @env['ascii_utf8.js'].to_s
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,73 @@
1
+ require 'sprockets_test'
2
+ require 'sprockets/engines'
3
+ require 'tilt'
4
+
5
+ class AlertTemplate < Tilt::Template
6
+ def self.default_mime_type
7
+ 'application/javascript'
8
+ end
9
+
10
+ def prepare
11
+ end
12
+
13
+ def evaluate(scope, locals, &block)
14
+ "alert(#{data.inspect});"
15
+ end
16
+ end
17
+
18
+ class StringTemplate < Tilt::Template
19
+ def prepare
20
+ end
21
+
22
+ def evaluate(scope, locals, &block)
23
+ data.gsub(/#\{.*?\}/, "moo")
24
+ end
25
+ end
26
+
27
+ class TestEngines < Sprockets::TestCase
28
+ ORIGINAL_ENGINES = Sprockets.instance_variable_get(:@engines)
29
+
30
+ def setup
31
+ Sprockets.instance_variable_set(:@engines, ORIGINAL_ENGINES.dup)
32
+ end
33
+
34
+ def teardown
35
+ Sprockets.instance_variable_set(:@engines, ORIGINAL_ENGINES)
36
+ end
37
+
38
+ test "registering a global engine" do
39
+ Sprockets.register_engine ".alert", AlertTemplate
40
+ assert_equal AlertTemplate, Sprockets.engines("alert")
41
+ assert_equal AlertTemplate, Sprockets.engines(".alert")
42
+
43
+ env = new_environment
44
+ asset = env["hello.alert"]
45
+ assert_equal 'alert("Hello world!\n");', asset.to_s
46
+ assert_equal 'application/javascript', asset.content_type
47
+ end
48
+
49
+ test "overriding an engine globally" do
50
+ env1 = new_environment
51
+ assert_equal %(console.log("Moo, #{RUBY_VERSION}");\n), env1["moo.js"].to_s
52
+
53
+ Sprockets.register_engine ".str", StringTemplate
54
+ env2 = new_environment
55
+ assert_equal %(console.log("Moo, moo");\n), env2["moo.js"].to_s
56
+ end
57
+
58
+ test "overriding an engine in an environment" do
59
+ env1 = new_environment
60
+ env2 = new_environment
61
+
62
+ env1.register_engine ".str", StringTemplate
63
+ assert_equal %(console.log("Moo, moo");\n), env1["moo.js"].to_s
64
+
65
+ assert_equal %(console.log("Moo, #{RUBY_VERSION}");\n), env2["moo.js"].to_s
66
+ end
67
+
68
+ def new_environment
69
+ Sprockets::Environment.new.tap do |env|
70
+ env.append_path(fixture_path('engines'))
71
+ end
72
+ end
73
+ end