Class: RuBB::Node::Image

Inherits:
RuBB::Node show all
Defined in:
lib/rubb/node/image.rb

Instance Attribute Summary collapse

Attributes inherited from RuBB::Node

#children

Instance Method Summary collapse

Methods inherited from RuBB::Node

#<<

Constructor Details

#initialize(options = {}) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
# File 'lib/rubb/node/image.rb', line 7

def initialize(options={})
  super(options)
  @width = options[:width]
  @height = options[:height]
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/rubb/node/image.rb', line 5

def height
  @height
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/rubb/node/image.rb', line 4

def width
  @width
end

Instance Method Details

#to_htmlObject



13
14
15
16
17
18
19
20
21
# File 'lib/rubb/node/image.rb', line 13

def to_html
  if(@width && @height)
    url = Parser.escape_quotes(@children.map {|c| c ? c.to_html : '' }.join)
    html = "<img src=\"#{url}\" style=\"width: #{@width}px; height: #{@height}px;\" alt=\"\" />"
  else
    url = Parser.escape_quotes(@children.map {|c| c ? c.to_html : '' }.join)
    html = "<img src=\"#{url}\" alt=\"\" />"
  end
end