Class: Garterbelt::ContentTag

Inherits:
ClosedTag show all
Includes:
ContentRendering
Defined in:
lib/renderers/content_tag.rb

Instance Attribute Summary

Attributes inherited from ClosedTag

#attributes, #css_class, #type

Attributes inherited from Renderer

#escape, #style, #view

Instance Method Summary collapse

Methods included from ContentRendering

included

Methods inherited from ClosedTag

#render, #rendered_attributes, #template

Methods inherited from Renderer

#indent, #level, #line_end, #output, #output=, #render

Constructor Details

#initialize(opts, &block) ⇒ ContentTag

Returns a new instance of ContentTag.



5
6
7
8
9
10
11
12
# File 'lib/renderers/content_tag.rb', line 5

def initialize(opts, &block)
  super
  if block_given?
    self.content = block
  else
    self.content = opts[:content]
  end
end

Instance Method Details

#c(*classes, &block) ⇒ Object



20
21
22
23
24
# File 'lib/renderers/content_tag.rb', line 20

def c(*classes, &block)
  super(*classes)
  self.content = block if block_given?
  self
end

#footObject



49
50
51
52
# File 'lib/renderers/content_tag.rb', line 49

def foot
  super
  self.output << foot_template
end

#foot_templateObject



40
41
42
43
44
45
46
47
# File 'lib/renderers/content_tag.rb', line 40

def foot_template
  if style == :text 
    [:p, :ul, :ol, :li].include?(type) ? "\n" : '' 
  else
    foot_dent = style == :compact ? '' : indent
    "#{foot_dent}</#{type}>#{line_end}"
  end
end

#headObject



35
36
37
38
# File 'lib/renderers/content_tag.rb', line 35

def head
  self.output << head_template
  super
end

#head_templateObject



26
27
28
29
30
31
32
33
# File 'lib/renderers/content_tag.rb', line 26

def head_template
  if style == :text 
    ''
  else 
    head_end = style == :compact ? '' : line_end
    "#{indent}<#{type}#{rendered_attributes}>#{head_end}"
  end
end

#id(identifier, &block) ⇒ Object



14
15
16
17
18
# File 'lib/renderers/content_tag.rb', line 14

def id(identifier, &block)
  super(identifier)
  self.content = block if block_given?
  self
end