bpm 0.1.4 → 1.0.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (341) hide show
  1. data/CHANGELOG.md +20 -0
  2. data/README.md +1 -1
  3. data/TODO.md +90 -2
  4. data/bpm.gemspec +3 -3
  5. data/lib/bpm/cli/base.rb +103 -52
  6. data/lib/bpm/errors.rb +51 -0
  7. data/lib/bpm/init_generator.rb +1 -8
  8. data/lib/bpm/libgems_ext/libgems.rb +9 -0
  9. data/lib/bpm/local.rb +6 -11
  10. data/lib/bpm/package.rb +272 -178
  11. data/lib/bpm/pipeline/generated_asset.rb +88 -28
  12. data/lib/bpm/pipeline/plugin_asset.rb +8 -2
  13. data/lib/bpm/pipeline/source_url_processor.rb +16 -0
  14. data/lib/bpm/pipeline/transport_processor.rb +5 -3
  15. data/lib/bpm/pipeline.rb +33 -23
  16. data/lib/bpm/project.rb +492 -167
  17. data/lib/bpm/project_generator.rb +14 -1
  18. data/lib/bpm/remote.rb +6 -4
  19. data/lib/bpm/server.rb +4 -15
  20. data/lib/bpm/version.rb +2 -1
  21. data/lib/bpm.rb +2 -0
  22. data/man/bpm-add.1.ronn +22 -0
  23. data/man/bpm-build.1.ronn +22 -0
  24. data/man/bpm-compile.1.ronn +23 -0
  25. data/man/bpm-config.7.ronn +21 -0
  26. data/man/bpm-fetch.1.ronn +22 -0
  27. data/man/bpm-fetched.1.ronn +22 -0
  28. data/man/bpm-init.1.ronn +22 -0
  29. data/man/bpm-list.1.ronn +22 -0
  30. data/man/bpm-login.1.ronn +22 -0
  31. data/man/bpm-new.1.ronn +22 -0
  32. data/man/bpm-owner.1.ronn +22 -0
  33. data/man/bpm-preview.1.ronn +22 -0
  34. data/man/bpm-push.1.ronn +22 -0
  35. data/man/bpm-remove.1.ronn +22 -0
  36. data/man/bpm-unpack.1.ronn +22 -0
  37. data/man/bpm-yank.1.ronn +22 -0
  38. data/man/bpm.1.ronn +31 -0
  39. data/spec/cli/add_spec.rb +26 -7
  40. data/spec/cli/fetch_spec.rb +15 -6
  41. data/spec/cli/init_spec.rb +165 -25
  42. data/spec/cli/{build_spec.rb → pack_spec.rb} +9 -10
  43. data/spec/cli/push_spec.rb +4 -4
  44. data/spec/cli/rebuild_spec.rb +181 -0
  45. data/spec/cli/remove_spec.rb +3 -4
  46. data/spec/cli/unpack_spec.rb +6 -6
  47. data/spec/fixtures/gems/core-test-0.4.9.bpkg +0 -0
  48. data/spec/fixtures/{core-test-0.4.9.bpkg → gems/uglify-js-1.0.4.bpkg} +0 -0
  49. data/spec/fixtures/packages/core-test/extras/extra_file.html +3 -0
  50. data/spec/fixtures/packages/core-test/index.html +3 -0
  51. data/spec/fixtures/{core-test → packages/core-test}/package.json +9 -3
  52. data/spec/fixtures/packages/invalid_json/package.json +3 -0
  53. data/spec/fixtures/packages/uglify-js/README.html +825 -0
  54. data/spec/fixtures/packages/uglify-js/README.org +431 -0
  55. data/spec/fixtures/packages/uglify-js/bin/uglifyjs +305 -0
  56. data/spec/fixtures/packages/uglify-js/docstyle.css +75 -0
  57. data/spec/fixtures/packages/uglify-js/lib/parse-js.js +1 -0
  58. data/spec/fixtures/packages/uglify-js/lib/process.js +1 -0
  59. data/spec/fixtures/packages/uglify-js/lib/squeeze-more.js +1 -0
  60. data/spec/fixtures/packages/uglify-js/package.json +27 -0
  61. data/spec/fixtures/packages/uglify-js/plugins/minifier.js +6 -0
  62. data/spec/fixtures/packages/uglify-js/uglify-js.js +17 -0
  63. data/spec/fixtures/projects/hello2/README.md +21 -0
  64. data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_packages.js +6 -1
  65. data/{templates/init → spec/fixtures/projects/hello2}/assets/bpm_styles.css +1 -1
  66. data/spec/fixtures/projects/hello2/hello2.json +16 -0
  67. data/spec/fixtures/projects/hello2/index.html +13 -0
  68. data/spec/fixtures/projects/hello2/packages/a/lib/main.js +2 -0
  69. data/spec/fixtures/projects/hello2/packages/a/package.json +17 -0
  70. data/spec/fixtures/projects/hello2/packages/b/lib/main.js +2 -0
  71. data/spec/fixtures/projects/hello2/packages/b/package.json +17 -0
  72. data/spec/fixtures/projects/hello2/packages/c/lib/main.js +2 -0
  73. data/spec/fixtures/projects/hello2/packages/c/package.json +16 -0
  74. data/spec/fixtures/projects/hello_dev/LICENSE +19 -0
  75. data/spec/fixtures/projects/hello_dev/README.md +21 -0
  76. data/spec/fixtures/projects/hello_dev/app/main.js +6 -0
  77. data/spec/fixtures/projects/hello_dev/assets/bpm_libs.js +5 -0
  78. data/spec/fixtures/projects/hello_dev/assets/bpm_styles.css +6 -0
  79. data/spec/fixtures/projects/hello_dev/css/main.css +1 -0
  80. data/spec/fixtures/projects/hello_dev/hello_dev.json +25 -0
  81. data/spec/fixtures/projects/hello_dev/index.html +14 -0
  82. data/spec/fixtures/projects/hello_dev/packages/style_package/css/some_style.css +3 -0
  83. data/spec/fixtures/{minitest/minitest.json → projects/hello_dev/packages/style_package/package.json} +5 -9
  84. data/spec/fixtures/projects/hello_world/LICENSE +19 -0
  85. data/spec/fixtures/projects/hello_world/assets/bpm_packages.js +1 -0
  86. data/spec/fixtures/projects/hello_world/assets/bpm_styles.css +1 -0
  87. data/spec/fixtures/projects/hello_world/custom_dir/custom.js +1 -0
  88. data/spec/fixtures/projects/hello_world/hello_world.json +41 -0
  89. data/spec/fixtures/projects/hello_world/lib/another.js +1 -0
  90. data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/package.json +5 -2
  91. data/spec/fixtures/projects/hello_world/vendor/lib/something.js +1 -0
  92. data/spec/fixtures/projects/init_app/assets/bpm_libs.js +6 -0
  93. data/spec/fixtures/projects/init_app/assets/bpm_styles.css +5 -0
  94. data/spec/fixtures/projects/init_app/assets/new_project/bpm_libs.js +6 -0
  95. data/spec/fixtures/projects/init_app/assets/new_project/bpm_styles.css +5 -0
  96. data/spec/fixtures/projects/init_app/new_project.json +27 -0
  97. data/spec/fixtures/projects/init_default/assets/bpm_libs.js +6 -0
  98. data/spec/fixtures/projects/init_default/assets/bpm_styles.css +5 -0
  99. data/spec/fixtures/projects/init_default/new_project.json +15 -0
  100. data/spec/fixtures/projects/minitest/minitest.json +26 -0
  101. data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/package.json +1 -1
  102. data/spec/fixtures/projects/needs_rake/needs_rake.json +7 -0
  103. data/spec/fixtures/{transporter → projects/transporter}/packages/transport/package.json +1 -1
  104. data/spec/package_spec.rb +343 -315
  105. data/spec/pipeline_spec.rb +89 -71
  106. data/spec/plugins/minifier_spec.rb +25 -16
  107. data/spec/plugins/transport_spec.rb +1 -1
  108. data/spec/project_spec.rb +97 -34
  109. data/spec/spec_helper.rb +41 -0
  110. data/spec/support/fake_gem_server.rb +8 -4
  111. data/spec/support/path.rb +8 -0
  112. data/spec/support/project.rb +50 -17
  113. data/templates/init/project.json +12 -14
  114. data/templates/project/LICENSE +1 -1
  115. data/templates/project/app/main.js +6 -0
  116. data/templates/project/css/main.css +1 -0
  117. data/templates/project/index.html +4 -3
  118. data/vendor/sprockets/.travis.yml +3 -2
  119. data/vendor/sprockets/Gemfile +0 -6
  120. data/vendor/sprockets/lib/sprockets/asset.rb +7 -12
  121. data/vendor/sprockets/lib/sprockets/asset_attributes.rb +70 -53
  122. data/vendor/sprockets/lib/sprockets/base.rb +1 -14
  123. data/vendor/sprockets/lib/sprockets/bundled_asset.rb +72 -45
  124. data/vendor/sprockets/lib/sprockets/caching.rb +28 -23
  125. data/vendor/sprockets/lib/sprockets/context.rb +56 -26
  126. data/vendor/sprockets/lib/sprockets/directive_processor.rb +21 -4
  127. data/vendor/sprockets/lib/sprockets/eco_template.rb +3 -4
  128. data/vendor/sprockets/lib/sprockets/ejs_template.rb +3 -4
  129. data/vendor/sprockets/lib/sprockets/engines.rb +26 -1
  130. data/vendor/sprockets/lib/sprockets/environment.rb +2 -1
  131. data/vendor/sprockets/lib/sprockets/index.rb +1 -0
  132. data/vendor/sprockets/lib/sprockets/mime.rb +38 -0
  133. data/vendor/sprockets/lib/sprockets/processing.rb +4 -45
  134. data/vendor/sprockets/lib/sprockets/static_asset.rb +5 -6
  135. data/vendor/sprockets/lib/sprockets/static_compilation.rb +4 -12
  136. data/vendor/sprockets/lib/sprockets/trail.rb +2 -1
  137. data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
  138. data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +3 -0
  139. data/vendor/sprockets/test/test_asset.rb +121 -15
  140. data/vendor/sprockets/test/test_asset_attributes.rb +85 -21
  141. data/vendor/sprockets/test/test_environment.rb +13 -36
  142. metadata +564 -444
  143. data/spec/cli/new_spec.rb +0 -118
  144. data/spec/fixtures/hello_world/assets/bpm_packages.js +0 -13
  145. data/spec/fixtures/hello_world/assets/bpm_styles.css +0 -14
  146. data/spec/fixtures/hello_world/hello_world.json +0 -20
  147. /data/spec/fixtures/{badrake-0.8.7.bpkg → gems/badrake-0.8.7.bpkg} +0 -0
  148. /data/spec/fixtures/{builder-3.0.0.bpkg → gems/builder-3.0.0.bpkg} +0 -0
  149. /data/spec/fixtures/{bundler-1.1.pre.bpkg → gems/bundler-1.1.pre.bpkg} +0 -0
  150. /data/spec/fixtures/{coffee-1.0.1.pre.bpkg → gems/coffee-1.0.1.pre.bpkg} +0 -0
  151. /data/spec/fixtures/{custom_generator-1.0.bpkg → gems/custom_generator-1.0.bpkg} +0 -0
  152. /data/spec/fixtures/{highline-1.6.1.bpkg → gems/highline-1.6.1.bpkg} +0 -0
  153. /data/spec/fixtures/{ivory-0.0.1.bpkg → gems/ivory-0.0.1.bpkg} +0 -0
  154. /data/spec/fixtures/{jquery-1.4.3.bpkg → gems/jquery-1.4.3.bpkg} +0 -0
  155. /data/spec/fixtures/{optparse-1.0.1.bpkg → gems/optparse-1.0.1.bpkg} +0 -0
  156. /data/spec/fixtures/{rake-0.8.6.bpkg → gems/rake-0.8.6.bpkg} +0 -0
  157. /data/spec/fixtures/{rake-0.8.7.bpkg → gems/rake-0.8.7.bpkg} +0 -0
  158. /data/spec/fixtures/{spade-0.5.0.bpkg → gems/spade-0.5.0.bpkg} +0 -0
  159. /data/spec/fixtures/{src → packages}/README.txt +0 -0
  160. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/.gitignore +0 -0
  161. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/CHANGELOG.md +0 -0
  162. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/ISSUES.md +0 -0
  163. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/LICENSE +0 -0
  164. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/README.md +0 -0
  165. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/UPGRADING.md +0 -0
  166. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/bin/bundle +0 -0
  167. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/definition.js +0 -0
  168. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dependency.js +0 -0
  169. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/dsl.js +0 -0
  170. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler/ui.js +0 -0
  171. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/lib/bundler.js +0 -0
  172. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-config.ronn +0 -0
  173. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-exec.ronn +0 -0
  174. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-install.ronn +0 -0
  175. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-package.ronn +0 -0
  176. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle-update.ronn +0 -0
  177. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/bundle.ronn +0 -0
  178. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/gemfile.5.ronn +0 -0
  179. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/man/index.txt +0 -0
  180. /data/spec/fixtures/{src → packages}/bundler-1.1.pre/package.json +0 -0
  181. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/cake +0 -0
  182. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/bin/coffee +0 -0
  183. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/base.js +0 -0
  184. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee/mocha/chai.js +0 -0
  185. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/lib/coffee.js +0 -0
  186. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/package.json +0 -0
  187. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/coffee/test.js +0 -0
  188. /data/spec/fixtures/{src → packages}/coffee-1.0.1.pre/qunit/test.js +0 -0
  189. /data/spec/fixtures/{core-test → packages/core-test}/bin/cot +0 -0
  190. /data/spec/fixtures/{core-test → packages/core-test}/lib/main.js +0 -0
  191. /data/spec/fixtures/{core-test → packages/core-test}/resources/runner.css +0 -0
  192. /data/spec/fixtures/{core-test → packages/core-test}/tests/test.js +0 -0
  193. /data/spec/fixtures/{custom_generator → packages/custom_generator}/lib/main.js +0 -0
  194. /data/spec/fixtures/{custom_generator → packages/custom_generator}/package.json +0 -0
  195. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/init/project.json +0 -0
  196. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/app.js +0 -0
  197. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project/lib/main.js +0 -0
  198. /data/spec/fixtures/{custom_generator → packages/custom_generator}/templates/project_generator.rb +0 -0
  199. /data/spec/fixtures/{src → packages}/jquery/lib/main.js +0 -0
  200. /data/spec/fixtures/{src → packages}/jquery/package.json +0 -0
  201. /data/spec/fixtures/{src → packages}/rake-0.8.6/CHANGES +0 -0
  202. /data/spec/fixtures/{src → packages}/rake-0.8.6/MIT-LICENSE +0 -0
  203. /data/spec/fixtures/{src → packages}/rake-0.8.6/README +0 -0
  204. /data/spec/fixtures/{src → packages}/rake-0.8.6/Rakefile +0 -0
  205. /data/spec/fixtures/{src → packages}/rake-0.8.6/TODO +0 -0
  206. /data/spec/fixtures/{src → packages}/rake-0.8.6/bin/rake +0 -0
  207. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/command_line_usage.rdoc +0 -0
  208. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile1 +0 -0
  209. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/Rakefile2 +0 -0
  210. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/a.c +0 -0
  211. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/b.c +0 -0
  212. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/example/main.c +0 -0
  213. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/glossary.rdoc +0 -0
  214. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/jamis.rb +0 -0
  215. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/proto_rake.rdoc +0 -0
  216. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rake.1.gz +0 -0
  217. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rakefile.rdoc +0 -0
  218. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/rational.rdoc +0 -0
  219. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.14.rdoc +0 -0
  220. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.4.15.rdoc +0 -0
  221. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.0.rdoc +0 -0
  222. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.3.rdoc +0 -0
  223. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.5.4.rdoc +0 -0
  224. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.6.0.rdoc +0 -0
  225. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.0.rdoc +0 -0
  226. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.1.rdoc +0 -0
  227. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.2.rdoc +0 -0
  228. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.7.3.rdoc +0 -0
  229. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.0.rdoc +0 -0
  230. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.2.rdoc +0 -0
  231. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.3.rdoc +0 -0
  232. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.4.rdoc +0 -0
  233. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.5.rdoc +0 -0
  234. /data/spec/fixtures/{src → packages}/rake-0.8.6/doc/release_notes/rake-0.8.6.rdoc +0 -0
  235. /data/spec/fixtures/{src → packages}/rake-0.8.6/install.rb +0 -0
  236. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/alt_system.rb +0 -0
  237. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/classic_namespace.rb +0 -0
  238. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/clean.rb +0 -0
  239. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/compositepublisher.rb +0 -0
  240. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/ftptools.rb +0 -0
  241. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/publisher.rb +0 -0
  242. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/rubyforgepublisher.rb +0 -0
  243. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sshpublisher.rb +0 -0
  244. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/contrib/sys.rb +0 -0
  245. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/gempackagetask.rb +0 -0
  246. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/loaders/makefile.rb +0 -0
  247. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/packagetask.rb +0 -0
  248. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rake_test_loader.rb +0 -0
  249. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/rdoctask.rb +0 -0
  250. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/ruby182_test_unit_fix.rb +0 -0
  251. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/runtest.rb +0 -0
  252. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/tasklib.rb +0 -0
  253. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/testtask.rb +0 -0
  254. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake/win32.rb +0 -0
  255. /data/spec/fixtures/{src → packages}/rake-0.8.6/lib/rake.rb +0 -0
  256. /data/spec/fixtures/{src → packages}/rake-0.8.6/package.json +0 -0
  257. /data/spec/fixtures/{src → packages}/rake-0.8.6/test/capture_stdout.rb +0 -0
  258. /data/spec/fixtures/{src → packages}/rake-0.8.7/CHANGES +0 -0
  259. /data/spec/fixtures/{src → packages}/rake-0.8.7/MIT-LICENSE +0 -0
  260. /data/spec/fixtures/{src → packages}/rake-0.8.7/README +0 -0
  261. /data/spec/fixtures/{src → packages}/rake-0.8.7/Rakefile +0 -0
  262. /data/spec/fixtures/{src → packages}/rake-0.8.7/TODO +0 -0
  263. /data/spec/fixtures/{src → packages}/rake-0.8.7/bin/rake +0 -0
  264. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/command_line_usage.rdoc +0 -0
  265. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile1 +0 -0
  266. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/Rakefile2 +0 -0
  267. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/a.c +0 -0
  268. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/b.c +0 -0
  269. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/example/main.c +0 -0
  270. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/glossary.rdoc +0 -0
  271. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/jamis.rb +0 -0
  272. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/proto_rake.rdoc +0 -0
  273. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rake.1.gz +0 -0
  274. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rakefile.rdoc +0 -0
  275. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/rational.rdoc +0 -0
  276. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.14.rdoc +0 -0
  277. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.4.15.rdoc +0 -0
  278. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.0.rdoc +0 -0
  279. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.3.rdoc +0 -0
  280. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.5.4.rdoc +0 -0
  281. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.6.0.rdoc +0 -0
  282. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.0.rdoc +0 -0
  283. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.1.rdoc +0 -0
  284. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.2.rdoc +0 -0
  285. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.7.3.rdoc +0 -0
  286. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.0.rdoc +0 -0
  287. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.2.rdoc +0 -0
  288. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.3.rdoc +0 -0
  289. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.4.rdoc +0 -0
  290. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.5.rdoc +0 -0
  291. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.6.rdoc +0 -0
  292. /data/spec/fixtures/{src → packages}/rake-0.8.7/doc/release_notes/rake-0.8.7.rdoc +0 -0
  293. /data/spec/fixtures/{src → packages}/rake-0.8.7/install.rb +0 -0
  294. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/alt_system.rb +0 -0
  295. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/classic_namespace.rb +0 -0
  296. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/clean.rb +0 -0
  297. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/compositepublisher.rb +0 -0
  298. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/ftptools.rb +0 -0
  299. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/publisher.rb +0 -0
  300. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/rubyforgepublisher.rb +0 -0
  301. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sshpublisher.rb +0 -0
  302. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/contrib/sys.rb +0 -0
  303. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/gempackagetask.rb +0 -0
  304. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/loaders/makefile.rb +0 -0
  305. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/packagetask.rb +0 -0
  306. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rake_test_loader.rb +0 -0
  307. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/rdoctask.rb +0 -0
  308. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/ruby182_test_unit_fix.rb +0 -0
  309. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/runtest.rb +0 -0
  310. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/tasklib.rb +0 -0
  311. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/testtask.rb +0 -0
  312. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake/win32.rb +0 -0
  313. /data/spec/fixtures/{src → packages}/rake-0.8.7/lib/rake.rb +0 -0
  314. /data/spec/fixtures/{src → packages}/rake-0.8.7/package.json +0 -0
  315. /data/spec/fixtures/{src → packages}/rake-0.8.7/test/capture_stdout.rb +0 -0
  316. /data/spec/fixtures/{src → packages}/spade/lib/main.js +0 -0
  317. /data/spec/fixtures/{src → packages}/spade/package.json +0 -0
  318. /data/spec/fixtures/{custom_name → projects/custom_name}/MyProject.json +0 -0
  319. /data/spec/fixtures/{hello_world → projects/hello2}/LICENSE +0 -0
  320. /data/{templates/project → spec/fixtures/projects/hello2}/app.js +0 -0
  321. /data/spec/fixtures/{hello_world → projects/hello_world}/README.md +0 -0
  322. /data/spec/fixtures/{hello_world → projects/hello_world}/assets/papa-smurf.jpg +0 -0
  323. /data/spec/fixtures/{hello_world → projects/hello_world}/css/dummy.css +0 -0
  324. /data/spec/fixtures/{hello_world → projects/hello_world}/lib/main.js +0 -0
  325. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/assets/dummy.txt +0 -0
  326. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/css/sample_styles.css +0 -0
  327. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/custom_dir/basic-module.js +0 -0
  328. /data/spec/fixtures/{hello_world → projects/hello_world}/packages/custom_package/lib/main.js +0 -0
  329. /data/spec/fixtures/{hello_world → projects/hello_world}/tests/main-test.js +0 -0
  330. /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_packages.js +0 -0
  331. /data/spec/fixtures/{minitest → projects/minitest}/assets/bpm_styles.css +0 -0
  332. /data/spec/fixtures/{minitest → projects/minitest}/assets/minitest/app_package.js +0 -0
  333. /data/spec/fixtures/{minitest → projects/minitest}/lib/main.js +0 -0
  334. /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/lib/main.js +0 -0
  335. /data/spec/fixtures/{minitest → projects/minitest}/packages/uglyduck/minifier/main.js +0 -0
  336. /data/spec/fixtures/{simple_hello/assets/bpm_packages.js → projects/simple_hello/assets/bpm_libs.js} +0 -0
  337. /data/spec/fixtures/{simple_hello → projects/simple_hello}/lib/main.js +0 -0
  338. /data/spec/fixtures/{transporter → projects/transporter}/lib/main.js +0 -0
  339. /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/lib/main.js +0 -0
  340. /data/spec/fixtures/{transporter → projects/transporter}/packages/transport/transports/wrapper.js +0 -0
  341. /data/spec/fixtures/{transporter → projects/transporter}/transporter.json +0 -0
@@ -8,6 +8,11 @@ module Sprockets
8
8
  # `BundledAsset`s are used for files that need to be processed and
9
9
  # concatenated with other assets. Use for `.js` and `.css` files.
10
10
  class BundledAsset < Asset
11
+ # Define extra attributes to be serialized.
12
+ def self.serialized_attributes
13
+ super + %w( content_type mtime )
14
+ end
15
+
11
16
  def initialize(environment, logical_path, pathname, options)
12
17
  super(environment, logical_path, pathname)
13
18
  @options = options || {}
@@ -15,21 +20,20 @@ module Sprockets
15
20
 
16
21
  # Initialize `BundledAsset` from serialized `Hash`.
17
22
  def init_with(environment, coder)
18
- super
19
-
20
23
  @options = {}
21
24
 
25
+ super
26
+
22
27
  @body = coder['body']
23
- @source = coder['source']
24
28
  @assets = coder['asset_paths'].map { |p|
25
29
  p = expand_root_path(p)
26
30
  p == pathname.to_s ? self : environment[p, @options]
27
31
  }
28
32
 
29
- @dependency_files = coder['dependency_files'].map { |h|
33
+ @dependency_paths = coder['dependency_paths'].map { |h|
30
34
  h.merge('path' => expand_root_path(h['path']))
31
35
  }
32
- @dependency_files.each do |dep|
36
+ @dependency_paths.each do |dep|
33
37
  dep['mtime'] = Time.parse(dep['mtime']) if dep['mtime'].is_a?(String)
34
38
  end
35
39
  end
@@ -39,9 +43,8 @@ module Sprockets
39
43
  super
40
44
 
41
45
  coder['body'] = body
42
- coder['source'] = to_s
43
46
  coder['asset_paths'] = to_a.map { |a| relativize_root_path(a.pathname) }
44
- coder['dependency_files'] = dependency_files.map { |h|
47
+ coder['dependency_paths'] = dependency_paths.map { |h|
45
48
  h.merge('path' => relativize_root_path(h['path']))
46
49
  }
47
50
  end
@@ -50,22 +53,22 @@ module Sprockets
50
53
  # dependencies but does run any processors or engines on the
51
54
  # original file.
52
55
  def body
53
- @body ||= dependency_context_and_body[1]
56
+ @body ||= build_dependency_context_and_body[1]
54
57
  end
55
58
 
56
59
  # Get latest mtime of all its dependencies.
57
60
  def mtime
58
- @mtime ||= dependency_files.map { |h| h['mtime'] }.max
61
+ @mtime ||= dependency_paths.map { |h| h['mtime'] }.max
59
62
  end
60
63
 
61
64
  # Get size of concatenated source.
62
65
  def length
63
- @length ||= Rack::Utils.bytesize(to_s)
66
+ @length ||= build_source['length']
64
67
  end
65
68
 
66
69
  # Compute digest of concatenated source.
67
70
  def digest
68
- @digest ||= environment.digest.update(to_s).hexdigest
71
+ @digest ||= build_source['digest']
69
72
  end
70
73
 
71
74
  # Return an `Array` of `Asset` files that are declared dependencies.
@@ -75,24 +78,19 @@ module Sprockets
75
78
 
76
79
  # Expand asset into an `Array` of parts.
77
80
  def to_a
78
- @assets ||= compute_assets
81
+ @assets ||= build_dependencies_paths_and_assets[1]
79
82
  end
80
83
 
81
84
  # Checks if Asset is stale by comparing the actual mtime and
82
85
  # digest to the inmemory model.
83
86
  def fresh?
84
- # Check if environment has changed first
85
- if environment.digest.hexdigest != environment_hexdigest
86
- return false
87
- end
88
-
89
87
  # Check freshness of all declared dependencies
90
- dependency_files.all? { |h| dependency_fresh?(h) }
88
+ dependency_paths.all? { |h| dependency_fresh?(h) }
91
89
  end
92
90
 
93
91
  # Return `String` of concatenated source.
94
92
  def to_s
95
- @source ||= build_source
93
+ @source ||= build_source['source']
96
94
  end
97
95
 
98
96
  # Save asset to disk.
@@ -131,24 +129,16 @@ module Sprockets
131
129
  environment.context_class.new(environment, logical_path.to_s, pathname)
132
130
  end
133
131
 
134
- def dependency_context_and_body
135
- @dependency_context_and_body ||= build_dependency_context_and_body
136
- end
137
-
138
132
  # Get `Context` after processors have been ran on it. This
139
133
  # trackes any dependencies that processors have added to it.
140
134
  def dependency_context
141
- dependency_context_and_body[0]
135
+ @dependency_context ||= build_dependency_context_and_body[0]
142
136
  end
143
137
 
144
- # All files that this asset depends on. This list may include
138
+ # All paths that this asset depends on. This list may include
145
139
  # non-assets like directories.
146
- def dependency_files
147
- @dependency_files ||= dependency_context._dependency_paths.to_a.map do |path|
148
- { 'path' => path,
149
- 'mtime' => environment.stat(path).mtime,
150
- 'hexdigest' => environment.file_digest(path).hexdigest }
151
- end
140
+ def dependency_paths
141
+ @dependency_paths ||= build_dependencies_paths_and_assets[0]
152
142
  end
153
143
 
154
144
  private
@@ -174,24 +164,15 @@ module Sprockets
174
164
  # Runs all processors on `Context`
175
165
  body = context.evaluate(pathname, :data => data)
176
166
 
177
- return context, body
178
- end
167
+ @dependency_context, @body = context, body
179
168
 
180
- def build_source
181
- data = ""
182
-
183
- # Explode Asset into parts and gather the dependency bodies
184
- to_a.each { |dependency| data << dependency.body }
185
-
186
- # Run bundle processors on concatenated source
187
- blank_context.evaluate(pathname, :data => data,
188
- :processors => environment.bundle_processors(content_type))
169
+ return context, body
189
170
  end
190
171
 
191
- def compute_assets
172
+ def build_dependencies_paths_and_assets
192
173
  check_circular_dependency!
193
174
 
194
- assets = []
175
+ paths, assets = {}, []
195
176
 
196
177
  # Define an `add_dependency` helper
197
178
  add_dependency = lambda do |asset|
@@ -216,7 +197,53 @@ module Sprockets
216
197
  # Ensure self is added to the dependency list
217
198
  add_dependency.call(self)
218
199
 
219
- assets
200
+ dependency_context._dependency_paths.each do |path|
201
+ paths[path] ||= {
202
+ 'path' => path,
203
+ 'mtime' => environment.stat(path).mtime,
204
+ 'hexdigest' => environment.file_digest(path).hexdigest
205
+ }
206
+ end
207
+
208
+ dependency_context._dependency_assets.each do |path|
209
+ # Skip if depending on self
210
+ next if path == pathname.to_s
211
+
212
+ # Recursively lookup required asset
213
+ environment[path, @options].to_a.each do |asset|
214
+ asset.dependency_paths.each do |dep|
215
+ paths[dep['path']] ||= dep
216
+ end
217
+ end
218
+ end
219
+
220
+ @dependency_paths, @assets = paths.values, assets
221
+
222
+ return @dependency_paths, @assets
223
+ end
224
+
225
+ def build_source
226
+ hash = environment.cache_hash("#{pathname}:source", id) do
227
+ data = ""
228
+
229
+ # Explode Asset into parts and gather the dependency bodies
230
+ to_a.each { |dependency| data << dependency.body }
231
+
232
+ # Run bundle processors on concatenated source
233
+ data = blank_context.evaluate(pathname, :data => data,
234
+ :processors => environment.bundle_processors(content_type))
235
+
236
+ { 'length' => Rack::Utils.bytesize(data),
237
+ 'digest' => environment.digest.update(data).hexdigest,
238
+ 'source' => data }
239
+ end
240
+ hash['length'] = Integer(hash['length']) if hash['length'].is_a?(String)
241
+
242
+ @length = hash['length']
243
+ @digest = hash['digest']
244
+ @source = hash['source']
245
+
246
+ hash
220
247
  end
221
248
  end
222
249
  end
@@ -7,6 +7,7 @@ module Sprockets
7
7
  module Caching
8
8
  # Return `Asset` instance for serialized `Hash`.
9
9
  def asset_from_hash(hash)
10
+ return unless hash.is_a?(Hash)
10
11
  case hash['class']
11
12
  when 'BundledAsset'
12
13
  BundledAsset.from_hash(self, hash)
@@ -17,6 +18,17 @@ module Sprockets
17
18
  end
18
19
  end
19
20
 
21
+ def cache_hash(key, version)
22
+ if cache.nil?
23
+ yield
24
+ elsif hash = cache_get_hash(key, version)
25
+ hash
26
+ elsif hash = yield
27
+ cache_set_hash(key, version, hash)
28
+ hash
29
+ end
30
+ end
31
+
20
32
  protected
21
33
  # Cache helper method. Takes a `path` argument which maybe a
22
34
  # logical path or fully expanded path. The `&block` is passed
@@ -27,18 +39,21 @@ module Sprockets
27
39
  yield
28
40
 
29
41
  # Check cache for `path`
30
- elsif asset = cache_get_asset(path)
42
+ elsif (asset = asset_from_hash(cache_get_hash(path.to_s, digest.hexdigest))) && asset.fresh?
31
43
  asset
32
44
 
33
45
  # Otherwise yield block that slowly finds and builds the asset
34
46
  elsif asset = yield
47
+ hash = {}
48
+ asset.encode_with(hash)
49
+
35
50
  # Save the asset to at its path
36
- cache_set_asset(path.to_s, asset)
51
+ cache_set_hash(path.to_s, digest.hexdigest, hash)
37
52
 
38
53
  # Since path maybe a logical or full pathname, save the
39
54
  # asset its its full path too
40
55
  if path.to_s != asset.pathname.to_s
41
- cache_set_asset(asset.pathname.to_s, asset)
56
+ cache_set_hash(asset.pathname.to_s, digest.hexdigest, hash)
42
57
  end
43
58
 
44
59
  asset
@@ -52,31 +67,21 @@ module Sprockets
52
67
 
53
68
  # Removes `Environment#root` from key and prepends
54
69
  # `Environment#cache_key_namespace`.
55
- def cache_key_for(path)
56
- File.join(cache_key_namespace, path.sub(root, ''))
70
+ def cache_key_for(key)
71
+ File.join(cache_key_namespace, key.sub(root, ''))
57
72
  end
58
73
 
59
- # Gets asset from cache and unserializes it
60
- def cache_get_asset(path)
61
- hash = cache_get(cache_key_for(path))
62
-
63
- if hash.is_a?(Hash)
64
- asset = asset_from_hash(hash)
65
-
66
- if asset.fresh?
67
- asset
68
- end
69
- else
70
- nil
74
+ def cache_get_hash(key, version)
75
+ hash = cache_get(cache_key_for(key))
76
+ if hash.is_a?(Hash) && version == hash['_version']
77
+ hash
71
78
  end
72
79
  end
73
80
 
74
- # Serializes and saves asset to cache
75
- def cache_set_asset(path, asset)
76
- hash = {}
77
- asset.encode_with(hash)
78
- cache_set(cache_key_for(path), hash)
79
- asset
81
+ def cache_set_hash(key, version, hash)
82
+ hash['_version'] = version
83
+ cache_set(cache_key_for(key), hash)
84
+ hash
80
85
  end
81
86
 
82
87
  # Low level cache getter for `key`. Checks a number of supported
@@ -1,3 +1,5 @@
1
+ require 'base64'
2
+ require 'rack/utils'
1
3
  require 'sprockets/errors'
2
4
  require 'sprockets/utils'
3
5
  require 'pathname'
@@ -20,7 +22,7 @@ module Sprockets
20
22
  # assets. See `DirectiveProcessor` for an example of this.
21
23
  class Context
22
24
  attr_reader :environment, :pathname
23
- attr_reader :_required_paths, :_dependency_paths
25
+ attr_reader :_required_paths, :_dependency_paths, :_dependency_assets
24
26
  attr_writer :__LINE__
25
27
 
26
28
  def initialize(environment, logical_path, pathname)
@@ -29,8 +31,9 @@ module Sprockets
29
31
  @pathname = pathname
30
32
  @__LINE__ = nil
31
33
 
32
- @_required_paths = []
33
- @_dependency_paths = Set.new([pathname.to_s])
34
+ @_required_paths = []
35
+ @_dependency_paths = Set.new([pathname.to_s])
36
+ @_dependency_assets = Set.new
34
37
  end
35
38
 
36
39
  # Returns the environment path that contains the file.
@@ -108,6 +111,44 @@ module Sprockets
108
111
  # source file.
109
112
  def depend_on(path)
110
113
  @_dependency_paths << resolve(path).to_s
114
+ nil
115
+ end
116
+
117
+ # `depend_on_asset` allows you to state an asset dependency
118
+ # without including it.
119
+ #
120
+ # This is used for caching purposes. Any changes that would
121
+ # invalidate the dependency asset will invalidate the source
122
+ # file. Unlike `depend_on`, this will include recursively include
123
+ # the target asset's dependencies.
124
+ def depend_on_asset(path)
125
+ filename = resolve(path).to_s
126
+ @_dependency_assets << filename
127
+ nil
128
+ end
129
+
130
+ # `require_asset` declares `path` as a dependency of the file. The
131
+ # dependency will be inserted before the file and will only be
132
+ # included once.
133
+ #
134
+ # If ERB processing is enabled, you can use it to dynamically
135
+ # require assets.
136
+ #
137
+ # <%= require_asset "#{framework}.js" %>
138
+ #
139
+ def require_asset(path)
140
+ pathname = resolve(path, :content_type => :self)
141
+ depend_on_asset(pathname)
142
+ @_required_paths << pathname.to_s
143
+ nil
144
+ end
145
+
146
+ # Tests if target path is able to be safely required into the
147
+ # current concatenation.
148
+ def asset_requirable?(path)
149
+ pathname = resolve(path)
150
+ content_type = environment.content_type_of(pathname)
151
+ pathname.file? && (self.content_type.nil? || self.content_type == content_type)
111
152
  end
112
153
 
113
154
  # Reads `path` and runs processors on the file.
@@ -145,32 +186,21 @@ module Sprockets
145
186
  result
146
187
  end
147
188
 
148
- # Tests if target path is able to be safely required into the
149
- # current concatenation.
150
- def asset_requirable?(path)
151
- pathname = resolve(path)
152
- content_type = environment.content_type_of(pathname)
153
- pathname.file? && (self.content_type.nil? || self.content_type == content_type)
154
- end
155
-
156
- # `require_asset` declares `path` as a dependency of the file. The
157
- # dependency will be inserted before the file and will only be
158
- # included once.
189
+ # Returns a Base64-encoded `data:` URI with the contents of the
190
+ # asset at the specified path, and marks that path as a dependency
191
+ # of the current file.
159
192
  #
160
- # If ERB processing is enabled, you can use it to dynamically
161
- # require assets.
193
+ # Use `asset_data_uri` from ERB with CSS or JavaScript assets:
162
194
  #
163
- # <%= require_asset "#{framework}.js" %>
195
+ # #logo { background: url(<%= asset_data_uri 'logo.png' %>) }
164
196
  #
165
- def require_asset(path)
166
- pathname = resolve(path, :content_type => :self)
167
-
168
- unless @_required_paths.include?(pathname.to_s)
169
- @_dependency_paths << pathname.to_s
170
- @_required_paths << pathname.to_s
171
- end
172
-
173
- pathname
197
+ # $('<img>').attr('src', '<%= asset_data_uri 'avatar.jpg' %>')
198
+ #
199
+ def asset_data_uri(path)
200
+ depend_on(path)
201
+ asset = environment.find_asset(path)
202
+ base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
203
+ "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
174
204
  end
175
205
 
176
206
  private
@@ -270,7 +270,9 @@ module Sprockets
270
270
  # //= include "header"
271
271
  #
272
272
  def process_include_directive(path)
273
- included_pathnames << context.resolve(path)
273
+ pathname = context.resolve(path)
274
+ context.depend_on_asset(pathname)
275
+ included_pathnames << pathname
274
276
  end
275
277
 
276
278
  # `require_directory` requires all the files inside a single
@@ -326,7 +328,7 @@ module Sprockets
326
328
  # including it.
327
329
  #
328
330
  # This is used for caching purposes. Any changes made to
329
- # the dependency file with invalidate the cache of the
331
+ # the dependency file will invalidate the cache of the
330
332
  # source file.
331
333
  #
332
334
  # This is useful if you are using ERB and File.read to pull
@@ -335,7 +337,22 @@ module Sprockets
335
337
  # //= depend_on "foo.png"
336
338
  #
337
339
  def process_depend_on_directive(path)
338
- context.depend_on(context.resolve(path))
340
+ context.depend_on(path)
341
+ end
342
+
343
+ # Allows you to state a dependency on an asset without including
344
+ # it.
345
+ #
346
+ # This is used for caching purposes. Any changes that would
347
+ # invalid the asset dependency will invalidate the cache our the
348
+ # source file.
349
+ #
350
+ # Unlike `depend_on`, the path must be a requirable asset.
351
+ #
352
+ # //= depend_on_asset "bar.js"
353
+ #
354
+ def process_depend_on_asset_directive(path)
355
+ context.depend_on_asset(path)
339
356
  end
340
357
 
341
358
  # Enable Sprockets 1.x compat mode.
@@ -376,5 +393,5 @@ module Sprockets
376
393
  def relative?(path)
377
394
  path =~ /^\.($|\.?\/)/
378
395
  end
379
- end
396
+ end
380
397
  end
@@ -9,10 +9,9 @@ module Sprockets
9
9
  # https://github.com/sstephenson/eco
10
10
  #
11
11
  class EcoTemplate < Tilt::Template
12
- # Eco templates always produced compiled JS. We can set Tilt's
13
- # default mime type hint.
14
- def self.default_mime_type
15
- 'application/javascript'
12
+ # Check to see if Eco is loaded
13
+ def self.engine_initialized?
14
+ defined? ::Eco
16
15
  end
17
16
 
18
17
  # Autoload eco library. If the library isn't loaded, Tilt will produce
@@ -8,10 +8,9 @@ module Sprockets
8
8
  # https://github.com/sstephenson/ruby-ejs
9
9
  #
10
10
  class EjsTemplate < Tilt::Template
11
- # EJS templates always produced compiled JS. We can set Tilt's
12
- # default mime type hint.
13
- def self.default_mime_type
14
- 'application/javascript'
11
+ # Check to see if EJS is loaded
12
+ def self.engine_initialized?
13
+ defined? ::EJS
15
14
  end
16
15
 
17
16
  # Autoload ejs library. If the library isn't loaded, Tilt will produce
@@ -1,6 +1,7 @@
1
1
  require 'sprockets/eco_template'
2
2
  require 'sprockets/ejs_template'
3
3
  require 'sprockets/jst_processor'
4
+ require 'sprockets/mime'
4
5
  require 'sprockets/utils'
5
6
  require 'tilt'
6
7
 
@@ -47,6 +48,15 @@ module Sprockets
47
48
  end
48
49
  end
49
50
 
51
+ def engine_formats(ext = nil)
52
+ if ext
53
+ ext = Sprockets::Utils.normalize_extension(ext)
54
+ @engine_formats[ext]
55
+ else
56
+ deep_copy_hash(@engine_formats)
57
+ end
58
+ end
59
+
50
60
  # Returns an `Array` of engine extension `String`s.
51
61
  #
52
62
  # environment.engine_extensions
@@ -62,13 +72,28 @@ module Sprockets
62
72
  #
63
73
  def register_engine(ext, klass)
64
74
  ext = Sprockets::Utils.normalize_extension(ext)
65
- @engines ||= {}
66
75
  @engines[ext] = klass
76
+
77
+ if klass.respond_to?(:default_mime_type) && klass.default_mime_type
78
+ if format_ext = extension_for_mime_type(klass.default_mime_type)
79
+ @engine_formats[format_ext] << ext
80
+ end
81
+ end
82
+
83
+ klass
67
84
  end
85
+
86
+ private
87
+ def deep_copy_hash(hash)
88
+ initial = Hash.new { |h, k| h[k] = [] }
89
+ hash.inject(initial) { |h, (k, a)| h[k] = a.dup; h }
90
+ end
68
91
  end
69
92
 
70
93
  # Extend Sprockets module to provide global registry
71
94
  extend Engines
95
+ @engines = {}
96
+ @engine_formats = Hash.new { |h, k| h[k] = [] }
72
97
 
73
98
  # Cherry pick the default Tilt engines that make sense for
74
99
  # Sprockets. We don't need ones that only generate html like HAML.
@@ -33,7 +33,8 @@ module Sprockets
33
33
 
34
34
  @static_root = nil
35
35
 
36
- @engines = Sprockets.engines
36
+ @engines = Sprockets.engines
37
+ @engine_formats = Sprockets.engine_formats
37
38
  @trail.extensions.replace(engine_extensions)
38
39
 
39
40
  @mime_types = {}
@@ -26,6 +26,7 @@ module Sprockets
26
26
  @preprocessors = environment.preprocessors
27
27
  @postprocessors = environment.postprocessors
28
28
  @bundle_processors = environment.bundle_processors
29
+ @engine_formats = environment.engine_formats
29
30
 
30
31
  # Initialize caches
31
32
  @assets = {}
@@ -0,0 +1,38 @@
1
+ require 'rack/mime'
2
+
3
+ module Sprockets
4
+ module Mime
5
+ # Returns a `Hash` of registered mime types registered on the
6
+ # environment and those part of `Rack::Mime`.
7
+ #
8
+ # If an `ext` is given, it will lookup the mime type for that extension.
9
+ def mime_types(ext = nil)
10
+ if ext.nil?
11
+ Rack::Mime::MIME_TYPES.merge(@mime_types)
12
+ else
13
+ ext = Sprockets::Utils.normalize_extension(ext)
14
+ @mime_types[ext] || Rack::Mime::MIME_TYPES[ext]
15
+ end
16
+ end
17
+
18
+ if {}.respond_to?(:key)
19
+ def extension_for_mime_type(type)
20
+ mime_types.key(type)
21
+ end
22
+ else
23
+ def extension_for_mime_type(type)
24
+ mime_types.index(type)
25
+ end
26
+ end
27
+
28
+ # Register a new mime type.
29
+ def register_mime_type(mime_type, ext)
30
+ ext = Sprockets::Utils.normalize_extension(ext)
31
+ @mime_types[ext] = mime_type
32
+ end
33
+ end
34
+
35
+ # Extend Sprockets module to provide global registry
36
+ extend Mime
37
+ @mime_types = {}
38
+ end
@@ -1,33 +1,20 @@
1
1
  require 'sprockets/engines'
2
+ require 'sprockets/mime'
2
3
  require 'sprockets/processor'
3
4
  require 'sprockets/utils'
4
- require 'rack/mime'
5
5
 
6
6
  module Sprockets
7
7
  # `Processing` is an internal mixin whose public methods are exposed on
8
8
  # the `Environment` and `Index` classes.
9
9
  module Processing
10
- include Engines
11
-
12
- # Returns a `Hash` of registered mime types registered on the
13
- # environment and those part of `Rack::Mime`.
14
- #
15
- # If an `ext` is given, it will lookup the mime type for that extension.
16
- def mime_types(ext = nil)
17
- if ext.nil?
18
- Rack::Mime::MIME_TYPES.merge(@mime_types)
19
- else
20
- ext = Sprockets::Utils.normalize_extension(ext)
21
- @mime_types[ext] || Rack::Mime::MIME_TYPES[ext]
22
- end
23
- end
10
+ include Engines, Mime
24
11
 
25
12
  # Register a new mime type.
26
13
  def register_mime_type(mime_type, ext)
14
+ # Overrides the global behavior to expire the index
27
15
  expire_index!
28
- ext = Sprockets::Utils.normalize_extension(ext)
29
16
  @trail.extensions << ext
30
- @mime_types[ext] = mime_type
17
+ super
31
18
  end
32
19
 
33
20
  # Returns an `Array` of format extension `String`s.
@@ -278,33 +265,5 @@ module Sprockets
278
265
  compressor.compress(data)
279
266
  end
280
267
  end
281
-
282
- protected
283
- def compute_digest
284
- digest = super
285
-
286
- # Add mime types to environment digest
287
- digest << @mime_types.keys.join(',')
288
-
289
- # Add engines to environment digest
290
- digest << @engines.map { |e, k| "#{e}:#{k.name}" }.join(',')
291
-
292
- # Add preprocessors to environment digest
293
- digest << @preprocessors.map { |m, a| "#{m}:#{a.map(&:name)}" }.join(',')
294
-
295
- # Add postprocessors to environment digest
296
- digest << @postprocessors.map { |m, a| "#{m}:#{a.map(&:name)}" }.join(',')
297
-
298
- # Add bundle processors to environment digest
299
- digest << @bundle_processors.map { |m, a| "#{m}:#{a.map(&:name)}" }.join(',')
300
-
301
- digest
302
- end
303
-
304
- private
305
- def deep_copy_hash(hash)
306
- initial = Hash.new { |h, k| h[k] = [] }
307
- hash.inject(initial) { |h, (k, a)| h[k] = a.dup; h }
308
- end
309
268
  end
310
269
  end