Class: Formidable::Renderers::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/formidable/renderers/string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element, &rendering_block) ⇒ Renderer

Returns a new instance of Renderer.



8
9
10
# File 'lib/formidable/renderers/string.rb', line 8

def initialize(element, &rendering_block)
  @element, @rendering_block = element, rendering_block
end

Instance Attribute Details

#elementObject (readonly)

Returns the value of attribute element.



7
8
9
# File 'lib/formidable/renderers/string.rb', line 7

def element
  @element
end

#rendering_blockObject (readonly)

Returns the value of attribute rendering_block.



7
8
9
# File 'lib/formidable/renderers/string.rb', line 7

def rendering_block
  @rendering_block
end

Instance Method Details

#renderObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/formidable/renderers/string.rb', line 20

def render
  raise NotImplementedError, "You are supposed to redefine #render method in subclasses of Renderer"
end

#self_close_tag(name, attributes = nil) ⇒ Object



16
17
18
# File 'lib/formidable/renderers/string.rb', line 16

def self_close_tag(name, attributes = nil)
  "<#{name}#{hash_to_attributes_string(attributes) if attributes} />"
end

#tag(name, attributes = nil, &block) ⇒ Object



12
13
14
# File 'lib/formidable/renderers/string.rb', line 12

def tag(name, attributes = nil, &block)
  "<#{name}#{hash_to_attributes_string(attributes) if attributes}>#{block.call if block}</#{name}>"
end