Class: CssRewrite::Postprocessor
- Inherits:
-
Object
- Object
- CssRewrite::Postprocessor
- Defined in:
- lib/css-rewrite/postprocessor.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename, &block) ⇒ Postprocessor
constructor
A new instance of Postprocessor.
- #render(context, empty_hash_wtf) ⇒ Object
Constructor Details
#initialize(filename, &block) ⇒ Postprocessor
Returns a new instance of Postprocessor.
63 64 65 66 |
# File 'lib/css-rewrite/postprocessor.rb', line 63 def initialize(filename, &block) @filename = filename @source = block.call end |
Class Method Details
.call(input) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/css-rewrite/postprocessor.rb', line 25 def call(input) filename = input[:filename] source = input[:data] context = input[:environment].context_class.new(input) result = run(filename, source, context) context..merge(data: result) end |
.run(filename, source, context) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/css-rewrite/postprocessor.rb', line 6 def run(filename, source, context) rewriters = find_rewriters(filename) return source if rewriters.empty? tree = Crass.parse(source, preserve_comments: true) replace_urls(tree) do |url| rewritten_url = nil rewriters.each do |rewriter| rewritten_url = rewriter.rewrite(url) break if rewritten_url end rewritten_url || url end Crass::Parser.stringify(tree) end |
Instance Method Details
#render(context, empty_hash_wtf) ⇒ Object
68 69 70 |
# File 'lib/css-rewrite/postprocessor.rb', line 68 def render(context, empty_hash_wtf) self.class.run(@filename, @source, context) end |