Class: Html::Base

Inherits:
Object show all
Defined in:
lib/html/base.rb

Overview

The base Html class provides functionality for wrapping HTML tags, e.g. <div>…</div>

Direct Known Subclasses

Comment, Container, Flag, Item, Link, Span

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attr = {}) ⇒ Base

Returns a new instance of Base.



44
45
46
# File 'lib/html/base.rb', line 44

def initialize(attr={})
  @attr = attr
end

Class Method Details

.tagObject



49
50
51
# File 'lib/html/base.rb', line 49

def self.tag
  @tag
end

Instance Method Details

#<<(other) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/html/base.rb', line 65

def << (other)
  if other.is_a?(String)
    processed_output(other)
  else
    Composite.new(self, other)
  end
end

#attributesObject



57
58
59
# File 'lib/html/base.rb', line 57

def attributes
  @attr.length == 0 ? "" : @attr.collect {|key, value| " #{key.to_s}='#{value}'"}.join
end

#processed_output(contents) ⇒ Object



61
62
63
# File 'lib/html/base.rb', line 61

def processed_output(contents)
  "<#{tag}#{attributes}>#{contents}</#{tag}>"
end

#tagObject



53
54
55
# File 'lib/html/base.rb', line 53

def tag
  self.class.tag
end