simple_table 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,13 @@ module SimpleTable
2
2
  class Body < Rows
3
3
  self.tag_name = :tbody
4
4
 
5
- def row(options = {}, &block)
6
- table.collection.each_with_index do |record, ix|
7
- super(record, options_for_record(record, ix, options))
8
- end
5
+ def render
6
+ build
7
+ super(''.tap do |html|
8
+ table.collection.each_with_index do |record, ix|
9
+ html << rows.map { |row| row.render(record, options_for_record(record, ix, options)) }.join
10
+ end
11
+ end)
9
12
  end
10
13
 
11
14
  protected
@@ -2,5 +2,9 @@ module SimpleTable
2
2
  class Foot < Rows
3
3
  self.level = 1
4
4
  self.tag_name = :tfoot
5
+
6
+ def render(*args)
7
+ super(rows.map { |row| row.render(*args) })
8
+ end
5
9
  end
6
- end
10
+ end
@@ -3,6 +3,11 @@ module SimpleTable
3
3
  self.level = 1
4
4
  self.tag_name = :thead
5
5
 
6
+ def render(*args)
7
+ build
8
+ super(rows.map { |row| row.render(*args) })
9
+ end
10
+
6
11
  protected
7
12
 
8
13
  def build
@@ -13,4 +18,4 @@ module SimpleTable
13
18
  rows << row
14
19
  end
15
20
  end
16
- end
21
+ end
@@ -3,14 +3,13 @@ module SimpleTable
3
3
  self.level = 2
4
4
  self.tag_name = :tr
5
5
 
6
- attr_reader :cells
6
+ attr_reader :cells, :block
7
7
 
8
8
  def initialize(parent, record = nil, options = {}, &block)
9
9
  @parent = parent
10
10
  @options = options
11
11
  @cells = []
12
-
13
- yield(*[self, record].compact) if block_given?
12
+ @block = block
14
13
  end
15
14
 
16
15
  def cell(*contents)
@@ -24,12 +23,19 @@ module SimpleTable
24
23
  end
25
24
  end
26
25
 
27
- def render
26
+ def render(record = nil, options = {})
27
+ @options.merge!(options)
28
+ build(record) if block
28
29
  super(cells.map(&:render))
29
30
  end
30
31
 
31
32
  protected
32
33
 
34
+ def build(record)
35
+ @cells = []
36
+ block.call(*[self, record].compact)
37
+ end
38
+
33
39
  def alternate(options)
34
40
  options[:class] ||= ''
35
41
  options[:class] = options[:class].split(' ').push('alternate').join(' ')
@@ -17,10 +17,5 @@ module SimpleTable
17
17
  options = args.extract_options!
18
18
  rows << Row.new(self, args.shift, options, &block)
19
19
  end
20
-
21
- def render
22
- build if respond_to?(:build)
23
- super(rows.map(&:render))
24
- end
25
20
  end
26
21
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleTable
2
- VERSION = '0.0.15'
2
+ VERSION = '0.0.16'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_table
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 15
10
- version: 0.0.15
9
+ - 16
10
+ version: 0.0.16
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs