table_go 0.2.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA512:
3
- metadata.gz: 98d1c35fd3e8d901ed141a60dae4c72feb84288f71e40953ccb6a509c923fdb0f4ac5069446a4df37d2a183e378a5fe38682999f4e290390552e49895c890477
4
- data.tar.gz: 245dbc606d4525f4338fefc23b6cc7a8aaa9bbdf06f76a6c9cde4f89a998e66f99170b22e637e8951a02e0091705ccd19007f5b0c4f491bdfdd41010c7b002af
5
2
  SHA1:
6
- metadata.gz: fd07ac423cdbee16255d07adae5b52d3fbb0e705
7
- data.tar.gz: 0eb4b6402e9df3792144845b1e4373aef069936f
3
+ data.tar.gz: e6ee92b29494a850af5b152318603b9b2fc33f94
4
+ metadata.gz: 5c8759d782dc7907d1f190cc08bb0a3651108469
5
+ SHA512:
6
+ data.tar.gz: ac16f30159744d31f6e67d776de04893d84fdb0d0fe0ad91aa61e0ad6bb42b3b08503412daa6ad851bc5add508386e46af3401aea7054652e4251cf74a5ccfca
7
+ metadata.gz: 33b6aa743e509a43cb2b96580e4fd305f13135d7951cecaf29707a8d72aea320fc7e1d7e0622555a783bdba357ef8481edf0ee6ab1a24a49cfcac7de8f53b55a
data/README.md CHANGED
@@ -78,6 +78,11 @@ example in HAML
78
78
 
79
79
  ## Changelog
80
80
 
81
+ #### 0.2.4
82
+
83
+ - new method: table_rows_for
84
+ - table options: render_rows_only, without_header
85
+
81
86
  #### 0.2.3
82
87
 
83
88
  - speed optimisation for haml templates
data/lib/table_go.rb CHANGED
@@ -18,7 +18,7 @@ module TableGo
18
18
  end
19
19
 
20
20
  def self.render(collection, model_klass, renderer_klass, template, options = {}, &block)
21
- table = Table.new(collection, model_klass, options, &block)
21
+ table = Table.new(collection.respond_to?(:each) ? collection : [collection], model_klass, options, &block)
22
22
  renderer = TableRenderer.new(table)
23
23
  renderer.renderer_klass = renderer_klass
24
24
  renderer.template = template
@@ -11,5 +11,9 @@ module TableGo
11
11
  end
12
12
  end
13
13
 
14
+ def table_rows_for(collection, model_klass, options = {}, &block)
15
+ table_go_for(collection, model_klass, options.merge(:render_rows_only => true), &block)
16
+ end
17
+
14
18
  end
15
19
  end
@@ -6,7 +6,7 @@ module TableGo
6
6
 
7
7
  def render_template
8
8
  ::FasterCSV.generate(:col_sep => ";", :row_sep => "\n", :force_quotes => true, :quote_char => '"') do |csv|
9
- csv << table.columns.map { |column| label_for_column(column) }
9
+ csv << table.columns.map { |column| label_for_column(column) } unless table.render_rows_only || table.without_header
10
10
  table.collection.each do |record|
11
11
  csv << table.columns.map do |column|
12
12
  value = value_from_record_by_column(record, column)
@@ -4,10 +4,14 @@ module TableGo
4
4
  include RendererBase
5
5
 
6
6
  def render_template
7
- content_tag(:table, table.table_html) do
8
- concat(content_tag(:caption, table.title)) if table.title
9
- concat(table_head)
10
- concat(table_body)
7
+ if table.render_rows_only
8
+ table_rows
9
+ else
10
+ content_tag(:table, table.table_html) do
11
+ concat(content_tag(:caption, table.title)) if table.title
12
+ concat(table_head) unless table.without_header
13
+ concat(table_body)
14
+ end
11
15
  end
12
16
  end
13
17
 
@@ -23,15 +27,19 @@ module TableGo
23
27
 
24
28
  def table_body
25
29
  content_tag(:tbody) do
26
- table.collection.each do |record|
27
- tr = content_tag(:tr, html_options_for_row(record)) do
28
- table.columns.each do |column|
29
- value = value_from_record_by_column(record, column)
30
- concat(content_tag(:td, apply_formatter(record, column, value), html_options_for_cell(record, column, value)))
31
- end
32
- end
33
- concat(tr)
34
- end
30
+ table_rows
31
+ end
32
+ end
33
+
34
+ def table_rows
35
+ table.collection.each do |record|
36
+ tr = content_tag(:tr, html_options_for_row(record)) do
37
+ table.columns.each do |column|
38
+ value = value_from_record_by_column(record, column)
39
+ concat(content_tag(:td, apply_formatter(record, column, value), html_options_for_cell(record, column, value)))
40
+ end
41
+ end
42
+ concat(tr)
35
43
  end
36
44
  end
37
45
 
@@ -57,5 +57,14 @@ module TableGo
57
57
  @row_html
58
58
  end
59
59
 
60
+ def render_rows_only(render_rows_only = nil)
61
+ @render_rows_only = render_rows_only if render_rows_only
62
+ @render_rows_only
63
+ end
64
+
65
+ def without_header(without_header = nil)
66
+ @without_header = without_header if without_header
67
+ @without_header
68
+ end
60
69
  end
61
70
  end
@@ -1,3 +1,3 @@
1
1
  module TableGo
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
@@ -0,0 +1,14 @@
1
+ = table_go_for(articles, Article) do |t|
2
+ - t.render_rows_only true
3
+ - t.column :ident
4
+ - t.column :custom_single_cell do |value, record, column|
5
+ = "Ident: %s - Title: %s" % [record.ident, record.title]
6
+ - t.column :custom_multiline_cell do |value, record, column|
7
+ = "Ident: %s -" % record.ident
8
+ = " Title: %s" % record.title
9
+ - t.column :custom_single_cell_with_backwards_compatibility do |value, record, column|
10
+ - "Ident: %s" % record.ident
11
+ - t.column :field_with_html_markup, :label => 'field with_html_markup' do |value, record, column|
12
+ = link_to('click me', 'http://nowhere.com')
13
+ %br
14
+ = link_to('and here', 'http://otherwhere.com')
@@ -0,0 +1,14 @@
1
+ = table_go_for(articles, Article) do |t|
2
+ - t.without_header true
3
+ - t.column :ident
4
+ - t.column :custom_single_cell do |value, record, column|
5
+ = "Ident: %s - Title: %s" % [record.ident, record.title]
6
+ - t.column :custom_multiline_cell do |value, record, column|
7
+ = "Ident: %s -" % record.ident
8
+ = " Title: %s" % record.title
9
+ - t.column :custom_single_cell_with_backwards_compatibility do |value, record, column|
10
+ - "Ident: %s" % record.ident
11
+ - t.column :field_with_html_markup, :label => 'field with_html_markup' do |value, record, column|
12
+ = link_to('click me', 'http://nowhere.com')
13
+ %br
14
+ = link_to('and here', 'http://otherwhere.com')
@@ -0,0 +1,13 @@
1
+ = table_rows_for(articles, Article) do |t|
2
+ - t.column :ident
3
+ - t.column :custom_single_cell do |value, record, column|
4
+ = "Ident: %s - Title: %s" % [record.ident, record.title]
5
+ - t.column :custom_multiline_cell do |value, record, column|
6
+ = "Ident: %s -" % record.ident
7
+ = " Title: %s" % record.title
8
+ - t.column :custom_single_cell_with_backwards_compatibility do |value, record, column|
9
+ - "Ident: %s" % record.ident
10
+ - t.column :field_with_html_markup, :label => 'field with_html_markup' do |value, record, column|
11
+ = link_to('click me', 'http://nowhere.com')
12
+ %br
13
+ = link_to('and here', 'http://otherwhere.com')
@@ -4,7 +4,6 @@ require 'spec_helper'
4
4
  ActionView::Base.send :include, TableGo::Helpers
5
5
 
6
6
  describe TableGo::Helpers do
7
-
8
7
  let(:articles) do
9
8
  [ Article.new(:title => 'iPutz',
10
9
  :date_of_order => Date.new(2012), :ident => 1, :vat => 19, :price => 5, :xmas_bonus => true,
@@ -18,7 +17,6 @@ describe TableGo::Helpers do
18
17
 
19
18
 
20
19
  describe 'integration in haml template' do
21
-
22
20
  let(:subject) do
23
21
  Haml::Engine.new(read_file_from_fixtures_path('simple_table.html.haml')).render(template, :articles => articles)
24
22
  end
@@ -55,8 +53,66 @@ describe TableGo::Helpers do
55
53
  <p>Pampe</p>
56
54
  ).cleanup_html
57
55
  end
56
+ end
57
+
58
+ describe 'integration in haml template for a table_rows_for' do
59
+ let(:subject) do
60
+ Haml::Engine.new(read_file_from_fixtures_path('table_rows_for.html.haml')).render(template, :articles => articles.first)
61
+ end
62
+
63
+ it "it should render in haml" do
64
+ subject.cleanup_html.should eql %Q(
65
+ <tr>
66
+ <td>1</td>
67
+ <td>Ident: 1 - Title: iPutz</td>
68
+ <td>Ident: 1 - Title: iPutz</td>
69
+ <td>Ident: 1</td>
70
+ <td><a href="http://nowhere.com">click me</a><br /><a href="http://otherwhere.com">and here</a></td>
71
+ </tr>
72
+ ).cleanup_html
73
+ end
74
+ end
75
+
76
+ describe 'integration in haml template for a table_go_for with options render_rows_only "true"' do
77
+ let(:subject) do
78
+ Haml::Engine.new(read_file_from_fixtures_path('table_go_for_with_only_rows.html.haml')).
79
+ render(template, :articles => articles.first)
80
+ end
81
+
82
+ it "it should render in haml" do
83
+ subject.cleanup_html.should eql %Q(
84
+ <tr>
85
+ <td>1</td>
86
+ <td>Ident: 1 - Title: iPutz</td>
87
+ <td>Ident: 1 - Title: iPutz</td>
88
+ <td>Ident: 1</td>
89
+ <td><a href="http://nowhere.com">click me</a><br /><a href="http://otherwhere.com">and here</a></td>
90
+ </tr>
91
+ ).cleanup_html
92
+ end
93
+ end
58
94
 
95
+ describe 'integration in haml template for a table_go_for with options without_header "true"' do
96
+ let(:subject) do
97
+ Haml::Engine.new(read_file_from_fixtures_path('table_go_for_without_header.html.haml')).
98
+ render(template, :articles => articles.first)
99
+ end
59
100
 
101
+ it "it should render in haml" do
102
+ subject.cleanup_html.should eql %Q(
103
+ <table>
104
+ <tbody>
105
+ <tr>
106
+ <td>1</td>
107
+ <td>Ident: 1 - Title: iPutz</td>
108
+ <td>Ident: 1 - Title: iPutz</td>
109
+ <td>Ident: 1</td>
110
+ <td><a href="http://nowhere.com">click me</a><br /><a href="http://otherwhere.com">and here</a></td>
111
+ </tr>
112
+ </tbody>
113
+ </table>
114
+ ).cleanup_html
115
+ end
60
116
  end
61
117
 
62
118
  # context 'speedtest' do
@@ -12,7 +12,6 @@ describe TableGo::Renderers::CsvRenderer do
12
12
  :my_type => 'hardware_type') ]
13
13
  end
14
14
 
15
-
16
15
  describe 'automatic mode' do
17
16
  subject { TableGo.render_csv(articles, Article, {}) }
18
17
 
@@ -23,10 +22,29 @@ describe TableGo::Renderers::CsvRenderer do
23
22
  "2";"Nutzbook";"2012-01-01";"19";"5";"false";"hardware_type"
24
23
  ).cleanup_csv
25
24
  end
25
+ end
26
26
 
27
+ describe 'automatic mode without title row, render_rows_only => true' do
28
+ subject { TableGo.render_csv(articles, Article, {:render_rows_only => true}) }
27
29
 
30
+ it 'should render a simple automatic csv table' do
31
+ subject.cleanup_csv.should == %Q(
32
+ "1";"iPutz";"2012-01-01";"19";"5";"true";"super_type"
33
+ "2";"Nutzbook";"2012-01-01";"19";"5";"false";"hardware_type"
34
+ ).cleanup_csv
35
+ end
28
36
  end
29
37
 
38
+ describe 'automatic mode without_header => true' do
39
+ subject { TableGo.render_csv(articles, Article, {:without_header => true}) }
40
+
41
+ it 'should render a simple automatic csv table' do
42
+ subject.cleanup_csv.should == %Q(
43
+ "1";"iPutz";"2012-01-01";"19";"5";"true";"super_type"
44
+ "2";"Nutzbook";"2012-01-01";"19";"5";"false";"hardware_type"
45
+ ).cleanup_csv
46
+ end
47
+ end
30
48
 
31
49
  describe 'custom mode' do
32
50
  subject do
data/table_go.gemspec CHANGED
@@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
9
9
  gem.description = %q{simple, flexible and fast html table generator}
10
10
  gem.summary = %q{}
11
11
  gem.homepage = 'http://github.com/megorei/table_go/'
12
+ gem.license = 'MIT'
12
13
 
13
14
  gem.files = `git ls-files`.split($\)
14
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_go
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Gollnow
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-10-09 00:00:00 Z
13
+ date: 2013-11-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionpack
@@ -78,14 +78,17 @@ files:
78
78
  - lib/table_go/table_renderer.rb
79
79
  - lib/table_go/version.rb
80
80
  - spec/fixtures/simple_table.html.haml
81
+ - spec/fixtures/table_go_for_with_only_rows.html.haml
82
+ - spec/fixtures/table_go_for_without_header.html.haml
83
+ - spec/fixtures/table_rows_for.html.haml
81
84
  - spec/spec_helper.rb
82
85
  - spec/table_go/helpers_spec.rb
83
86
  - spec/table_go/renderers/csv_renderer_spec.rb
84
87
  - spec/table_go/renderers/html_renderer_spec.rb
85
88
  - table_go.gemspec
86
89
  homepage: http://github.com/megorei/table_go/
87
- licenses: []
88
-
90
+ licenses:
91
+ - MIT
89
92
  metadata: {}
90
93
 
91
94
  post_install_message:
@@ -108,6 +111,9 @@ specification_version: 4
108
111
  summary: ""
109
112
  test_files:
110
113
  - spec/fixtures/simple_table.html.haml
114
+ - spec/fixtures/table_go_for_with_only_rows.html.haml
115
+ - spec/fixtures/table_go_for_without_header.html.haml
116
+ - spec/fixtures/table_rows_for.html.haml
111
117
  - spec/spec_helper.rb
112
118
  - spec/table_go/helpers_spec.rb
113
119
  - spec/table_go/renderers/csv_renderer_spec.rb