Class: CssParser::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/webpage-archivist/stylesheet_document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#importsObject (readonly)

Returns the value of attribute imports.



16
17
18
# File 'lib/webpage-archivist/stylesheet_document.rb', line 16

def imports
  @imports
end

Instance Method Details

#add_block_archivist(block, options = {}) ⇒ Object

Adapted from add_block! so the imports are listed instead of fetched



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/webpage-archivist/stylesheet_document.rb', line 29

def add_block_archivist(block, options = {})
  @imports ||= []

  options = {:base_uri => nil, :base_dir => nil, :charset => nil, :media_types => :all, :only_media_types => :all}.merge(options)
  options[:media_types] = [options[:media_types]].flatten
  options[:only_media_types] = [options[:only_media_types]].flatten

  block = cleanup_block(block)

  if options[:base_uri] and @options[:absolute_paths]
    block = CssParser.convert_uris(block, options[:base_uri])
  end

  # List @imported CSS
  block.scan(RE_AT_IMPORT_RULE).each do |import_rule|
    imports << import_rule[0].to_s.gsub(/['"]*/, '').strip
  end

  block.gsub!(RE_AT_IMPORT_RULE, '')

  parse_block_into_rule_sets!(block, options)
end

#to_s(media_types = :all) ⇒ Object

Add the imports first



19
20
21
22
23
24
25
26
# File 'lib/webpage-archivist/stylesheet_document.rb', line 19

def to_s(media_types = :all)
  out = imports ? "#{imports.collect { |i| "@import url(\"#{i}\");" }.join("\n")}\n\n" : ''

  each_selector(media_types) do |selectors, declarations, specificity|
    out << "#{selectors} {\n#{declarations}\n}\n"
  end
  out
end