Module: Muddle::Filter::BoilerplateStyleElement
- Extended by:
- Muddle::Filter
- Defined in:
- lib/muddle/filter/boilerplate_style_element.rb
Class Method Summary
collapse
append_or_insert, find_or_append, find_or_prepend, prepend_or_insert
Class Method Details
.boilerplate_css ⇒ Object
28
29
30
|
# File 'lib/muddle/filter/boilerplate_style_element.rb', line 28
def self.boilerplate_css
@boilerplate_css ||= File.read(File.join(File.dirname(__FILE__), '..', 'resources', 'boilerplate_style.css'))
end
|
.filter(body_string) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/muddle/filter/boilerplate_style_element.rb', line 6
def self.filter(body_string)
doc = Hpricot(body_string)
insert_style_block(doc)
doc.to_html
end
|
.insert_style_block(doc) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/muddle/filter/boilerplate_style_element.rb', line 14
def self.insert_style_block(doc)
find_or_append(doc, 'html', :with => '<html></html>') do |html|
find_or_prepend(html.first, 'body', :with => '<body></body>') do |body|
if node = body.search('style:first-of-type()').first
node.before('<style type="text/css"></style>')
else
append_or_insert(body.first, '<style type="text/css"></style>')
end
body.search('style:first-of-type()').inner_html(boilerplate_css)
end
end
end
|