Class: STableBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/stable_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, partial_view) ⇒ STableBuilder

Returns a new instance of STableBuilder.



57
58
59
60
61
62
63
64
# File 'app/helpers/stable_helper.rb', line 57

def initialize(context, partial_view)
  @partial_view =  partial_view
  @context = context
  @data = []
  @column_html_options = []
  @row_wrapper_html_options = []
  @row_index = -1
end

Instance Method Details

#table(options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/helpers/stable_helper.rb', line 66

def table(options)
  @options = options.reverse_merge!({ fixed_rows: 1, fixed_columns: 1 })
  html_options = options.clone
  html_options.delete :fixed_rows

  yield

  @context.haml_concat @context.render(:partial => @partial_view,
    :locals => {
      :data => @data,
      :options => @options,
      :html_options => html_options,
      :row_wrapper_html_options => @row_wrapper_html_options
    }
  )
end

#tbodyObject



116
117
118
# File 'app/helpers/stable_helper.rb', line 116

def tbody
  yield
end

#td(content, html_options) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/helpers/stable_helper.rb', line 92

def td(content, html_options)
  @col_index += 1

  # ensure slot for @column_html_options[@col_index]
  if @col_index >= @column_html_options.size
    @column_html_options << {}
  end

  # if html_options define style for column, override it
  if c = html_options.delete(:column)
    @column_html_options[@col_index] = c
  end

  # merge html_options with column html_options
  html_options.merge!(@column_html_options[@col_index])

  @data.last << { value: content, html_options: html_options }
end

#theadObject



111
112
113
114
# File 'app/helpers/stable_helper.rb', line 111

def thead
  yield
  @options[:fixed_rows] = @row_index + 1
end

#tr(html_options) ⇒ Object



83
84
85
86
87
88
89
90
# File 'app/helpers/stable_helper.rb', line 83

def tr(html_options)
  @row_index += 1
  @col_index = -1

  @row_wrapper_html_options << html_options
  @data << []
  yield
end