Class: Swordfish::Node::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/swordfish/nodes/image.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#children, #content, #style

Instance Method Summary collapse

Methods inherited from Base

#clear_children, #find_nodes_by_type, #inform!, #initialize, #replace, #replace_with, #stylize, #wrap_children

Constructor Details

This class inherits a constructor from Swordfish::Node::Base

Instance Attribute Details

#captionObject

Returns the value of attribute caption.



16
17
18
# File 'lib/swordfish/nodes/image.rb', line 16

def caption
  @caption
end

#original_nameObject

Returns the value of attribute original_name.



13
14
15
# File 'lib/swordfish/nodes/image.rb', line 13

def original_name
  @original_name
end

#pathObject

Returns the value of attribute path.



15
16
17
# File 'lib/swordfish/nodes/image.rb', line 15

def path
  @path
end

Instance Method Details

#append(node) ⇒ Object

Override Base append because an image node should never have children

Raises:



19
20
21
# File 'lib/swordfish/nodes/image.rb', line 19

def append(node)
  raise BadContentError
end

#to_htmlObject



23
24
25
26
27
# File 'lib/swordfish/nodes/image.rb', line 23

def to_html
  @caption ||= ""
  src = URI::escape(@path ? @path : @original_name)
  "<img src=\"#{src}\" alt=\"#{CGI::escapeHTML(@caption)}\" title=\"#{CGI::escapeHTML(@caption)}\" />"
end