Class: TwitterBootstrapMarkup::Tag

Inherits:
Object
  • Object
show all
Includes:
Popover, SidePosition, Tooltip
Defined in:
lib/twitter_bootstrap_markup/tag.rb

Constant Summary

Constants included from Popover

Popover::POSITIONS

Constants included from Tooltip

TwitterBootstrapMarkup::Tooltip::POSITIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SidePosition

#pull_left, #pull_right

Methods included from Popover

#popover

Methods included from Tooltip

#tooltip

Constructor Details

#initialize(*args, &block) ⇒ Tag

Returns a new instance of Tag.



23
24
25
26
27
28
29
30
31
# File 'lib/twitter_bootstrap_markup/tag.rb', line 23

def initialize(*args, &block)
  @name = args.shift
  content = args.shift unless args.first.is_a?(Hash)
  @attributes = args.shift || {}
  @children = []
  @is_block = content || block_given?
  append content if content
  evaluate(&block) if block_given?
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



8
9
10
# File 'lib/twitter_bootstrap_markup/tag.rb', line 8

def attributes
  @attributes
end

#childrenObject (readonly)

Returns the value of attribute children.



9
10
11
# File 'lib/twitter_bootstrap_markup/tag.rb', line 9

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/twitter_bootstrap_markup/tag.rb', line 7

def name
  @name
end

Class Method Details

.block(*args, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/twitter_bootstrap_markup/tag.rb', line 15

def self.block(*args, &block)
  if block_given?
    Tag.new(*args, &block)
  else
    Tag.new(*args) {}
  end
end

.inline(name, attributes = {}) ⇒ Object



11
12
13
# File 'lib/twitter_bootstrap_markup/tag.rb', line 11

def self.inline(name, attributes={})
  Tag.new(name, attributes)
end

Instance Method Details

#append(element = nil, &block) ⇒ Object



33
34
35
36
37
# File 'lib/twitter_bootstrap_markup/tag.rb', line 33

def append(element=nil, &block)
  element = evaluate(&block) if block_given?
  @children << element
  element
end

#prepend(element) ⇒ Object



39
40
41
# File 'lib/twitter_bootstrap_markup/tag.rb', line 39

def prepend(element)
  @children.insert 0, element
end

#to_sObject



43
44
45
46
47
48
49
50
# File 'lib/twitter_bootstrap_markup/tag.rb', line 43

def to_s
  attributes_markup = attributes.empty? ? '' : " #{attributes.map{|key, value| "#{key}#{value ? "=\"#{value}\"" : ''}"}.join(' ')}"
  if @is_block
    "<#{name}#{attributes_markup}>#{children.map(&:to_s).join}</#{name}>"
  else
    "<#{name}#{attributes_markup}>"
  end
end