Class: StyleInliner

Inherits:
Inliner show all
Defined in:
lib/hldr/inliners/style_inliner.rb

Class Method Summary collapse

Methods inherited from Inliner

getContent, get_image_extension

Class Method Details

.embed(element) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/hldr/inliners/style_inliner.rb', line 4

def StyleInliner.embed(element)

    # try to retrieve content
    content = getContent(element[:href])
    return if content[:data].nil?

    # keep media and type; remove all other params
    whitelist = ["type", "media"]
    element.attributes.each do |key, val|
        if !whitelist.include?(key)
            element.attributes[key].remove
        end
    end

    # force rel type to style if null
    element[:type] = "text/css" if 
        element[:type].nil? || element[:type] == ""

    # rename tag to style
    element.name = "style"

    # embed content
    element.content = content[:data]

end