simple_table 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,10 +17,10 @@ module SimpleTable
17
17
  end
18
18
 
19
19
  def options_for_record(record, ix, options = {})
20
- options = options.dup
21
- options[:id] = dom_id(record) if record.respond_to?(:new_record?)
22
- add_class!(options, 'alternate') if ix % 2 == 1
23
- options
20
+ options.dup.tap do |options|
21
+ options[:id] = dom_id(record) if record.respond_to?(:new_record?)
22
+ add_class!(options, 'alternate') if ix % 2 == 1
23
+ end
24
24
  end
25
25
  end
26
26
  end
@@ -1,6 +1,6 @@
1
1
  module SimpleTable
2
2
  class Column
3
- attr_reader :name, :options
3
+ attr_reader :name, :table, :options
4
4
 
5
5
  def initialize(table, name, options = {})
6
6
  @table = table
@@ -15,7 +15,7 @@ module SimpleTable
15
15
  end
16
16
 
17
17
  def translate(content)
18
- scope = [SimpleTable.options[:i18n_scope], @table.collection_name, :columns].compact
18
+ scope = [SimpleTable.options[:i18n_scope], table.collection_name, :columns].compact
19
19
  I18n.t(content, :scope => scope)
20
20
  end
21
21
 
@@ -10,7 +10,7 @@ module SimpleTable
10
10
  table.columns.each do |column|
11
11
  row.cell(column.content, column.options.reverse_merge(:scope => 'col'))
12
12
  end
13
- @rows << row
13
+ rows << row
14
14
  end
15
15
  end
16
16
  end
@@ -2,6 +2,8 @@ module SimpleTable
2
2
  class Row < Tag
3
3
  self.level = 2
4
4
  self.tag_name = :tr
5
+
6
+ attr_reader :cells
5
7
 
6
8
  def initialize(parent, record = nil, options = {}, &block)
7
9
  super(parent, options)
@@ -17,12 +19,12 @@ module SimpleTable
17
19
  options = contents.last.is_a?(Hash) ? contents.pop : {}
18
20
  add_class!(options, current_column_class) if parent.is_a?(Body)
19
21
  contents.each do |content|
20
- @cells << Cell.new(self, content, options)
22
+ cells << Cell.new(self, content, options)
21
23
  end
22
24
  end
23
25
 
24
26
  def render
25
- super(@cells.map(&:render))
27
+ super(cells.map(&:render))
26
28
  end
27
29
 
28
30
  protected
@@ -33,7 +35,7 @@ module SimpleTable
33
35
  end
34
36
 
35
37
  def current_column_class
36
- column = table.columns[@cells.size]
38
+ column = table.columns[cells.size]
37
39
  column && column.options[:class] || ''
38
40
  end
39
41
  end
@@ -10,17 +10,17 @@ module SimpleTable
10
10
  end
11
11
 
12
12
  def empty?
13
- @rows.empty?
13
+ rows.empty?
14
14
  end
15
15
 
16
16
  def row(*args, &block)
17
17
  options = args.extract_options!
18
- @rows << Row.new(self, args.shift, options, &block)
18
+ rows << Row.new(self, args.shift, options, &block)
19
19
  end
20
20
 
21
21
  def render
22
22
  build if respond_to?(:build)
23
- super(@rows.map(&:render))
23
+ super(rows.map(&:render))
24
24
  end
25
25
  end
26
26
  end
@@ -26,13 +26,11 @@ module SimpleTable
26
26
 
27
27
  def column(*names)
28
28
  options = names.last.is_a?(Hash) ? names.pop : {}
29
- names.each do |name|
30
- @columns << Column.new(self, name, options)
31
- end
29
+ names.each { |name| columns << Column.new(self, name, options) }
32
30
  end
33
31
 
34
32
  def empty(*args, &block)
35
- @empty = (args << block).compact
33
+ @empty ||= (args << block).compact
36
34
  end
37
35
 
38
36
  def row(*args, &block)
@@ -41,33 +39,33 @@ module SimpleTable
41
39
 
42
40
  def collection_class
43
41
  # @collection.first.class.base_class
44
- @collection.first.class
42
+ collection.first.class
45
43
  end
46
44
 
47
45
  def collection_name
48
- @collection_name ||= collection_class.name.tableize.gsub('/', '_').gsub('rails_', '')
46
+ collection_name ||= collection_class.name.tableize.gsub('/', '_').gsub('rails_', '')
49
47
  end
50
48
 
51
49
  def render
52
- (@collection.empty? && @empty) ? render_empty : begin
53
- column(*collection_attribute_names) if @columns.empty?
50
+ (collection.empty? && empty) ? render_empty : begin
51
+ column(*collection_attribute_names) if columns.empty?
54
52
  super do |html|
55
53
  html << head.render
56
54
  html << body.render
57
- html << foot.render if @foot && !@foot.empty?
55
+ html << foot.render if foot && !foot.empty?
58
56
  end.gsub(/\n\s*\n/, "\n")
59
57
  end
60
58
  end
61
59
 
62
60
  def render_empty
63
- @empty.insert(1, @empty.pop.call) if @empty.last.respond_to?(:call)
64
- content_tag(*@empty)
61
+ empty.insert(1, empty.pop.call) if empty.last.respond_to?(:call)
62
+ content_tag(*empty)
65
63
  end
66
64
 
67
65
  protected
68
66
 
69
67
  def collection_attribute_names
70
- record = @collection.first
68
+ record = collection.first
71
69
  names = record.respond_to?(:attribute_names) ? record.attribute_names : []
72
70
  names.map(&:titleize)
73
71
  end
@@ -1,9 +1,11 @@
1
+ require 'active_support/core_ext/class/inheritable_attributes'
2
+
1
3
  module SimpleTable
2
4
  class Tag
3
- class_inheritable_accessor :level, :tag_name
4
-
5
5
  include ActionView::Helpers::TagHelper
6
6
 
7
+ class_inheritable_accessor :level, :tag_name
8
+
7
9
  attr_reader :options, :parent
8
10
 
9
11
  def initialize(parent = nil, options = {})
@@ -0,0 +1,3 @@
1
+ module SimpleTable
2
+ VERSION = '0.0.4'
3
+ end
data/lib/simple_table.rb CHANGED
@@ -1,19 +1,20 @@
1
- require 'simple_table/tag'
2
- require 'simple_table/cell'
3
- require 'simple_table/row'
4
- require 'simple_table/rows'
5
- require 'simple_table/body'
6
- require 'simple_table/head'
7
- require 'simple_table/foot'
8
- require 'simple_table/column'
9
- require 'simple_table/table'
10
-
1
+ require 'active_support/core_ext/module/attribute_accessors'
11
2
 
12
3
  module SimpleTable
4
+ autoload :Tag, 'simple_table/tag'
5
+ autoload :Cell, 'simple_table/cell'
6
+ autoload :Row, 'simple_table/row'
7
+ autoload :Rows, 'simple_table/rows'
8
+ autoload :Body, 'simple_table/body'
9
+ autoload :Head, 'simple_table/head'
10
+ autoload :Foot, 'simple_table/foot'
11
+ autoload :Column, 'simple_table/column'
12
+ autoload :Table, 'simple_table/table'
13
+
13
14
  mattr_accessor :options
14
15
  self.options = {
15
16
  :alternate_rows => true,
16
- :i18n_scope => nil
17
+ :i18n_scope => nil
17
18
  }
18
19
 
19
20
  def table_for(collection = [], options = {}, &block)
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs
@@ -16,26 +16,57 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-01 00:00:00 +02:00
19
+ date: 2010-08-02 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: activesupport
23
+ name: actionpack
24
24
  prerelease: false
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- hash: -1848230024
30
+ hash: 7712042
31
31
  segments:
32
32
  - 3
33
33
  - 0
34
34
  - 0
35
- - beta4
36
- version: 3.0.0.beta4
35
+ - rc
36
+ version: 3.0.0.rc
37
37
  type: :runtime
38
38
  version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: activesupport
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ hash: 7712042
48
+ segments:
49
+ - 3
50
+ - 0
51
+ - 0
52
+ - rc
53
+ version: 3.0.0.rc
54
+ type: :runtime
55
+ version_requirements: *id002
56
+ - !ruby/object:Gem::Dependency
57
+ name: gem_patching
58
+ prerelease: false
59
+ requirement: &id003 !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id003
39
70
  description: "[description]"
40
71
  email: raphaela.wrede@gmail.com
41
72
  executables: []
@@ -54,6 +85,7 @@ files:
54
85
  - lib/simple_table/rows.rb
55
86
  - lib/simple_table/table.rb
56
87
  - lib/simple_table/tag.rb
88
+ - lib/simple_table/version.rb
57
89
  - lib/simple_table.rb
58
90
  has_rdoc: true
59
91
  homepage: http://github.com/rwrede/simple_table