Class: InlineSVG

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-inline_svg/inline_svg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ InlineSVG

Returns a new instance of InlineSVG.



6
7
8
9
10
# File 'lib/middleman-inline_svg/inline_svg.rb', line 6

def initialize(file, options = {})
  @file = file
  @title = options.delete(:title)
  @options = options
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/middleman-inline_svg/inline_svg.rb', line 4

def file
  @file
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/middleman-inline_svg/inline_svg.rb', line 4

def options
  @options
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/middleman-inline_svg/inline_svg.rb', line 4

def title
  @title
end

Instance Method Details

#to_htmlObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/middleman-inline_svg/inline_svg.rb', line 12

def to_html
  doc = asset_doc(file)
  svg = doc.at_css("svg")

  if title
    add_title(doc, svg, title)
  end

  options.each do |key, value|
    svg[key.to_s.tr("_", "-")] = value
  end

  doc.to_html
end