Class: Tungsten::SectionHelper::Section

Inherits:
Helper
  • Object
show all
Defined in:
app/helpers/tungsten/section_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(title = nil, options = {}) ⇒ Section

Returns a new instance of Section.



5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/tungsten/section_helper.rb', line 5

def initialize( title = nil, options = {} )
  if title.is_a? Hash
    @options = title
    @title = nil
  else
    @options = options
    @title = title
  end

  @id = @options[:id]
end

Instance Method Details

#content(options = {}, &block) ⇒ Object



45
46
47
# File 'app/helpers/tungsten/section_helper.rb', line 45

def content( options={}, &block )
  ( :div, class: 'app-section-content', &block )
end

#display(body) ⇒ Object



17
18
19
20
21
22
23
# File 'app/helpers/tungsten/section_helper.rb', line 17

def display( body )
  ( :section, @options ) do
    @options[:class] = "app-section #{@options[:class]} #{"hidden" if @options.delete(:hidden)}".strip
    concat title( @title ) if @title
    concat body
  end
end

#heading(text, options = {}) ⇒ Object



39
40
41
42
43
# File 'app/helpers/tungsten/section_helper.rb', line 39

def heading( text, options={})
  options[:class] ||= ''
  options[:class] << ' app-section-heading'
  ( :h2, text, options )
end

#title(text = nil, options = {}, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/tungsten/section_helper.rb', line 25

def title( text = nil, options = {}, &block )
  options[:class] = "app-section-title #{options[:class]}".strip

  if text
    text = ( :a, text, href: "##{@id}", class: 'app-section-title-anchor' ) unless @id.nil?
    text = heading(text)
  end

  tag = ( :div, options ) {
    concat text
    concat ( :div, class: 'app-section-description', &block) if block_given?
  }
end