middleman-sprockets 4.0.0.rc.1 → 4.0.0.rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +13 -0
  3. data/.gitignore +2 -0
  4. data/.rubocop.yml +57 -0
  5. data/.simplecov +1 -1
  6. data/.travis.yml +26 -15
  7. data/CHANGELOG.md +15 -0
  8. data/Gemfile +25 -21
  9. data/README.md +60 -6
  10. data/Rakefile +31 -11
  11. data/docs/upgrade-3-to-4.md +118 -0
  12. data/features/asset_gems.feature +63 -0
  13. data/features/basic_usage.feature +97 -0
  14. data/features/bower.feature +90 -30
  15. data/features/linked_assets.feature +123 -0
  16. data/features/middleman_helpers.feature +154 -0
  17. data/features/step_definitions/builder_steps.rb +8 -0
  18. data/features/step_definitions/server_steps.rb +20 -0
  19. data/features/support/env.rb +0 -1
  20. data/features/{asset_hash.feature → test_cases/asset_hash.feature} +28 -22
  21. data/features/test_cases/exception_response.feature +31 -0
  22. data/features/test_cases/excluded_file_extensions.feature +39 -0
  23. data/features/test_cases/file_not_found.feature +31 -0
  24. data/features/test_cases/ignore_directive_is_respected.feature +90 -0
  25. data/features/test_cases/imported_asset_extensions.feature +77 -0
  26. data/features/test_cases/jst.feature +36 -0
  27. data/features/test_cases/long_filenames.feature +40 -0
  28. data/features/test_cases/path_helpers.feature +106 -0
  29. data/features/test_cases/processible_outside_asset_dir.feature +49 -0
  30. data/features/test_cases/sass_globs.feature +76 -0
  31. data/features/test_cases/sass_partials.feature +49 -0
  32. data/features/test_cases/sassc.feature +27 -0
  33. data/features/test_cases/use_from_templates.feature +21 -0
  34. data/features/test_cases/using_assets_gem_assets.feature +88 -0
  35. data/fixtures/asset-hash-app/config.rb +2 -0
  36. data/fixtures/asset-hash-app/source/stylesheets/jquery-mobile.css.scss +1 -0
  37. data/fixtures/asset-hash-host-app/config.rb +4 -4
  38. data/fixtures/base-app/config.rb +1 -0
  39. data/fixtures/{bower-multiple-assets-app/source/index.html → base-app/source/index.html.erb} +0 -0
  40. data/fixtures/gems/assets_gem/assets_gem.gemspec +16 -0
  41. data/fixtures/gems/assets_gem/lib/assets_gem.rb +7 -0
  42. data/fixtures/gems/assets_gem/vendor/assets/css/_imports/_import.scss +1 -0
  43. data/fixtures/{sprockets-imported-assets-match-multiple-paths-app/vendor/assets/css/test.css → gems/assets_gem/vendor/assets/css/test.scss} +1 -1
  44. data/fixtures/gems/assets_gem/vendor/assets/fonts/font.ttf +0 -0
  45. data/fixtures/gems/assets_gem/vendor/assets/images/logo.png +0 -0
  46. data/fixtures/gems/assets_gem/vendor/assets/javascripts/_imports/import.js +1 -0
  47. data/gemfiles/middleman-4.0.gemfile +7 -0
  48. data/gemfiles/middleman-4.1.gemfile +7 -0
  49. data/gemfiles/middleman-head.gemfile +7 -0
  50. data/gemfiles/sprockets-4.0.gemfile +6 -0
  51. data/lib/middleman-sprockets.rb +5 -5
  52. data/lib/middleman-sprockets/extension.rb +174 -215
  53. data/lib/middleman-sprockets/interface.rb +64 -0
  54. data/lib/middleman-sprockets/resource.rb +97 -0
  55. data/lib/middleman-sprockets/version.rb +1 -1
  56. data/middleman-sprockets.gemspec +16 -15
  57. data/tasks/matrix.rake +46 -0
  58. metadata +77 -237
  59. data/features/jst.feature +0 -14
  60. data/features/long_filenames.feature +0 -17
  61. data/features/sass_globs.feature +0 -9
  62. data/features/sass_partials.feature +0 -36
  63. data/features/sprockets.feature +0 -108
  64. data/features/sprockets_gems.feature +0 -48
  65. data/fixtures/asset-paths-app/config.rb +0 -1
  66. data/fixtures/asset-paths-app/derp/javascripts/vendored_js.js +0 -1
  67. data/fixtures/asset-paths-app/source/javascripts/vendored_include.js +0 -1
  68. data/fixtures/bower-app/bower.json +0 -7
  69. data/fixtures/bower-app/bower_components/underscore/bower.json +0 -8
  70. data/fixtures/bower-app/bower_components/underscore/underscore.js +0 -1343
  71. data/fixtures/bower-app/config.rb +0 -1
  72. data/fixtures/bower-app/source/javascripts/application.js +0 -1
  73. data/fixtures/bower-app/source/javascripts/import.js +0 -1
  74. data/fixtures/bower-individual-outputdir-app/bower.json +0 -7
  75. data/fixtures/bower-individual-outputdir-app/bower_components/underscore/bower.json +0 -8
  76. data/fixtures/bower-individual-outputdir-app/bower_components/underscore/underscore.js +0 -1343
  77. data/fixtures/bower-individual-outputdir-app/config.rb +0 -2
  78. data/fixtures/bower-individual-outputdir-app/source/javascripts/application.js +0 -4
  79. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/.bower.json +0 -34
  80. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/bower.json +0 -26
  81. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/img/close.png +0 -0
  82. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/js/lightbox.js +0 -2
  83. data/fixtures/bower-individual-outputdir-app/vendor/assets/components/lightbox2/package.json +0 -37
  84. data/fixtures/bower-json-app/config.rb +0 -1
  85. data/fixtures/bower-json-app/source/javascripts/application.js.coffee +0 -1
  86. data/fixtures/bower-json-app/source/javascripts/bower.json +0 -5
  87. data/fixtures/bower-multiple-assets-app/.bowerrc +0 -4
  88. data/fixtures/bower-multiple-assets-app/bower.json +0 -7
  89. data/fixtures/bower-multiple-assets-app/config.rb +0 -1
  90. data/fixtures/bower-multiple-assets-app/source/javascripts/core.js +0 -2
  91. data/fixtures/bower-multiple-assets-app/vendor/assets/components/lightbox2/.bower.json +0 -34
  92. data/fixtures/bower-multiple-assets-app/vendor/assets/components/lightbox2/bower.json +0 -26
  93. data/fixtures/bower-multiple-assets-app/vendor/assets/components/lightbox2/img/close.png +0 -0
  94. data/fixtures/bower-multiple-assets-app/vendor/assets/components/lightbox2/img/open.png +0 -0
  95. data/fixtures/bower-multiple-assets-app/vendor/assets/components/lightbox2/js/lightbox.js +0 -2
  96. data/fixtures/bower-multiple-assets-app/vendor/assets/components/lightbox2/package.json +0 -37
  97. data/fixtures/glob-app/config.rb +0 -0
  98. data/fixtures/glob-app/source/stylesheets/main.css.scss +0 -1
  99. data/fixtures/glob-app/source/stylesheets/module1/_i-am-mod.scss +0 -3
  100. data/fixtures/glob-app/source/stylesheets/module2/_derp.sass +0 -2
  101. data/fixtures/glob-app/source/stylesheets/shared/3rd-party/bootstrap.sass +0 -2
  102. data/fixtures/glob-app/source/stylesheets/shared/shared.scss +0 -3
  103. data/fixtures/jquery-mobile-app/config.rb +0 -0
  104. data/fixtures/jquery-mobile-app/source/javascripts/app.js +0 -1
  105. data/fixtures/jquery-mobile-app/source/stylesheets/base.css.scss +0 -2
  106. data/fixtures/long-filenames-app/config.rb +0 -0
  107. data/fixtures/long-filenames-app/source/images/00000000-0000-0000-0000-000000.svg +0 -3
  108. data/fixtures/long-filenames-app/source/images/00000000-0000-0000-0000-0000001.svg +0 -3
  109. data/fixtures/preview-app/config.rb +0 -0
  110. data/fixtures/preview-app/source/content.html.erb +0 -1
  111. data/fixtures/preview-app/source/layout.erb +0 -1
  112. data/fixtures/preview-app/source/stylesheets/_partial.sass +0 -2
  113. data/fixtures/preview-app/source/stylesheets/_partial2.css.sass +0 -2
  114. data/fixtures/preview-app/source/stylesheets/main.css.sass +0 -4
  115. data/fixtures/preview-app/source/stylesheets/main2.css.sass +0 -4
  116. data/fixtures/preview-app/source/stylesheets/plain.css.sass +0 -2
  117. data/fixtures/sprockets-app/config.rb +0 -2
  118. data/fixtures/sprockets-app/source/index.html.erb +0 -6
  119. data/fixtures/sprockets-app/source/library/css/bootstrap_include.css.scss +0 -1
  120. data/fixtures/sprockets-app/source/library/css/plain.css +0 -5
  121. data/fixtures/sprockets-app/source/library/css/sprockets_base1.css.scss +0 -1
  122. data/fixtures/sprockets-app/source/library/css/sprockets_base2.css.scss +0 -1
  123. data/fixtures/sprockets-app/source/library/css/sprockets_sub.css.scss +0 -1
  124. data/fixtures/sprockets-app/source/library/js/jquery_include.js +0 -1
  125. data/fixtures/sprockets-app/source/library/js/plain.js +0 -6
  126. data/fixtures/sprockets-app/source/library/js/sprockets_base.js +0 -5
  127. data/fixtures/sprockets-app/source/library/js/sprockets_sub.js +0 -3
  128. data/fixtures/sprockets-app/source/library/js/vendored_include.js +0 -1
  129. data/fixtures/sprockets-app/vendor/assets/javascripts/coffee.js.coffee +0 -2
  130. data/fixtures/sprockets-app/vendor/assets/javascripts/vendored_js.js +0 -1
  131. data/fixtures/sprockets-app/vendor/assets/stylesheets/vendored.css.scss +0 -4
  132. data/fixtures/sprockets-app2/config.rb +0 -0
  133. data/fixtures/sprockets-app2/data/test.yml +0 -4
  134. data/fixtures/sprockets-app2/data/test2.json +0 -4
  135. data/fixtures/sprockets-app2/source/javascripts/_templates/test.jst.ejs +0 -1
  136. data/fixtures/sprockets-app2/source/javascripts/_templates/test2.jst.eco +0 -1
  137. data/fixtures/sprockets-app2/source/javascripts/asset_path.js.erb +0 -3
  138. data/fixtures/sprockets-app2/source/javascripts/multiple_engines.js.coffee.erb +0 -1
  139. data/fixtures/sprockets-app2/source/javascripts/sprockets_base.js +0 -5
  140. data/fixtures/sprockets-app2/source/javascripts/sprockets_sub.js +0 -3
  141. data/fixtures/sprockets-app2/source/javascripts/templates.js +0 -1
  142. data/fixtures/sprockets-app2/source/stylesheets/sprockets_base1.css.scss +0 -1
  143. data/fixtures/sprockets-app2/source/stylesheets/sprockets_base2.css.scss +0 -1
  144. data/fixtures/sprockets-app2/source/stylesheets/sprockets_sub.css.scss +0 -1
  145. data/fixtures/sprockets-images-app/config.rb +0 -1
  146. data/fixtures/sprockets-images-app/source/index.html.erb +0 -10
  147. data/fixtures/sprockets-images-app/source/library/images/cat.jpg +0 -0
  148. data/fixtures/sprockets-images-app/vendor/assets/images/cat-2.jpg +0 -0
  149. data/fixtures/sprockets-imported-asset-path-conflicts-app/config.rb +0 -4
  150. data/fixtures/sprockets-imported-asset-path-conflicts-app/resources/assets/stylesheets/test.css +0 -3
  151. data/fixtures/sprockets-imported-assets-match-multiple-paths-app/config.rb +0 -4
  152. data/fixtures/sprockets-multiple-extensions-app/bower.json +0 -8
  153. data/fixtures/sprockets-multiple-extensions-app/config.rb +0 -1
  154. data/fixtures/sprockets-multiple-extensions-app/source/fonts/fontawesome-webfont-source.svg.gz +0 -0
  155. data/fixtures/sprockets-multiple-extensions-app/source/images/drawing-source.svg +0 -76
  156. data/fixtures/sprockets-multiple-extensions-app/source/stylesheets/app.css.scss +0 -3
  157. data/fixtures/sprockets-multiple-extensions-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg.gz +0 -0
  158. data/fixtures/sprockets-multiple-extensions-app/vendor/assets/components/jquery/jquery.asdf.asdf.js.min.asdf +0 -4
  159. data/fixtures/sprockets-multiple-extensions-app/vendor/assets/components/jquery/jquery.min.js +0 -4
  160. data/fixtures/sprockets-svg-font-app/bower.json +0 -8
  161. data/fixtures/sprockets-svg-font-app/config.rb +0 -1
  162. data/fixtures/sprockets-svg-font-app/source/fonts/fontawesome-webfont-source.svg +0 -504
  163. data/fixtures/sprockets-svg-font-app/source/fonts/fontawesome-webfont-source.svg.gz +0 -0
  164. data/fixtures/sprockets-svg-font-app/source/images/drawing-source.svg +0 -76
  165. data/fixtures/sprockets-svg-font-app/source/stylesheets/app.css.scss +0 -4
  166. data/fixtures/sprockets-svg-font-app/vendor/assets/components/blub/images/drawing-bower.svg +0 -76
  167. data/fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg +0 -504
  168. data/fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.svg.gz +0 -0
  169. data/fixtures/sprockets-svg-font-app/vendor/assets/components/font-awesome/fonts/fontawesome-webfont-bower.ttf.gz +0 -0
@@ -0,0 +1,63 @@
1
+ Feature: Make Gem assets available to Sprocket's lookup paths
2
+
3
+ An attempt is made to lookup all css, js, image, & font paths in asset gems to be appended to Sprocket's lookup paths. These gems are expected to loosely follow a few conventions:
4
+
5
+ - asset root at: `assets`, `app`, `vendor`, `lib`, `app/assets`, `vendor/assets`, or `lib/assets`
6
+ - asset directories named: `javascripts`, `js`, `stylesheets`, `css`, `images`, `img`, or `fonts`
7
+
8
+ If not, no worries -- you can append the gems path manually to Sprockets.
9
+
10
+ Scenario: An asset gem with assets under vendor
11
+ Using the fixture asset gem located at `fixtures/gems/asset_gem` which puts it's assets in `vendor` like this:
12
+ """
13
+ assets_gem/
14
+ +-- vendor/
15
+ +-- assets/
16
+ +-- css/
17
+ +-- fonts/
18
+ +-- images/
19
+ +-- javascripts/
20
+ """
21
+
22
+ Given a fixture app "base-app"
23
+ And a file named "config.rb" with:
24
+ """
25
+ activate :sprockets
26
+ """
27
+ And a file named "source/stylesheets/site.css.scss" with:
28
+ """
29
+ @import "test";
30
+ """
31
+ And the Server is running
32
+
33
+ Then sprockets paths should include gem path "assets_gem/vendor/assets/css"
34
+ And sprockets paths should include gem path "assets_gem/vendor/assets/fonts"
35
+ And sprockets paths should include gem path "assets_gem/vendor/assets/images"
36
+ And sprockets paths should include gem path "assets_gem/vendor/assets/javascripts"
37
+
38
+ When I go to "/stylesheets/site.css"
39
+ Then I should see:
40
+ """
41
+ body {
42
+ background: #fd0; }
43
+ """
44
+
45
+ Scenario: Manually appending a gem's paths
46
+ Given a fixture app "base-app"
47
+ And a file named "config.rb" with:
48
+ """
49
+ activate :sprockets
50
+ sprockets.append_path File.join(root, 'local_gem', 'resources')
51
+ """
52
+ And a file named "local_gem/resources/stylesheet.css" with:
53
+ """
54
+ body { content: 'local_gem'; }
55
+ """
56
+ And a file named "source/stylesheets/site.css" with:
57
+ """
58
+ //= require stylesheet
59
+ """
60
+ And the Server is running
61
+
62
+ When I go to "/stylesheets/site.css"
63
+ Then I should see "content: 'local_gem';"
@@ -0,0 +1,97 @@
1
+ Feature: Basic Usage
2
+
3
+ At it's base, the middleman-sprockets extension hooks sprockets into Middleman so that Sprockets is used to render js & css files instead of Middleman. This gives you access to [sprockets directives](https://github.com/rails/sprockets#sprockets-directives) and automagically building linked assets.
4
+
5
+ To use, activate the extension in `config.rb`:
6
+
7
+ """ruby
8
+ activate :sprockets
9
+ """
10
+
11
+ Scenario: CSS & JS files are rendered with Sprockets
12
+ Given a fixture app "base-app"
13
+ And a file named "config.rb" with:
14
+ """
15
+ activate :sprockets
16
+ """
17
+ And a file named "source/stylesheets/_lib/partial.scss" with:
18
+ """
19
+ body { background: #fd0; }
20
+ """
21
+ And a file named "source/stylesheets/site.css.scss" with:
22
+ """
23
+ @import '_lib/partial';
24
+ """
25
+ And a file named "source/javascripts/_lib/partial.js" with:
26
+ """
27
+ console.log('hello');
28
+ """
29
+ And a file named "source/javascripts/site.js" with:
30
+ """
31
+ //= require '_lib/partial'
32
+ """
33
+ And the Server is running
34
+
35
+ When I go to "/stylesheets/site.css"
36
+ Then I should see:
37
+ """
38
+ body {
39
+ background: #fd0; }
40
+ """
41
+
42
+ When I go to "/javascripts/site.js"
43
+ Then I should see "console.log('hello');"
44
+
45
+
46
+ Scenario: The default :css_dir or :js_dir are appended to Sprockets lookup paths
47
+ Given a fixture app "base-app"
48
+ And a file named "config.rb" with:
49
+ """
50
+ activate :sprockets
51
+ """
52
+ And the Server is running
53
+
54
+ Then sprockets paths should include "source/stylesheets"
55
+ And sprockets paths should include "source/javascripts"
56
+
57
+
58
+ Scenario: Custom directories for :css_dir or :js_dir are appened to Sprockets lookup paths
59
+ Given a fixture app "base-app"
60
+ And a file named "config.rb" with:
61
+ """
62
+ activate :sprockets
63
+
64
+ set :css_dir, "assets/css"
65
+ set :js_dir, "assets/scripts"
66
+ """
67
+ And the Server is running
68
+
69
+ Then sprockets paths should include "source/assets/css"
70
+ And sprockets paths should include "source/assets/scripts"
71
+
72
+ @sprockets3
73
+ Scenario: Css can use either a Sprockets require or Sass import
74
+ Given a fixture app "base-app"
75
+ And a file named "config.rb" with:
76
+ """
77
+ activate :sprockets
78
+ """
79
+ And a file named "source/stylesheets/_lib/import.scss" with:
80
+ """
81
+ body { content: 'imported'; }
82
+ """
83
+ And a file named "source/stylesheets/sprockets.css.scss" with:
84
+ """
85
+ //= require '_lib/import.css'
86
+ """
87
+ And a file named "source/stylesheets/sass_import.css.scss" with:
88
+ """
89
+ @import '_lib/import';
90
+ """
91
+ And the Server is running
92
+
93
+ When I go to "/stylesheets/sprockets.css"
94
+ Then I should see "content: 'imported';"
95
+
96
+ When I go to "/stylesheets/sass_import.css"
97
+ Then I should see "content: 'imported';"
@@ -1,42 +1,102 @@
1
- Feature: Bower
2
- Scenario: Sprockets can pull underscore from bower
3
- Given the Server is running at "bower-app"
1
+ Feature: Using assets installed via Bower
2
+
3
+ Usage with Bower is fairly barebones -- for now we don't do anything fancy to detect which files to link by reading bower.json files. A typical workflow looks something like this:
4
+
5
+ - create your `ROOT/bower.json` & install via bower to `ROOT/bower_components`
6
+ - append `bower_components` to sprockets paths
7
+ - either require assets for use, or create a `manifest.js` that links files
8
+
9
+ Background:
10
+ Given a fixture app "base-app"
11
+ And a file named "config.rb" with:
12
+ """
13
+ activate :sprockets
14
+ sprockets.append_path File.join(root, "bower_components")
15
+ """
16
+ And a file named "bower_components/underscore/underscore.js" with:
17
+ """
18
+ var _ = {};
19
+ return _;
20
+ """
21
+ And a file named "source/javascripts/application.js" with:
22
+ """
23
+ //= require underscore/underscore
24
+ """
25
+
26
+ Scenario: Sprockets can require underscore from bower
27
+ Given the Server is running
28
+
29
+ Then sprockets paths should include "bower_components"
4
30
  When I go to "/javascripts/application.js"
5
31
  Then I should see "return _;"
6
32
 
7
- Scenario: Sprockets can build underscore from bower
8
- Given a successfully built app at "bower-app"
33
+
34
+ Scenario: Sprockets can build when requiring underscore from bower
35
+ And a successfully built app
36
+
9
37
  When I cd to "build"
10
38
  Then the following files should exist:
11
39
  | javascripts/application.js |
12
40
  And the file "javascripts/application.js" should contain "return _;"
13
41
 
14
- Scenario: Sprockets should not mess with bower.json
15
- Given a successfully built app at "bower-json-app"
16
- When I cd to "build"
17
- Then the following files should exist:
18
- | javascripts/bower.json |
19
- And the file "javascripts/bower.json" should contain '"name": "my-project",'
20
42
 
21
- Scenario: Assets can be added to the build with import_asset from bower dir
22
- Given a successfully built app at "bower-app"
23
- When I cd to "build"
24
- Then a file named "assets/underscore/underscore.js" should exist
43
+ Scenario: Assets can be added to the sitemap by linking them in a manifest
44
+ Given a file named "source/javascripts/manifest.js" with:
45
+ """
46
+ //= link underscore/underscore
47
+ """
48
+ And the Server is running
25
49
 
26
- Scenario: Multiple assets can be added to the build with import_asset from bower dir and are placed in the correct directory
27
- Given a successfully built app at "bower-multiple-assets-app"
28
- When I cd to "build"
29
- Then a file named "assets/lightbox2/img/close.png" should exist
30
- Then a file named "assets/lightbox2/js/lightbox.js" should exist
50
+ When I go to "/assets/underscore/underscore.js"
51
+ Then I should see "return _;"
31
52
 
32
- Scenario: Assets which haven't been imported don't appear in output directory
33
- Given a successfully built app at "bower-multiple-assets-app"
34
- When I cd to "build"
35
- Then a file named "images/lightbox2/img/open.png" should not exist
36
53
 
37
- Scenario: Assets can have an individual output directory
38
- Given a successfully built app at "bower-individual-outputdir-app"
39
- When I cd to "build"
40
- Then a file named "assets/underscore/underscore.js" should exist
41
- And a file named "assets/lightbox2/img/close.png" should exist
42
- And a file named "assets/lightbox2/js/lightbox.js" should exist
54
+ Scenario: Assets which haven't been linked aren't added to the sitemap
55
+ Given a file named "bower_components/underscore/hello.js" with:
56
+ """
57
+ console.log('hello');
58
+ """
59
+ And the Server is running
60
+
61
+ When I go to "/assets/underscore/hello.js"
62
+ Then the status code should be "404"
63
+
64
+
65
+ Scenario: Assets have an individual output directory
66
+ Given a file named "vendor/assets/lightbox2/hello.js" with:
67
+ """
68
+ console.log('hello');
69
+ """
70
+ And a file named "config.rb" with:
71
+ """
72
+ activate :sprockets
73
+ sprockets.append_path File.join(root, "bower_components")
74
+ sprockets.append_path File.join(root, "vendor/assets")
75
+ """
76
+ And a file named "source/javascripts/manifest.js" with:
77
+ """
78
+ //= link underscore/underscore
79
+ //= link lightbox2/hello
80
+ """
81
+ And the Server is running
82
+
83
+ When I go to "/assets/underscore/underscore.js"
84
+ Then I should see "return _;"
85
+
86
+ When I go to "/assets/lightbox2/hello.js"
87
+ Then I should see "console.log('hello');"
88
+
89
+
90
+ Scenario: Sprockets should not mess with bower.json if it's in source
91
+ Given a file named "source/javascripts/bower.json" with:
92
+ """
93
+ {
94
+ "name": "my-project",
95
+ "version": "1.0.0",
96
+ "main": "application.js"
97
+ }
98
+ """
99
+ And the Server is running
100
+
101
+ When I go to "/javascripts/bower.json"
102
+ Then I should see '"name": "my-project",'
@@ -0,0 +1,123 @@
1
+ Feature: Linked assets are included in the sitemap
2
+
3
+ Assets that are linked, either through a `//= link` directive or with an asset url helper (like `asset_path`) will be included in the sitemap & built automatically. The path these assets are placed at is configurable with the `:imported_asset_path` option.
4
+
5
+ Note that we're taking advantage of the fact that the `assets_gem` is included in the sprockets paths with these examples.
6
+
7
+ Scenario: Assets linked with a Sprockets directive
8
+ Given a fixture app "base-app"
9
+ And a file named "config.rb" with:
10
+ """
11
+ activate :sprockets
12
+ """
13
+ And a file named "source/stylesheets/manifest.js" with:
14
+ """
15
+ //= link logo.png
16
+ """
17
+ And the Server is running
18
+
19
+ When I go to "/assets/logo.png"
20
+ Then the status code should be "200"
21
+
22
+
23
+ Scenario: Assets linked using a path helper
24
+ Given a fixture app "base-app"
25
+ And a file named "config.rb" with:
26
+ """
27
+ activate :sprockets
28
+ """
29
+ And a file named "source/stylesheets/site.css.scss" with:
30
+ """
31
+ @import 'import';
32
+ """
33
+ And a file named "source/stylesheets/_import.scss" with:
34
+ """
35
+ body {
36
+ background: image-url('logo.png');
37
+ }
38
+ """
39
+ And the Server is running
40
+
41
+ When I go to "/assets/logo.png"
42
+ Then the status code should be "200"
43
+
44
+ When I go to "/stylesheets/site.css"
45
+ Then I should see "url(/assets/logo.png)"
46
+
47
+
48
+ Scenario: Linked asset destination is configurable
49
+ Given a fixture app "base-app"
50
+ And a file named "config.rb" with:
51
+ """
52
+ activate :sprockets do |c|
53
+ c.imported_asset_path = 'linked'
54
+ end
55
+ """
56
+ And a file named "source/javascripts/manifest.js" with:
57
+ """
58
+ //= link logo.png
59
+ """
60
+ And the Server is running
61
+
62
+ When I go to "/linked/logo.png"
63
+ Then the status code should be "200"
64
+
65
+
66
+ Scenario: Linked assets can be rendered
67
+ Given a fixture app "base-app"
68
+ And a file named "config.rb" with:
69
+ """
70
+ activate :sprockets
71
+ """
72
+ And a file named "vendor/css/vendored.css.sass" with:
73
+ """
74
+ body
75
+ color: red
76
+ """
77
+ And a file named "vendor/js/vendored.js.coffee" with:
78
+ """
79
+ console.log 'hello'
80
+ """
81
+ And a file named "source/javascripts/manifest.js" with:
82
+ """
83
+ //= link 'vendored.css'
84
+ //= link 'vendored.js'
85
+ """
86
+ And the Server is running
87
+
88
+ When I go to "/assets/vendored.css"
89
+ Then I should see "color: red;"
90
+
91
+ When I go to "/assets/vendored.js"
92
+ Then I should see "console.log('hello')"
93
+
94
+
95
+ Scenario: Linking to Sprockets assets from Middleman
96
+ You can do this, but you need to make sure that the asset is imported into the sitemap. If the asset is linked via a Sprockets directive or path helper no worries -- otherwise you could create a manifest file that contains links to assets you need.
97
+
98
+ In this test case, remember the `assets_gem` is available.
99
+
100
+ Given a fixture app "base-app"
101
+ And a file named "config.rb" with:
102
+ """
103
+ activate :sprockets
104
+ """
105
+ And a file named "source/index.html.erb" with:
106
+ """
107
+ <%= image_tag('assets/logo.png') %>
108
+ """
109
+ And the Server is running
110
+
111
+ When I go to "/assets/logo.png"
112
+ Then the status code should be "404"
113
+
114
+ And the file "source/javascripts/manifest.js" has the contents
115
+ """
116
+ //= link 'logo.png'
117
+ """
118
+
119
+ When I go to "/assets/logo.png"
120
+ Then the status code should be "200"
121
+
122
+ When I go to "/"
123
+ Then I should see '<img src="/assets/logo.png" />'
@@ -0,0 +1,154 @@
1
+ Feature: Access to Middleman helpers
2
+
3
+ Sprockets is given an `asset_path` helper that is able to use the Middleman sitemap. This allows Sprockets methods like `image-url` to work for Middleman assets.
4
+
5
+ By default helpers other than asset_path that are added to Middleman aren't available in Sprockets' rendering context. They can, however, be added through a configuration option. There is a caveat though that `current_resource` is unavailable so look out for helpers that depend on it.
6
+
7
+ Scenario: Using asset_path to link to a Middleman asset
8
+ Here we're depending on the behavior of `image-url` to call asset_path internally
9
+
10
+ Given a fixture app "base-app"
11
+ And a file named "config.rb" with:
12
+ """
13
+ activate :sprockets
14
+ set :http_prefix, '/winterfell'
15
+ """
16
+ And a file named "source/images/img.svg" with:
17
+ """
18
+ <?xml version="1.0" encoding="iso-8859-1"?>
19
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"
20
+ "http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
21
+ <svg width="100%" height="100%">
22
+ <g transform="translate(50,50)">
23
+ <rect x="0" y="0" width="150" height="50" style="fill:red;" />
24
+ </g>
25
+ </svg>
26
+ """
27
+ And a file named "source/stylesheets/site.css.scss" with:
28
+ """
29
+ body {
30
+ background: image-url('img.svg');
31
+ }
32
+ """
33
+ And the Server is running
34
+
35
+ When I go to "/stylesheets/site.css"
36
+ Then I should see:
37
+ """
38
+ body {
39
+ background: url(/winterfell/images/img.svg); }
40
+ """
41
+
42
+ Scenario: Sprockets has access to Middleman data
43
+ Given a fixture app "base-app"
44
+ And a file named "config.rb" with:
45
+ """
46
+ activate :sprockets
47
+ """
48
+ And a file named "data/test.yml" with:
49
+ """
50
+ foo: bar
51
+ """
52
+ And a file named "source/javascripts/data_accessor.js.coffee.erb" with:
53
+ """
54
+ console.log '<%= data.test.foo %>'
55
+ """
56
+ And the Server is running
57
+
58
+ When I go to "/javascripts/data_accessor.js"
59
+ Then I should see "console.log('bar')"
60
+
61
+ Scenario: Using a helper from a Sprockets asset
62
+ Given a fixture app "base-app"
63
+ And a file named "config.rb" with:
64
+ """
65
+ activate :sprockets do |c|
66
+ c.expose_middleman_helpers = true
67
+ end
68
+
69
+ helpers do
70
+ def hello
71
+ 'hello'
72
+ end
73
+ end
74
+ """
75
+ And a file named "source/index.html.erb" with:
76
+ """
77
+ <h1><%= hello %></h1>
78
+ """
79
+ And a file named "source/javascripts/site.js.erb" with:
80
+ """
81
+ console.log('<%= hello %>');
82
+ """
83
+ And a file named "vendor/javascripts/imported.js.erb" with:
84
+ """
85
+ console.log('<%= hello %>');
86
+ """
87
+ And a file named "source/javascripts/importer.js" with:
88
+ """
89
+ //= require imported
90
+ """
91
+ And the Server is running
92
+
93
+ When I go to "/index.html"
94
+ Then I should see "<h1>hello</h1>"
95
+
96
+ When I go to "/javascripts/site.js"
97
+ Then I should see "console.log('hello');"
98
+
99
+ When I go to "/javascripts/importer.js"
100
+ Then I should see "console.log('hello');"
101
+
102
+
103
+ Scenario: current_resource is unavailable
104
+ Given a fixture app "base-app"
105
+ And a file named "config.rb" with:
106
+ """
107
+ activate :sprockets do |c|
108
+ c.expose_middleman_helpers = true
109
+ end
110
+ """
111
+ And a file named "source/index.html.erb" with:
112
+ """
113
+ <pre><%= current_resource.url %></pre>
114
+ """
115
+ And a file named "source/javascripts/site.js.erb" with:
116
+ """
117
+ console.log('<%= current_resource.url %>');
118
+ """
119
+ And the Server is running
120
+
121
+ When I go to "/index.html"
122
+ Then I should see "<pre>/</pre>"
123
+
124
+ When going to "/javascripts/site.js" should not raise an exception
125
+ And I should see "NoMethodError: undefined method `url' for nil:NilClass"
126
+
127
+
128
+ Scenario: Helpers are not included by default
129
+ Given a fixture app "base-app"
130
+ And a file named "config.rb" with:
131
+ """
132
+ activate :sprockets
133
+
134
+ helpers do
135
+ def hello
136
+ 'hello'
137
+ end
138
+ end
139
+ """
140
+ And a file named "source/index.html.erb" with:
141
+ """
142
+ <h1><%= hello %></h1>
143
+ """
144
+ And a file named "source/javascripts/site.js.erb" with:
145
+ """
146
+ console.log('<%= hello %>');
147
+ """
148
+ And the Server is running
149
+
150
+ When I go to "/index.html"
151
+ Then I should see "<h1>hello</h1>"
152
+
153
+ When going to "/javascripts/site.js" should not raise an exception
154
+ Then I should see "undefined local variable or method `hello'"