Class: Tungsten::CardHelper::Card

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Card.



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

def initialize( title = nil, options = {} )
  if title && title.is_a?(Hash)
    @options = title
    @title = nil
  else
    @options = options
    @title = title
  end
  @options[:data] ||= {}
  @options[:data][:animate] ||= @options.delete(:animate)
  @options[:class] = "card-section #{@options.delete(:class)} #{"hidden" if @options.delete(:hidden)}".strip
end

Instance Method Details

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



75
76
77
78
79
# File 'app/helpers/tungsten/card_helper.rb', line 75

def actions( options={}, &block )
  options[:class] = "card-actions #{options[:class]}".strip

  ( :nav, options, &block )
end

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



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/helpers/tungsten/card_helper.rb', line 61

def description( text = nil, options = {}, &block )
  if text.is_a? Hash
    options = text
    text = nil
  end

  options[:class] = "card-description #{options[:class]}".strip

  ( :p, options ) {
    concat text unless text.nil?
    concat capture(&block).html_safe if block_given?
  }
end

#display(body) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/tungsten/card_helper.rb', line 18

def display( body )
  ( :section, @options ) do
    ( :div, class: 'card-wrapper toggle-drawer' ) {
      ( :div, class: 'card' ) {
        concat header( @title ) if @title
        if first_header = body.scan(/\A<header.+?header>/m).first
          concat first_header.html_safe
          body = body.sub(first_header, '').html_safe
        end
        concat (:div, class: 'card-content') { body }
      }
    }
  end
end

#divider(options = {}) ⇒ Object



87
88
89
90
91
92
# File 'app/helpers/tungsten/card_helper.rb', line 87

def divider( options={} )
  options[:class] = "card-divider #{options[:class]}".strip

  tag.span(options)

end


47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/tungsten/card_helper.rb', line 47

def footer( text = nil, options = {}, &block )
  if text.is_a? Hash
    options = text
    text = nil
  end

  options[:class] = "card-footer #{options[:class]}".strip

  ( :footer, options ) {
    concat ( :p, text ) unless text.nil?
    concat capture(&block).html_safe if block_given?
  }
end

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



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/tungsten/card_helper.rb', line 33

def header( text = nil, options = {}, &block )
  if text.is_a? Hash
    options = text
    text = nil
  end

  options[:class] = "card-header #{options[:class]}".strip

  ( :header, options ) {
    concat ( :h2, text, class: 'card-heading' ) if text
    concat capture(&block).html_safe if block_given?
  }
end

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



81
82
83
84
85
# File 'app/helpers/tungsten/card_helper.rb', line 81

def well( options={}, &block )
  options[:class] = "card-well #{options[:class]}".strip

  ( :div, options, &block )
end