tableview 0.1.0 → 0.2.0

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.
data/README.md CHANGED
@@ -11,7 +11,7 @@ Installation
11
11
  In your Gemfile:
12
12
 
13
13
 
14
- gem 'tablevie'
14
+ gem 'tableview'
15
15
 
16
16
  then
17
17
 
@@ -41,4 +41,17 @@ Then create a partial named `_table.tv` in which you can use a DSL like this to
41
41
  row.cell post.title
42
42
  row.cell post.body if format.xls?
43
43
  end
44
- end
44
+ end
45
+
46
+ This partial will be used to render your view.
47
+
48
+ ### NEW! ###
49
+
50
+ We now have a column based DSL.
51
+
52
+ table.table_for @events
53
+
54
+ # uses I18n for header and calls the symbol as a method on the object
55
+ table.columns :first_name, :last_name
56
+ # Uses first arg as header, and evaluates block for each row
57
+ table.column("E-mail address") {|event| format.html? link_to event.email : event.email }
data/Rakefile CHANGED
@@ -1,2 +1,11 @@
1
1
  require 'bundler'
2
+ module ::Bundler
3
+ class GemHelper
4
+ include Rake::DSL
5
+ end
6
+ end
7
+
8
+ module ::RakeFileUtils
9
+ extend Rake::FileUtilsExt
10
+ end
2
11
  Bundler::GemHelper.install_tasks
@@ -1,3 +1,3 @@
1
1
  module Tableview
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,6 +10,7 @@ module Tableview
10
10
  ret = Table.new opts
11
11
  #ret.instance_eval &block
12
12
  yield(ret)
13
+ ret.create_table!
13
14
  ret
14
15
  end
15
16
 
@@ -27,6 +28,11 @@ module Tableview
27
28
  self.parts = []
28
29
  @current_part = Body.new
29
30
  @added = false
31
+ @headers, @procs = [], []
32
+ end
33
+
34
+ def table_for(s)
35
+ @collection = s
30
36
  end
31
37
 
32
38
  def config(opts)
@@ -75,6 +81,43 @@ module Tableview
75
81
  end
76
82
  @current_part.send :row, opts, &block
77
83
  end
84
+
85
+ def column(title, opts = {}, header_opts = {}, row_opts = {}, &block)
86
+ if title.is_a? Symbol
87
+ method = title unless block_given?
88
+ title = I18n.translate("activerecord.attributes.#{@collection.klass.name.downcase}.#{title}")
89
+ end
90
+ if block_given?
91
+ proc = block#lambda { |val| block.call(val) }
92
+ else
93
+ proc = lambda { |val| val.send(method) }
94
+ end
95
+
96
+ @headers << Cell.new(title, opts.merge(header_opts))
97
+ @procs << proc
98
+ @column_based = true
99
+ end
100
+
101
+ def columns(*titles)
102
+ titles.each do |title|
103
+ self.column title
104
+ end
105
+ end
106
+
107
+ def create_table!
108
+ return unless @column_based
109
+ header_row do |row|
110
+ row.cells = @headers
111
+ end
112
+ @collection.each do |el|
113
+ row do |r|
114
+ @procs.each do |proc|
115
+ r.cell proc.call(el)
116
+ end
117
+ end
118
+ end
119
+ end
120
+
78
121
  end
79
122
 
80
123
  class Part < TablePiece
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jakub Hampl
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-28 00:00:00 +00:00
17
+ date: 2011-05-30 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency