tableview 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,13 +10,15 @@ Installation
10
10
 
11
11
  In your Gemfile:
12
12
 
13
-
14
13
  gem 'tableview'
15
14
 
16
15
  then
17
16
 
18
17
  $ bundle install
19
18
  $ rails g tableview:install
19
+
20
+ Usage
21
+ =====
20
22
 
21
23
  To apply to a resource use the built in generator:
22
24
 
@@ -36,6 +38,10 @@ This will create a partial named `_table.tv` in which you can use a DSL like thi
36
38
  = @registration.other_scope, "Works as title in other formats as well"
37
39
  end
38
40
 
41
+ DSL
42
+ ===
43
+
44
+
39
45
  The DSL is a simple superset of ruby with a few special characters (only work if first printable character on line, won't work with eval and friends).
40
46
 
41
47
  Character | Meaning
@@ -45,6 +51,29 @@ Character | Meaning
45
51
  `+` | Defines a column. If passed a symbol, Tableview will use I18n to lookup the header and call the method on the model to get the value. Strings will be used literally. Optionally use a block to generate values.
46
52
  `=` | Render a subtable for the passed collection. Not all formatters support subtables, use at own risk (notably the CSV formatter has no support for this). Is meant mainly to have nice full-featured excel files.
47
53
 
54
+ What if I don't like the DSL?
55
+ =============================
56
+
57
+ You may simply create a `.rb` file instead, it will just have to include some boilerplate code (same result as above):
58
+
59
+ format = Tableview::Helper::Format.new(params)
60
+ tv = Tableview::ViewHandler.table do |table|
61
+ table.table_for @registrations
62
+
63
+ table.column :first_name
64
+ table.column :surname
65
+ table.column :address {|reg| reg.address + "\n" + reg.postcode }
66
+ table.column :friends if format.html?
67
+
68
+ if format.xls?
69
+ table.generate_subtable_for @registrations.some_scope, "Workbook title"
70
+ table.generate_subtable_for @registration.other_scope, "Works as title in other formats as well"
71
+ end
72
+ end
73
+ output = Tableview::output_class(params[:format]).new
74
+ output.process(tv)
75
+ output.to_s
76
+
48
77
  It will also add a few lines of code to your controller:
49
78
 
50
79
  - `self.responder = ApplicationResponder` this sets up the correct code path to use for dynamically rendering all the formats.
@@ -10,13 +10,9 @@ module Tableview::Helper
10
10
  end
11
11
 
12
12
  def method_missing(name, *args, &blk)
13
- puts name.inspect
14
13
  if m = name.to_s.match(/^(.+)\?$/)
15
- puts "matched"
16
- #puts m.inspect, name.inspect
17
14
  @params[:format] == m.captures.first
18
15
  else
19
- puts "did not match"
20
16
  super
21
17
  end
22
18
  end
@@ -9,7 +9,7 @@ module Tableview
9
9
  source.gsub!(/#{start}\*#{ending}/, 'table.config(\1)')
10
10
  %{
11
11
  format = Tableview::Helper::Format.new(params)
12
- tv = Tableview::ViewHandler.dsl do |table|
12
+ tv = Tableview::ViewHandler.table do |table|
13
13
  #{source}
14
14
  end
15
15
  output = Tableview::output_class(params[:format]).new
@@ -1,3 +1,3 @@
1
1
  module Tableview
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -6,7 +6,7 @@ module Tableview
6
6
 
7
7
  attr_reader :table
8
8
 
9
- def self.dsl(opts = {}, &block)
9
+ def self.table(opts = {}, &block)
10
10
  ret = Table.new opts
11
11
  #ret.instance_eval &block
12
12
  yield(ret)
@@ -82,10 +82,10 @@ module Tableview
82
82
  @current_part.send :row, opts, &block
83
83
  end
84
84
 
85
- def column(title, opts = {}, header_opts = {}, row_opts = {}, &block)
85
+ def column(title, method = nil, opts = {}, &block)
86
86
  if title.is_a? Symbol
87
87
  method = title unless block_given?
88
- title = I18n.translate("activerecord.attributes.#{@collection.klass.name.downcase}.#{title}")
88
+ title = I18n.translate("activerecord.attributes.#{@collection.klass.name.downcase}.#{title}")
89
89
  end
90
90
  if block_given?
91
91
  proc = block#lambda { |val| block.call(val) }
@@ -93,7 +93,7 @@ module Tableview
93
93
  proc = lambda { |val| val.send(method) }
94
94
  end
95
95
 
96
- @headers << Cell.new(title, opts.merge(header_opts))
96
+ @headers << Cell.new(title, opts)
97
97
  @procs << proc
98
98
  @column_based = true
99
99
  end
metadata CHANGED
@@ -1,89 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tableview
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 3
9
- version: 0.3.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Jakub Hampl
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2011-06-01 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-09-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: bundler
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70176550766880 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 0
31
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
32
21
  version: 1.0.0
33
22
  type: :development
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: terminal-table
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70176550766880
25
+ - !ruby/object:Gem::Dependency
26
+ name: terminal-table
27
+ requirement: &70176550765640 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
29
+ requirements:
41
30
  - - ~>
42
- - !ruby/object:Gem::Version
43
- segments:
44
- - 1
45
- - 4
46
- version: "1.4"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.4'
47
33
  type: :runtime
48
- version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: spreadsheet
51
34
  prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70176550765640
36
+ - !ruby/object:Gem::Dependency
37
+ name: spreadsheet
38
+ requirement: &70176550764080 !ruby/object:Gem::Requirement
53
39
  none: false
54
- requirements:
40
+ requirements:
55
41
  - - ~>
56
- - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- - 6
60
- version: "0.6"
42
+ - !ruby/object:Gem::Version
43
+ version: '0.6'
61
44
  type: :runtime
62
- version_requirements: *id003
63
- - !ruby/object:Gem::Dependency
64
- name: railties
65
45
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *70176550764080
47
+ - !ruby/object:Gem::Dependency
48
+ name: railties
49
+ requirement: &70176550762880 !ruby/object:Gem::Requirement
67
50
  none: false
68
- requirements:
51
+ requirements:
69
52
  - - ~>
70
- - !ruby/object:Gem::Version
71
- segments:
72
- - 3
73
- - 0
74
- version: "3.0"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
75
55
  type: :runtime
76
- version_requirements: *id004
77
- description: Supported formats are ASCII, MS Excel, HTML and CSV; it is easy to create your own exporter class.
78
- email:
56
+ prerelease: false
57
+ version_requirements: *70176550762880
58
+ description: Supported formats are ASCII, MS Excel, HTML and CSV; it is easy to create
59
+ your own exporter class.
60
+ email:
79
61
  - honitom@seznam.cz
80
62
  executables: []
81
-
82
63
  extensions: []
83
-
84
64
  extra_rdoc_files: []
85
-
86
- files:
65
+ files:
87
66
  - .gitignore
88
67
  - .rvm
89
68
  - Gemfile
@@ -102,39 +81,32 @@ files:
102
81
  - lib/tableview/version.rb
103
82
  - lib/tableview/view_handler.rb
104
83
  - tableview.gemspec
105
- has_rdoc: true
106
84
  homepage: http://rubygems.org/gems/tableview
107
85
  licenses: []
108
-
109
86
  post_install_message:
110
87
  rdoc_options: []
111
-
112
- require_paths:
88
+ require_paths:
113
89
  - lib
114
- required_ruby_version: !ruby/object:Gem::Requirement
90
+ required_ruby_version: !ruby/object:Gem::Requirement
115
91
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- segments:
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
120
97
  - 0
121
- version: "0"
122
- required_rubygems_version: !ruby/object:Gem::Requirement
98
+ hash: -4193223840860407879
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
100
  none: false
124
- requirements:
125
- - - ">="
126
- - !ruby/object:Gem::Version
127
- segments:
128
- - 1
129
- - 3
130
- - 6
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
131
104
  version: 1.3.6
132
105
  requirements: []
133
-
134
106
  rubyforge_project: tableview
135
- rubygems_version: 1.3.7
107
+ rubygems_version: 1.8.15
136
108
  signing_key:
137
109
  specification_version: 3
138
- summary: Tableview is a DSL for specifying tables in Rails views that can output in multiple formats
110
+ summary: Tableview is a DSL for specifying tables in Rails views that can output in
111
+ multiple formats
139
112
  test_files: []
140
-