Class: Tungsten::TableHelper::TableDrawer

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

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TableDrawer

Returns a new instance of TableDrawer.



20
21
22
23
24
# File 'app/helpers/tungsten/table_helper.rb', line 20

def initialize( options = {} )
  @options = options
  @id = "handle-#{SecureRandom.hex(5)}"
  @drawer_id = "drawer-#{SecureRandom.hex(5)}"
end

Instance Method Details

#close(&block) ⇒ Object



45
46
47
48
49
50
# File 'app/helpers/tungsten/table_helper.rb', line 45

def close( &block )
  capture(&block).sub(/>/, " role='button' \
                      data-hide=\"##{@drawer_id}\" \
                      data-remove-class=\"open; ##{@id}\" \
                      data-add-class=\"closed; ##{@id}\">").html_safe
end

#display(body) ⇒ Object



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

def display( body )
  options = {
    class: 'table-drawer-handle',
    id: @id,
  }
  options[:data] ||= {}

  options[:data]['toggle-class'] = 'open closed'
  options[:data]['toggle'] = "##{@drawer_id}"
  options[:role] = 'button'
  options[:class] << ' toggle-handle closed'
  (:tr, options) { body }
end

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



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

def drawer(options={}, &block)
  options[:animate] = 'drawer'
  tr_drawer(@drawer_id, options, &block)
end

#drawer_idObject



65
66
67
# File 'app/helpers/tungsten/table_helper.rb', line 65

def drawer_id
  @id
end

#idObject



69
70
71
# File 'app/helpers/tungsten/table_helper.rb', line 69

def id
  @id
end

#open(&block) ⇒ Object



58
59
60
61
62
63
# File 'app/helpers/tungsten/table_helper.rb', line 58

def open( &block )
  capture(&block).sub(/>/, " role='button' \
                      data-show=\"##{@drawer_id}\" \
                      data-add-class=\"open; ##{@id}\" \
                      data-remove-class=\"closed; ##{@id}\">").html_safe
end

#toggle(&block) ⇒ Object



52
53
54
55
56
# File 'app/helpers/tungsten/table_helper.rb', line 52

def toggle( &block )
  capture(&block).sub(/>/, " role='button' \
                      data-toggle=\"##{@drawer_id}\" \
                      data-toggle-class=\"open closed; ##{@id}\">").html_safe
end