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,81 +0,0 @@
1
- require 'sprockets/base'
2
-
3
- module Sprockets
4
- # `Index` is a special cached version of `Environment`.
5
- #
6
- # The expection is that all of its file system methods are cached
7
- # for the instances lifetime. This makes `Index` much faster. This
8
- # behavior is ideal in production environments where the file system
9
- # is immutable.
10
- #
11
- # `Index` should not be initialized directly. Instead use
12
- # `Environment#index`.
13
- class Index < Base
14
- def initialize(environment)
15
- # Copy environment attributes
16
- @logger = environment.logger
17
- @context_class = environment.context_class
18
- @cache = environment.cache
19
- @trail = environment.trail.index
20
- @static_root = environment.static_root
21
- @digest = environment.digest
22
- @digest_class = environment.digest_class
23
- @version = environment.version
24
- @mime_types = environment.mime_types
25
- @engines = environment.engines
26
- @preprocessors = environment.preprocessors
27
- @postprocessors = environment.postprocessors
28
- @bundle_processors = environment.bundle_processors
29
- @engine_formats = environment.engine_formats
30
-
31
- # Initialize caches
32
- @assets = {}
33
- @digests = {}
34
- end
35
-
36
- # No-op return self as index
37
- def index
38
- self
39
- end
40
-
41
- # Cache calls to `file_digest`
42
- def file_digest(pathname, data = nil)
43
- memoize(@digests, pathname.to_s) { super }
44
- end
45
-
46
- # Cache `find_asset` calls
47
- def find_asset(path, options = {})
48
- if asset = @assets[path.to_s]
49
- asset
50
- elsif asset = super
51
- # Cache at logical path and expanded path
52
- @assets[path.to_s] = @assets[asset.pathname.to_s] = asset
53
- asset
54
- end
55
- end
56
-
57
- protected
58
- # Index is immutable, any methods that try to clear the cache
59
- # should bomb.
60
- def expire_index!
61
- raise TypeError, "can't modify immutable index"
62
- end
63
-
64
- # Cache asset building in memory and in persisted cache.
65
- def build_asset(path, pathname, options)
66
- # Memory cache
67
- memoize(@assets, pathname.to_s) do
68
- # Persisted cache
69
- cache_asset(pathname.to_s) do
70
- super
71
- end
72
- end
73
- end
74
-
75
- private
76
- # Simple memoize helper that stores `nil` values
77
- def memoize(hash, key)
78
- hash.key?(key) ? hash[key] : hash[key] = yield
79
- end
80
- end
81
- end
@@ -1,26 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- class JstProcessor < Tilt::Template
5
- def self.default_mime_type
6
- 'application/javascript'
7
- end
8
-
9
- def prepare
10
- end
11
-
12
- def evaluate(scope, locals, &block)
13
- <<-JST
14
- (function() {
15
- this.JST || (this.JST = {});
16
- this.JST[#{scope.logical_path.inspect}] = #{indent(data)};
17
- }).call(this);
18
- JST
19
- end
20
-
21
- private
22
- def indent(string)
23
- string.gsub(/$(.)/m, "\\1 ").strip
24
- end
25
- end
26
- end
@@ -1,38 +0,0 @@
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,269 +0,0 @@
1
- require 'sprockets/engines'
2
- require 'sprockets/mime'
3
- require 'sprockets/processor'
4
- require 'sprockets/utils'
5
-
6
- module Sprockets
7
- # `Processing` is an internal mixin whose public methods are exposed on
8
- # the `Environment` and `Index` classes.
9
- module Processing
10
- include Engines, Mime
11
-
12
- # Register a new mime type.
13
- def register_mime_type(mime_type, ext)
14
- # Overrides the global behavior to expire the index
15
- expire_index!
16
- @trail.extensions << ext
17
- super
18
- end
19
-
20
- # Returns an `Array` of format extension `String`s.
21
- #
22
- # format_extensions
23
- # # => ['.js', '.css']
24
- #
25
- def format_extensions
26
- @trail.extensions - @engines.keys
27
- end
28
-
29
- # Registers a new Engine `klass` for `ext`.
30
- def register_engine(ext, klass)
31
- # Overrides the global behavior to expire the index
32
- expire_index!
33
- @trail.extensions << ext.to_s
34
- super
35
- end
36
-
37
- # Deprecated alias for `preprocessors`.
38
- def processors(*args)
39
- preprocessors(*args)
40
- end
41
-
42
- # Returns an `Array` of `Processor` classes. If a `mime_type`
43
- # argument is supplied, the processors registered under that
44
- # extension will be returned.
45
- #
46
- # Preprocessors are ran before Postprocessors and Engine
47
- # processors.
48
- #
49
- # All `Processor`s must follow the `Tilt::Template` interface. It is
50
- # recommended to subclass `Tilt::Template`.
51
- def preprocessors(mime_type = nil)
52
- if mime_type
53
- @preprocessors[mime_type].dup
54
- else
55
- deep_copy_hash(@preprocessors)
56
- end
57
- end
58
-
59
- # Returns an `Array` of `Processor` classes. If a `mime_type`
60
- # argument is supplied, the processors registered under that
61
- # extension will be returned.
62
- #
63
- # Postprocessors are ran after Postprocessors and Engine processors.
64
- #
65
- # All `Processor`s must follow the `Tilt::Template` interface. It is
66
- # recommended to subclass `Tilt::Template`.
67
- def postprocessors(mime_type = nil)
68
- if mime_type
69
- @postprocessors[mime_type].dup
70
- else
71
- deep_copy_hash(@postprocessors)
72
- end
73
- end
74
-
75
- # Deprecated alias for `register_preprocessor`.
76
- def register_processor(*args, &block)
77
- register_preprocessor(*args, &block)
78
- end
79
-
80
- # Registers a new Preprocessor `klass` for `mime_type`.
81
- #
82
- # register_preprocessor 'text/css', Sprockets::DirectiveProcessor
83
- #
84
- # A block can be passed for to create a shorthand processor.
85
- #
86
- # register_preprocessor :my_processor do |context, data|
87
- # data.gsub(...)
88
- # end
89
- #
90
- def register_preprocessor(mime_type, klass, &block)
91
- expire_index!
92
-
93
- if block_given?
94
- name = klass.to_s
95
- klass = Class.new(Processor) do
96
- @name = name
97
- @processor = block
98
- end
99
- end
100
-
101
- @preprocessors[mime_type].push(klass)
102
- end
103
-
104
- # Registers a new Postprocessor `klass` for `mime_type`.
105
- #
106
- # register_postprocessor 'text/css', Sprockets::CharsetNormalizer
107
- #
108
- # A block can be passed for to create a shorthand processor.
109
- #
110
- # register_postprocessor :my_processor do |context, data|
111
- # data.gsub(...)
112
- # end
113
- #
114
- def register_postprocessor(mime_type, klass, &block)
115
- expire_index!
116
-
117
- if block_given?
118
- name = klass.to_s
119
- klass = Class.new(Processor) do
120
- @name = name
121
- @processor = block
122
- end
123
- end
124
-
125
- @postprocessors[mime_type].push(klass)
126
- end
127
-
128
- # Deprecated alias for `unregister_preprocessor`.
129
- def unregister_processor(*args)
130
- unregister_preprocessor(*args)
131
- end
132
-
133
- # Remove Preprocessor `klass` for `mime_type`.
134
- #
135
- # unregister_preprocessor 'text/css', Sprockets::DirectiveProcessor
136
- #
137
- def unregister_preprocessor(mime_type, klass)
138
- expire_index!
139
-
140
- if klass.is_a?(String) || klass.is_a?(Symbol)
141
- klass = @preprocessors[mime_type].detect { |cls|
142
- cls.respond_to?(:name) &&
143
- cls.name == "Sprockets::Processor (#{klass})"
144
- }
145
- end
146
-
147
- @preprocessors[mime_type].delete(klass)
148
- end
149
-
150
- # Remove Postprocessor `klass` for `mime_type`.
151
- #
152
- # unregister_postprocessor 'text/css', Sprockets::DirectiveProcessor
153
- #
154
- def unregister_postprocessor(mime_type, klass)
155
- expire_index!
156
-
157
- if klass.is_a?(String) || klass.is_a?(Symbol)
158
- klass = @postprocessors[mime_type].detect { |cls|
159
- cls.respond_to?(:name) &&
160
- cls.name == "Sprockets::Processor (#{klass})"
161
- }
162
- end
163
-
164
- @postprocessors[mime_type].delete(klass)
165
- end
166
-
167
- # Returns an `Array` of `Processor` classes. If a `mime_type`
168
- # argument is supplied, the processors registered under that
169
- # extension will be returned.
170
- #
171
- # Bundle Processors are ran on concatenated assets rather than
172
- # individual files.
173
- #
174
- # All `Processor`s must follow the `Tilt::Template` interface. It is
175
- # recommended to subclass `Tilt::Template`.
176
- def bundle_processors(mime_type = nil)
177
- if mime_type
178
- @bundle_processors[mime_type].dup
179
- else
180
- deep_copy_hash(@bundle_processors)
181
- end
182
- end
183
-
184
- # Registers a new Bundle Processor `klass` for `mime_type`.
185
- #
186
- # register_bundle_processor 'text/css', Sprockets::CharsetNormalizer
187
- #
188
- # A block can be passed for to create a shorthand processor.
189
- #
190
- # register_bundle_processor :my_processor do |context, data|
191
- # data.gsub(...)
192
- # end
193
- #
194
- def register_bundle_processor(mime_type, klass, &block)
195
- expire_index!
196
-
197
- if block_given?
198
- name = klass.to_s
199
- klass = Class.new(Processor) do
200
- @name = name
201
- @processor = block
202
- end
203
- end
204
-
205
- @bundle_processors[mime_type].push(klass)
206
- end
207
-
208
- # Remove Bundle Processor `klass` for `mime_type`.
209
- #
210
- # unregister_bundle_processor 'text/css', Sprockets::CharsetNormalizer
211
- #
212
- def unregister_bundle_processor(mime_type, klass)
213
- expire_index!
214
-
215
- if klass.is_a?(String) || klass.is_a?(Symbol)
216
- klass = @bundle_processors[mime_type].detect { |cls|
217
- cls.respond_to?(:name) &&
218
- cls.name == "Sprockets::Processor (#{klass})"
219
- }
220
- end
221
-
222
- @bundle_processors[mime_type].delete(klass)
223
- end
224
-
225
- # Return CSS compressor or nil if none is set
226
- def css_compressor
227
- bundle_processors('text/css').detect { |klass|
228
- klass.respond_to?(:name) &&
229
- klass.name == 'Sprockets::Processor (css_compressor)'
230
- }
231
- end
232
-
233
- # Assign a compressor to run on `text/css` assets.
234
- #
235
- # The compressor object must respond to `compress` or `compile`.
236
- def css_compressor=(compressor)
237
- expire_index!
238
-
239
- unregister_bundle_processor 'text/css', :css_compressor
240
- return unless compressor
241
-
242
- register_bundle_processor 'text/css', :css_compressor do |context, data|
243
- compressor.compress(data)
244
- end
245
- end
246
-
247
- # Return JS compressor or nil if none is set
248
- def js_compressor
249
- bundle_processors('application/javascript').detect { |klass|
250
- klass.respond_to?(:name) &&
251
- klass.name == 'Sprockets::Processor (js_compressor)'
252
- }
253
- end
254
-
255
- # Assign a compressor to run on `application/javascript` assets.
256
- #
257
- # The compressor object must respond to `compress` or `compile`.
258
- def js_compressor=(compressor)
259
- expire_index!
260
-
261
- unregister_bundle_processor 'application/javascript', :js_compressor
262
- return unless compressor
263
-
264
- register_bundle_processor 'application/javascript', :js_compressor do |context, data|
265
- compressor.compress(data)
266
- end
267
- end
268
- end
269
- end
@@ -1,32 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- # `Processor` creates an anonymous processor class from a block.
5
- #
6
- # register_preprocessor :my_processor do |context, data|
7
- # # ...
8
- # end
9
- #
10
- class Processor < Tilt::Template
11
- # `processor` is a lambda or block
12
- def self.processor
13
- @processor
14
- end
15
-
16
- def self.name
17
- "Sprockets::Processor (#{@name})"
18
- end
19
-
20
- def self.to_s
21
- name
22
- end
23
-
24
- def prepare
25
- end
26
-
27
- # Call processor block with `context` and `data`.
28
- def evaluate(context, locals)
29
- self.class.processor.call(context, data)
30
- end
31
- end
32
- end
@@ -1,28 +0,0 @@
1
- require 'tilt'
2
-
3
- module Sprockets
4
- # For JS developers who are colonfobic, concatenating JS files using
5
- # the module pattern usually leads to syntax errors.
6
- #
7
- # The `SafetyColons` processor will insert missing semicolons to the
8
- # end of the file.
9
- #
10
- # This behavior can be disabled with:
11
- #
12
- # environment.unregister_postprocessor 'application/javascript', Sprockets::SafetyColons
13
- #
14
- class SafetyColons < Tilt::Template
15
- def prepare
16
- end
17
-
18
- def evaluate(context, locals, &block)
19
- # If the file is blank or ends in a semicolon, leave it as is
20
- if data =~ /\A\s*\Z/m || data =~ /;\s*\Z/m
21
- data
22
- else
23
- # Otherwise, append a semicolon and newline
24
- "#{data};\n"
25
- end
26
- end
27
- end
28
- end