Class: CssRewrite::Postprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/css-rewrite/postprocessor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, &block) ⇒ Postprocessor

Returns a new instance of Postprocessor.



49
50
51
52
# File 'lib/css-rewrite/postprocessor.rb', line 49

def initialize(filename, &block)
  @filename = filename
  @source = block.call
end

Class Method Details

.call(input) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/css-rewrite/postprocessor.rb', line 17

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
# File 'lib/css-rewrite/postprocessor.rb', line 6

def run(filename, source, context)
  tree = Crass.parse(source, preserve_comments: true)

  replace_urls(tree) do |url|
    rewriter = Config.instance.rewriters.find { |re| re.matches?(url) }
    rewriter ? rewriter.rewrite(url, filename) : url
  end

  Crass::Parser.stringify(tree)
end

Instance Method Details

#render(context, empty_hash_wtf) ⇒ Object



54
55
56
# File 'lib/css-rewrite/postprocessor.rb', line 54

def render(context, empty_hash_wtf)
  self.class.run(@filename, @source, context)
end