bpm 1.0.0.beta.8 → 1.0.0.beta.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG.md +9 -0
  3. data/bpm.gemspec +2 -7
  4. data/lib/bpm/pipeline/generated_asset.rb +19 -21
  5. data/lib/bpm/pipeline/plugin_context.rb +7 -7
  6. data/lib/bpm/pipeline/plugin_processor.rb +11 -20
  7. data/lib/bpm/pipeline/transport_processor.rb +8 -13
  8. data/lib/bpm/pipeline.rb +47 -42
  9. data/lib/bpm/project_generator.rb +2 -2
  10. data/lib/bpm/version.rb +1 -1
  11. data/lib/bpm.rb +0 -3
  12. data/spec/cli/init_spec.rb +48 -48
  13. data/spec/cli/rebuild_spec.rb +30 -30
  14. data/spec/fixtures/projects/init_app/assets/bpm_libs.js +1 -1
  15. data/spec/fixtures/projects/init_app/assets/bpm_styles.css +1 -1
  16. data/spec/fixtures/projects/init_default/assets/bpm_libs.js +1 -1
  17. data/spec/fixtures/projects/init_default/assets/bpm_styles.css +1 -1
  18. data/spec/plugins/minifier_spec.rb +8 -8
  19. data/templates/project/index.html +0 -2
  20. data/templates/project/{app → lib}/main.js +0 -0
  21. metadata +24 -209
  22. data/.gitmodules +0 -3
  23. data/vendor/sprockets/.gitignore +0 -7
  24. data/vendor/sprockets/.travis.yml +0 -7
  25. data/vendor/sprockets/Gemfile +0 -2
  26. data/vendor/sprockets/LICENSE +0 -20
  27. data/vendor/sprockets/README.md +0 -22
  28. data/vendor/sprockets/Rakefile +0 -8
  29. data/vendor/sprockets/lib/sprockets/asset.rb +0 -198
  30. data/vendor/sprockets/lib/sprockets/asset_attributes.rb +0 -178
  31. data/vendor/sprockets/lib/sprockets/base.rb +0 -134
  32. data/vendor/sprockets/lib/sprockets/bundled_asset.rb +0 -249
  33. data/vendor/sprockets/lib/sprockets/cache/file_store.rb +0 -41
  34. data/vendor/sprockets/lib/sprockets/caching.rb +0 -126
  35. data/vendor/sprockets/lib/sprockets/charset_normalizer.rb +0 -41
  36. data/vendor/sprockets/lib/sprockets/context.rb +0 -221
  37. data/vendor/sprockets/lib/sprockets/digest.rb +0 -73
  38. data/vendor/sprockets/lib/sprockets/directive_processor.rb +0 -397
  39. data/vendor/sprockets/lib/sprockets/eco_template.rb +0 -38
  40. data/vendor/sprockets/lib/sprockets/ejs_template.rb +0 -37
  41. data/vendor/sprockets/lib/sprockets/engines.rb +0 -117
  42. data/vendor/sprockets/lib/sprockets/environment.rb +0 -94
  43. data/vendor/sprockets/lib/sprockets/errors.rb +0 -17
  44. data/vendor/sprockets/lib/sprockets/index.rb +0 -81
  45. data/vendor/sprockets/lib/sprockets/jst_processor.rb +0 -26
  46. data/vendor/sprockets/lib/sprockets/mime.rb +0 -38
  47. data/vendor/sprockets/lib/sprockets/processing.rb +0 -269
  48. data/vendor/sprockets/lib/sprockets/processor.rb +0 -32
  49. data/vendor/sprockets/lib/sprockets/safety_colons.rb +0 -28
  50. data/vendor/sprockets/lib/sprockets/server.rb +0 -270
  51. data/vendor/sprockets/lib/sprockets/static_asset.rb +0 -86
  52. data/vendor/sprockets/lib/sprockets/static_compilation.rb +0 -74
  53. data/vendor/sprockets/lib/sprockets/trail.rb +0 -123
  54. data/vendor/sprockets/lib/sprockets/utils.rb +0 -67
  55. data/vendor/sprockets/lib/sprockets/version.rb +0 -3
  56. data/vendor/sprockets/lib/sprockets.rb +0 -31
  57. data/vendor/sprockets/sprockets.gemspec +0 -30
  58. data/vendor/sprockets/test/fixtures/asset/POW.png +0 -0
  59. data/vendor/sprockets/test/fixtures/asset/application.js +0 -6
  60. data/vendor/sprockets/test/fixtures/asset/bar-utf8.css +0 -2
  61. data/vendor/sprockets/test/fixtures/asset/charset.css +0 -2
  62. data/vendor/sprockets/test/fixtures/asset/circle/a.js +0 -2
  63. data/vendor/sprockets/test/fixtures/asset/circle/b.js +0 -2
  64. data/vendor/sprockets/test/fixtures/asset/circle/c.js +0 -2
  65. data/vendor/sprockets/test/fixtures/asset/compat.js +0 -4
  66. data/vendor/sprockets/test/fixtures/asset/constants.js +0 -2
  67. data/vendor/sprockets/test/fixtures/asset/constants.yml +0 -1
  68. data/vendor/sprockets/test/fixtures/asset/default_mime_type.js +0 -1
  69. data/vendor/sprockets/test/fixtures/asset/filename.js.erb +0 -1
  70. data/vendor/sprockets/test/fixtures/asset/foo-utf8.css +0 -2
  71. data/vendor/sprockets/test/fixtures/asset/included_header.js +0 -4
  72. data/vendor/sprockets/test/fixtures/asset/jquery.tmpl.min.js +0 -1
  73. data/vendor/sprockets/test/fixtures/asset/mismatch.js +0 -1
  74. data/vendor/sprockets/test/fixtures/asset/multiple.js +0 -2
  75. data/vendor/sprockets/test/fixtures/asset/multipleengine.js +0 -1
  76. data/vendor/sprockets/test/fixtures/asset/noengine.js +0 -1
  77. data/vendor/sprockets/test/fixtures/asset/noformat.coffee +0 -1
  78. data/vendor/sprockets/test/fixtures/asset/one.css +0 -1
  79. data/vendor/sprockets/test/fixtures/asset/oneengine.js +0 -1
  80. data/vendor/sprockets/test/fixtures/asset/project.css +0 -1
  81. data/vendor/sprockets/test/fixtures/asset/project.js.erb +0 -4
  82. data/vendor/sprockets/test/fixtures/asset/relative/include.js +0 -4
  83. data/vendor/sprockets/test/fixtures/asset/relative/require.js +0 -1
  84. data/vendor/sprockets/test/fixtures/asset/relative/require_outside_path.js +0 -1
  85. data/vendor/sprockets/test/fixtures/asset/require_self.css +0 -9
  86. data/vendor/sprockets/test/fixtures/asset/require_self_twice.css +0 -8
  87. data/vendor/sprockets/test/fixtures/asset/semicolons/bar.js +0 -1
  88. data/vendor/sprockets/test/fixtures/asset/semicolons/index.js +0 -5
  89. data/vendor/sprockets/test/fixtures/asset/sprite.css.erb +0 -12
  90. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/d.js +0 -2
  91. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c/e.js +0 -1
  92. data/vendor/sprockets/test/fixtures/asset/tree/all/b/c.js +0 -1
  93. data/vendor/sprockets/test/fixtures/asset/tree/all/b.css +0 -2
  94. data/vendor/sprockets/test/fixtures/asset/tree/all/b.js.erb +0 -1
  95. data/vendor/sprockets/test/fixtures/asset/tree/all/d/c.js.coffee +0 -1
  96. data/vendor/sprockets/test/fixtures/asset/tree/all/d/e.js +0 -1
  97. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require.js +0 -7
  98. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_directory.js +0 -1
  99. data/vendor/sprockets/test/fixtures/asset/tree/all_with_require_tree.js +0 -2
  100. data/vendor/sprockets/test/fixtures/asset/tree/directory/application.js +0 -2
  101. data/vendor/sprockets/test/fixtures/asset/tree/directory/bar.js +0 -1
  102. data/vendor/sprockets/test/fixtures/asset/tree/directory/foo.js +0 -1
  103. data/vendor/sprockets/test/fixtures/asset/tree/tree/application.js +0 -2
  104. data/vendor/sprockets/test/fixtures/asset/tree/tree/bar.js +0 -1
  105. data/vendor/sprockets/test/fixtures/asset/tree/tree/foo.js +0 -1
  106. data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/a/a.js +0 -1
  107. data/vendor/sprockets/test/fixtures/asset/tree/with_logical_path/require_tree_with_logical_path.js +0 -1
  108. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/a.js +0 -1
  109. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/b.js +0 -1
  110. data/vendor/sprockets/test/fixtures/asset/tree/without_argument/require_tree_without_argument.js +0 -1
  111. data/vendor/sprockets/test/fixtures/asset/two.css +0 -1
  112. data/vendor/sprockets/test/fixtures/asset/unicode.js +0 -2
  113. data/vendor/sprockets/test/fixtures/asset/unknownexts.min.js +0 -2
  114. data/vendor/sprockets/test/fixtures/asset/users.js.erb.str +0 -4
  115. data/vendor/sprockets/test/fixtures/context/POW.png +0 -0
  116. data/vendor/sprockets/test/fixtures/context/application.js.yml +0 -3
  117. data/vendor/sprockets/test/fixtures/context/bar.js +0 -1
  118. data/vendor/sprockets/test/fixtures/context/foo.js +0 -2
  119. data/vendor/sprockets/test/fixtures/context/helpers.css.erb +0 -3
  120. data/vendor/sprockets/test/fixtures/context/properties.js.erb +0 -7
  121. data/vendor/sprockets/test/fixtures/context/require_glob.js +0 -1
  122. data/vendor/sprockets/test/fixtures/context/resolve_content_type.js.erb +0 -4
  123. data/vendor/sprockets/test/fixtures/context/sprite.css.embed +0 -3
  124. data/vendor/sprockets/test/fixtures/default/application.js.coffee +0 -4
  125. data/vendor/sprockets/test/fixtures/default/blank.gif +0 -0
  126. data/vendor/sprockets/test/fixtures/default/coffee/foo.coffee +0 -1
  127. data/vendor/sprockets/test/fixtures/default/coffee/index.js +0 -3
  128. data/vendor/sprockets/test/fixtures/default/empty +0 -0
  129. data/vendor/sprockets/test/fixtures/default/gallery.css.erb +0 -3
  130. data/vendor/sprockets/test/fixtures/default/gallery.js +0 -1
  131. data/vendor/sprockets/test/fixtures/default/goodbye.jst.eco +0 -1
  132. data/vendor/sprockets/test/fixtures/default/hello.jst.ejs +0 -1
  133. data/vendor/sprockets/test/fixtures/default/hello.txt +0 -1
  134. data/vendor/sprockets/test/fixtures/default/interpolation.js +0 -1
  135. data/vendor/sprockets/test/fixtures/default/missing_require.js +0 -1
  136. data/vendor/sprockets/test/fixtures/default/mobile/a.js +0 -1
  137. data/vendor/sprockets/test/fixtures/default/mobile/b.js +0 -1
  138. data/vendor/sprockets/test/fixtures/default/mobile/c.css +0 -1
  139. data/vendor/sprockets/test/fixtures/default/mobile/d.css +0 -1
  140. data/vendor/sprockets/test/fixtures/default/mobile/index.css +0 -3
  141. data/vendor/sprockets/test/fixtures/default/mobile/index.js +0 -1
  142. data/vendor/sprockets/test/fixtures/default/noreturn.js +0 -1
  143. data/vendor/sprockets/test/fixtures/default/project.js.coffee.erb +0 -2
  144. data/vendor/sprockets/test/fixtures/default/with_data_uri.css.erb +0 -3
  145. data/vendor/sprockets/test/fixtures/directives/code_before_comment +0 -3
  146. data/vendor/sprockets/test/fixtures/directives/comment_without_directives +0 -6
  147. data/vendor/sprockets/test/fixtures/directives/directive_word_splitting +0 -6
  148. data/vendor/sprockets/test/fixtures/directives/directives_after_header +0 -16
  149. data/vendor/sprockets/test/fixtures/directives/double_slash +0 -9
  150. data/vendor/sprockets/test/fixtures/directives/hash +0 -8
  151. data/vendor/sprockets/test/fixtures/directives/no_header +0 -2
  152. data/vendor/sprockets/test/fixtures/directives/slash_star +0 -10
  153. data/vendor/sprockets/test/fixtures/directives/slash_star_single +0 -4
  154. data/vendor/sprockets/test/fixtures/directives/space_between_directive_word +0 -2
  155. data/vendor/sprockets/test/fixtures/directives/triple_hash +0 -10
  156. data/vendor/sprockets/test/fixtures/encoding/ascii.js +0 -1
  157. data/vendor/sprockets/test/fixtures/encoding/ascii_utf8.js +0 -2
  158. data/vendor/sprockets/test/fixtures/encoding/utf16.js +0 -0
  159. data/vendor/sprockets/test/fixtures/encoding/utf8.js +0 -1
  160. data/vendor/sprockets/test/fixtures/encoding/utf8_bom.js +0 -1
  161. data/vendor/sprockets/test/fixtures/engines/hello.alert +0 -1
  162. data/vendor/sprockets/test/fixtures/engines/moo.js.str +0 -1
  163. data/vendor/sprockets/test/fixtures/public/compiled-digest-0aa2105d29558f3eb790d411d7d8fb66.js +0 -3
  164. data/vendor/sprockets/test/fixtures/public/compiled-digest-1c41eb0cf934a0c76babe875f982f9d1.js +0 -1
  165. data/vendor/sprockets/test/fixtures/server/app/javascripts/application.js +0 -5
  166. data/vendor/sprockets/test/fixtures/server/app/javascripts/bar.js +0 -1
  167. data/vendor/sprockets/test/fixtures/server/app/javascripts/foo.js +0 -1
  168. data/vendor/sprockets/test/fixtures/server/app/javascripts/hello.txt +0 -2
  169. data/vendor/sprockets/test/fixtures/server/app/javascripts/tree.js +0 -1
  170. data/vendor/sprockets/test/fixtures/server/vendor/javascripts/missing_require.js +0 -1
  171. data/vendor/sprockets/test/fixtures/server/vendor/stylesheets/missing_require.css +0 -1
  172. data/vendor/sprockets/test/sprockets_test.rb +0 -56
  173. data/vendor/sprockets/test/test_asset.rb +0 -699
  174. data/vendor/sprockets/test/test_asset_attributes.rb +0 -150
  175. data/vendor/sprockets/test/test_caching.rb +0 -62
  176. data/vendor/sprockets/test/test_context.rb +0 -115
  177. data/vendor/sprockets/test/test_directive_processor.rb +0 -124
  178. data/vendor/sprockets/test/test_encoding.rb +0 -65
  179. data/vendor/sprockets/test/test_engines.rb +0 -73
  180. data/vendor/sprockets/test/test_environment.rb +0 -587
  181. data/vendor/sprockets/test/test_server.rb +0 -227
@@ -1,126 +0,0 @@
1
- require 'sprockets/bundled_asset'
2
- require 'sprockets/static_asset'
3
-
4
- module Sprockets
5
- # `Caching` is an internal mixin whose public methods are exposed on
6
- # the `Environment` and `Index` classes.
7
- module Caching
8
- # Return `Asset` instance for serialized `Hash`.
9
- def asset_from_hash(hash)
10
- return unless hash.is_a?(Hash)
11
- case hash['class']
12
- when 'BundledAsset'
13
- BundledAsset.from_hash(self, hash)
14
- when 'StaticAsset'
15
- StaticAsset.from_hash(self, hash)
16
- else
17
- nil
18
- end
19
- end
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
-
32
- protected
33
- # Cache helper method. Takes a `path` argument which maybe a
34
- # logical path or fully expanded path. The `&block` is passed
35
- # for finding and building the asset if its not in cache.
36
- def cache_asset(path)
37
- # If `cache` is not set, return fast
38
- if cache.nil?
39
- yield
40
-
41
- # Check cache for `path`
42
- elsif (asset = asset_from_hash(cache_get_hash(path.to_s, digest.hexdigest))) && asset.fresh?
43
- asset
44
-
45
- # Otherwise yield block that slowly finds and builds the asset
46
- elsif asset = yield
47
- hash = {}
48
- asset.encode_with(hash)
49
-
50
- # Save the asset to at its path
51
- cache_set_hash(path.to_s, digest.hexdigest, hash)
52
-
53
- # Since path maybe a logical or full pathname, save the
54
- # asset its its full path too
55
- if path.to_s != asset.pathname.to_s
56
- cache_set_hash(asset.pathname.to_s, digest.hexdigest, hash)
57
- end
58
-
59
- asset
60
- end
61
- end
62
-
63
- private
64
- def cache_key_namespace
65
- 'sprockets'
66
- end
67
-
68
- # Removes `Environment#root` from key and prepends
69
- # `Environment#cache_key_namespace`.
70
- def cache_key_for(key)
71
- File.join(cache_key_namespace, key.sub(root, ''))
72
- end
73
-
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
78
- end
79
- end
80
-
81
- def cache_set_hash(key, version, hash)
82
- hash['_version'] = version
83
- cache_set(cache_key_for(key), hash)
84
- hash
85
- end
86
-
87
- # Low level cache getter for `key`. Checks a number of supported
88
- # cache interfaces.
89
- def cache_get(key)
90
- # `Cache#get(key)` for Memcache
91
- if cache.respond_to?(:get)
92
- cache.get(key)
93
-
94
- # `Cache#[key]` so `Hash` can be used
95
- elsif cache.respond_to?(:[])
96
- cache[key]
97
-
98
- # `Cache#read(key)` for `ActiveSupport::Cache` support
99
- elsif cache.respond_to?(:read)
100
- cache.read(key)
101
-
102
- else
103
- nil
104
- end
105
- end
106
-
107
- # Low level cache setter for `key`. Checks a number of supported
108
- # cache interfaces.
109
- def cache_set(key, value)
110
- # `Cache#set(key, value)` for Memcache
111
- if cache.respond_to?(:set)
112
- cache.set(key, value)
113
-
114
- # `Cache#[key]=value` so `Hash` can be used
115
- elsif cache.respond_to?(:[]=)
116
- cache[key] = value
117
-
118
- # `Cache#write(key, value)` for `ActiveSupport::Cache` support
119
- elsif cache.respond_to?(:write)
120
- cache.write(key, value)
121
- end
122
-
123
- value
124
- end
125
- end
126
- end
@@ -1,41 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- # Some browsers have issues with stylesheets that contain multiple
5
- # `@charset` definitions. The issue surfaces while using Sass since
6
- # it inserts a `@charset` at the top of each file. Then Sprockets
7
- # concatenates them together.
8
- #
9
- # The `CharsetNormalizer` processor strips out multiple `@charset`
10
- # definitions.
11
- #
12
- # The current implementation is naive. It picks the first `@charset`
13
- # it sees and strips the others. This works for most people because
14
- # the other definitions are usually `UTF-8`. A more sophisticated
15
- # approach would be to re-encode stylesheets with mixed encodings.
16
- #
17
- # This behavior can be disabled with:
18
- #
19
- # environment.unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
20
- #
21
- class CharsetNormalizer < Tilt::Template
22
- def prepare
23
- end
24
-
25
- def evaluate(context, locals, &block)
26
- charset = nil
27
-
28
- # Find and strip out any `@charset` definitions
29
- filtered_data = data.gsub(/^@charset "([^"]+)";$/) {
30
- charset ||= $1; ""
31
- }
32
-
33
- if charset
34
- # If there was a charset, move it to the top
35
- "@charset \"#{charset}\";#{filtered_data}"
36
- else
37
- data
38
- end
39
- end
40
- end
41
- end
@@ -1,221 +0,0 @@
1
- require 'base64'
2
- require 'rack/utils'
3
- require 'sprockets/errors'
4
- require 'sprockets/utils'
5
- require 'pathname'
6
- require 'set'
7
-
8
- module Sprockets
9
- # `Context` provides helper methods to all `Tilt` processors. They
10
- # are typically accessed by ERB templates. You can mix in custom
11
- # helpers by injecting them into `Environment#context_class`. Do not
12
- # mix them into `Context` directly.
13
- #
14
- # environment.instance_eval do
15
- # include MyHelper
16
- # def asset_url; end
17
- # end
18
- #
19
- # <%= asset_url "foo.png" %>
20
- #
21
- # The `Context` also collects dependencies declared by
22
- # assets. See `DirectiveProcessor` for an example of this.
23
- class Context
24
- attr_reader :environment, :pathname
25
- attr_reader :_required_paths, :_dependency_paths, :_dependency_assets
26
- attr_writer :__LINE__
27
-
28
- def initialize(environment, logical_path, pathname)
29
- @environment = environment
30
- @logical_path = logical_path
31
- @pathname = pathname
32
- @__LINE__ = nil
33
-
34
- @_required_paths = []
35
- @_dependency_paths = Set.new([pathname.to_s])
36
- @_dependency_assets = Set.new
37
- end
38
-
39
- # Returns the environment path that contains the file.
40
- #
41
- # If `app/javascripts` and `app/stylesheets` are in your path, and
42
- # current file is `app/javascripts/foo/bar.js`, `root_path` would
43
- # return `app/javascripts`.
44
- def root_path
45
- environment.paths.detect { |path| pathname.to_s[path] }
46
- end
47
-
48
- # Returns logical path without any file extensions.
49
- #
50
- # 'app/javascripts/application.js'
51
- # # => 'application'
52
- #
53
- def logical_path
54
- @logical_path[/^([^.]+)/, 0]
55
- end
56
-
57
- # Returns content type of file
58
- #
59
- # 'application/javascript'
60
- # 'text/css'
61
- #
62
- def content_type
63
- environment.content_type_of(pathname)
64
- end
65
-
66
- # Given a logical path, `resolve` will find and return the fully
67
- # expanded path. Relative paths will also be resolved. An optional
68
- # `:content_type` restriction can be supplied to restrict the
69
- # search.
70
- #
71
- # resolve("foo.js")
72
- # # => "/path/to/app/javascripts/foo.js"
73
- #
74
- # resolve("./bar.js")
75
- # # => "/path/to/app/javascripts/bar.js"
76
- #
77
- def resolve(path, options = {}, &block)
78
- pathname = Pathname.new(path)
79
- attributes = environment.attributes_for(pathname)
80
-
81
- if pathname.absolute?
82
- pathname
83
-
84
- elsif content_type = options[:content_type]
85
- content_type = self.content_type if content_type == :self
86
-
87
- if attributes.format_extension
88
- if content_type != attributes.content_type
89
- raise ContentTypeMismatch, "#{path} is " +
90
- "'#{attributes.content_type}', not '#{content_type}'"
91
- end
92
- end
93
-
94
- resolve(path) do |candidate|
95
- if self.content_type == environment.content_type_of(candidate)
96
- return candidate
97
- end
98
- end
99
-
100
- raise FileNotFound, "couldn't find file '#{path}'"
101
- else
102
- environment.resolve(path, :base_path => self.pathname.dirname, &block)
103
- end
104
- end
105
-
106
- # `depend_on` allows you to state a dependency on a file without
107
- # including it.
108
- #
109
- # This is used for caching purposes. Any changes made to
110
- # the dependency file with invalidate the cache of the
111
- # source file.
112
- def depend_on(path)
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)
152
- end
153
-
154
- # Reads `path` and runs processors on the file.
155
- #
156
- # This allows you to capture the result of an asset and include it
157
- # directly in another.
158
- #
159
- # <%= evaluate "bar.js" %>
160
- #
161
- def evaluate(path, options = {})
162
- start_time = Time.now.to_f
163
- pathname = resolve(path)
164
- attributes = environment.attributes_for(pathname)
165
- processors = options[:processors] || attributes.processors
166
-
167
- if options[:data]
168
- result = options[:data]
169
- else
170
- result = Sprockets::Utils.read_unicode(pathname)
171
- end
172
-
173
- processors.each do |processor|
174
- begin
175
- template = processor.new(pathname.to_s) { result }
176
- result = template.render(self, {})
177
- rescue Exception => e
178
- annotate_exception! e
179
- raise
180
- end
181
- end
182
-
183
- elapsed_time = ((Time.now.to_f - start_time) * 1000).to_i
184
- logger.info "Compiled #{attributes.pretty_path} (#{elapsed_time}ms) (pid #{Process.pid})"
185
-
186
- result
187
- end
188
-
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.
192
- #
193
- # Use `asset_data_uri` from ERB with CSS or JavaScript assets:
194
- #
195
- # #logo { background: url(<%= asset_data_uri 'logo.png' %>) }
196
- #
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)}"
204
- end
205
-
206
- private
207
- # Annotates exception backtrace with the original template that
208
- # the exception was raised in.
209
- def annotate_exception!(exception)
210
- location = pathname.to_s
211
- location << ":#{@__LINE__}" if @__LINE__
212
-
213
- exception.extend(Sprockets::EngineError)
214
- exception.sprockets_annotation = " (in #{location})"
215
- end
216
-
217
- def logger
218
- environment.logger
219
- end
220
- end
221
- end
@@ -1,73 +0,0 @@
1
- module Sprockets
2
- # `Digest` is an internal mixin whose public methods are exposed on
3
- # the `Environment` and `Index` classes.
4
- module Digest
5
- # Returns a `Digest` implementation class.
6
- #
7
- # Defaults to `Digest::MD5`.
8
- def digest_class
9
- @digest_class
10
- end
11
-
12
- # Assign a `Digest` implementation class. This maybe any Ruby
13
- # `Digest::` implementation such as `Digest::MD5` or
14
- # `Digest::SHA1`.
15
- #
16
- # environment.digest_class = Digest::SHA1
17
- #
18
- def digest_class=(klass)
19
- expire_index!
20
- @digest_class = klass
21
- end
22
-
23
- # The `Environment#version` is a custom value used for manually
24
- # expiring all asset caches.
25
- #
26
- # Sprockets is able to track most file and directory changes and
27
- # will take care of expiring the cache for you. However, its
28
- # impossible to know when any custom helpers change that you mix
29
- # into the `Context`.
30
- #
31
- # It would be wise to increment this value anytime you make a
32
- # configuration change to the `Environment` object.
33
- def version
34
- @version
35
- end
36
-
37
- # Assign an environment version.
38
- #
39
- # environment.version = '2.0'
40
- #
41
- def version=(version)
42
- expire_index!
43
- @version = version
44
- end
45
-
46
- # Returns a `Digest` instance for the `Environment`.
47
- #
48
- # This value serves two purposes. If two `Environment`s have the
49
- # same digest value they can be treated as equal. This is more
50
- # useful for comparing environment states between processes rather
51
- # than in the same. Two equal `Environment`s can share the same
52
- # cached assets.
53
- #
54
- # The value also provides a seed digest for all `Asset`
55
- # digests. Any change in the environment digest will affect all of
56
- # its assets.
57
- def digest
58
- # Recompute digest for the first time or again after its been cleared
59
- @digest ||= compute_digest
60
-
61
- # Returned a dupped copy so the caller can safely mutate it with `.update`
62
- @digest.dup
63
- end
64
-
65
- protected
66
- def compute_digest
67
- # Compute the initial digest using the implementation
68
- # class. The Sprockets release version and custom environment
69
- # version are mixed in.
70
- digest_class.new.update(VERSION).update(version.to_s)
71
- end
72
- end
73
- end