Class: RhetButler::Stasis::CSSTransform

Inherits:
DocumentTransform show all
Defined in:
lib/rhet-butler/stasis/css-transform.rb

Instance Attribute Summary

Attributes inherited from DocumentTransform

#document, #queue, #target_path

Instance Method Summary collapse

Methods inherited from DocumentTransform

#document_source, #get_link_translation, #process, register, #save_document

Instance Method Details

#parse_documentObject



8
9
10
# File 'lib/rhet-butler/stasis/css-transform.rb', line 8

def parse_document
  @parsed = Crass::parse(document.body)
end

#render_documentObject



51
52
53
# File 'lib/rhet-butler/stasis/css-transform.rb', line 51

def render_document
  Crass::Parser.stringify(@parsed)
end


42
43
44
45
46
47
48
49
# File 'lib/rhet-butler/stasis/css-transform.rb', line 42

def translate_links
  url_nodes(@parsed).uniq.each do |node|
    node[:value] = get_link_translation(node[:value]).to_s
    if node[:node] == :url
      node[:raw] = "url(#{node[:value]})"
    end
  end
end

#url_nodes(node_list) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rhet-butler/stasis/css-transform.rb', line 12

def url_nodes(node_list)
  return [] if node_list.nil?

  list = []

  node_list.each do |node|
    case node[:node]
    when :url
      list << node
    when :at_rule
      if node[:name] == "import"
        list += node[:prelude].find_all do |node|
          node[:node] == :url or node[:node] == :string
        end
      else
        children = node
        [:block, :value].each do |key|
          children = children[key]
          break if children.nil?
          break if children.is_a? Array
        end
        list += url_nodes(children)
      end
    else
      list += url_nodes(node[:children])
    end
  end
  return list
end