easy-table 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.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format nested --color
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Kristian Mandrup
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,167 @@
1
+ # Easy Table
2
+
3
+ Table helpers for your views to facilitate creating tables using a nice DSL similar to what 'simpleform' and 'formtastic' are for forms ;)
4
+
5
+ ## Install
6
+
7
+ <code>gem install easy-table</code>
8
+
9
+ ## Demo
10
+
11
+ <pre>
12
+ <code>
13
+ data_table @posts, %w{Id Title}, :summary => 'many posts', :caption => 'posts table'
14
+
15
+ =>
16
+ <table>
17
+ <thead>
18
+ <tr>
19
+ <th>id</th>
20
+ <th>title</th>
21
+ </tr>
22
+ </thead>
23
+ <tbody>
24
+ <tr>
25
+ <td>1</td>
26
+ <td>my post</td>
27
+ </tr>
28
+ <tr>
29
+ <td>2</td>
30
+ <td>my other post</td>
31
+ </tr>
32
+ </tbody>
33
+ </table>
34
+ </code>
35
+ </pre>
36
+
37
+ ## Helpers
38
+
39
+ The following is the current Table Helper API.
40
+
41
+ _Note:_ This API clearly needs to be cleaned up in the "near" future ;)
42
+
43
+ ### Table
44
+
45
+ * data_table
46
+ * table
47
+ * render_table
48
+
49
+ ### Table parts
50
+
51
+ * render_tbody
52
+ * table_body
53
+ * render_caption
54
+ * render_header
55
+ * render_footer
56
+ * header_row
57
+
58
+ ### Rows
59
+
60
+ * row
61
+ * data_rows
62
+ * data_row
63
+
64
+ ### Cells
65
+
66
+ * cells
67
+ * cell
68
+
69
+ ### Misc
70
+
71
+ * indent_tag_
72
+
73
+ ## Usage
74
+
75
+ The following examples might not all be compatible with any API changes.
76
+ Please raise an issue if you find a mismatch or have a problem using it ;)
77
+ Thanks!
78
+
79
+ Example: Using *table* helper
80
+
81
+ <pre>
82
+ <% table @posts, %w{ID title} do |post, klass| -%>
83
+ <tr class="<%= klass %>">
84
+ <td><%= post.id</td>
85
+ <td><%= post.title </td>
86
+ </tr>
87
+ <% end -%>
88
+ </pre>
89
+
90
+ Example: Using *row* helper
91
+
92
+ <pre>
93
+ <% table @posts, %w{ID title} do |post, klass| -%>
94
+ <% row klass do |post| -%>
95
+ <td><%= post.id %></td>
96
+ <td><%= post.title %></td>
97
+ <% end -%>
98
+ <% end -%>
99
+ </pre>
100
+
101
+ Example: Using *row* and *cell* helpers
102
+
103
+ <pre>
104
+ <% table @posts, %w{ID title} do |post, klass| -%>
105
+ <% row klass do |post| -%>
106
+ <%= cell post.id %>
107
+ <%= cell post.title %>
108
+ <% end -%>
109
+ <% end -%>
110
+ </pre>
111
+
112
+ Example: Using *data_row* helper
113
+
114
+ <pre>
115
+ <% table @posts, %w{ID title} do |post, klass| -%>
116
+ <% data_row post, %w{id title}, klass -%>
117
+ <% end -%>
118
+ </pre>
119
+
120
+
121
+ Example: Using *cells* helper
122
+
123
+ The last argument to cells is the CSS classes to cycle
124
+
125
+ <pre>
126
+ <% table @posts, %w{ID title} do |post, klass| -%>
127
+ <% row klass do |post| -%>
128
+ <%= cells post, %w{id title}, %w{number label} %>
129
+ <% end -%>
130
+ <% end -%>
131
+ </pre>
132
+
133
+ Example: Using *rows* helper
134
+
135
+ <pre>
136
+ <% render_table 'posts', 'Posts table', do -%>
137
+ <% rows @posts, klass, :id, :title -%>
138
+ <% end -%>
139
+ </pre>
140
+
141
+
142
+ Example: Using *data_table* helper
143
+
144
+ This will by default try to extract attribute names from the headers list!
145
+ <pre>
146
+ <% data_table @posts, %w{ID title}, :summary => 'Posts table' -%>
147
+ </pre>
148
+
149
+ Supply an :attributes options hash value to select attributes to display
150
+
151
+ <pre>
152
+ <% data_table @posts, %w{Number Title}, :attributes => %w{id label} -%>
153
+ </pre>
154
+
155
+ ## Note on Patches/Pull Requests
156
+
157
+ * Fork the project.
158
+ * Make your feature addition or bug fix.
159
+ * Add tests for it. This is important so I don't break it in a
160
+ future version unintentionally.
161
+ * Commit, do not mess with rakefile, version, or history.
162
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
163
+ * Send me a pull request. Bonus points for topic branches.
164
+
165
+ ## Copyright
166
+
167
+ Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "easy-table"
5
+ gem.summary = %Q{Simple table helper DSL similar to the well known form helpers}
6
+ gem.description = %Q{Makes it easy to add tables to your views using a nice DSL similar to the form helpers}
7
+ gem.email = "kmandrup@gmail.com"
8
+ gem.homepage = "http://github.com/kristianmandrup/easy-table"
9
+ gem.authors = ["Kristian Mandrup"]
10
+ gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
11
+ gem.add_development_dependency 'rspec-action_view', '>= 0.3.0'
12
+
13
+ gem.add_dependency 'rails3_plugin_toolbox', '>= 0.3.4'
14
+ gem.add_dependency "activesupport", ">= 3.0.0.rc"
15
+ gem.add_dependency "sugar-high", ">= 0.1.4"
16
+ gem.add_dependency "sugar-high", ">= 0.1.4"
17
+
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,95 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{easy-table}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = %q{2010-08-26}
13
+ s.description = %q{Makes it easy to add tables to your views using a nice DSL similar to the form helpers}
14
+ s.email = %q{kmandrup@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "LICENSE",
24
+ "README.markdown",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "easy-table.gemspec",
28
+ "lib/easy-table.rb",
29
+ "lib/easy-table/cell.rb",
30
+ "lib/easy-table/namespaces.rb",
31
+ "lib/easy-table/rails_config.rb",
32
+ "lib/easy-table/row.rb",
33
+ "lib/easy-table/row/data.rb",
34
+ "lib/easy-table/table.rb",
35
+ "lib/easy-table/table/base.rb",
36
+ "lib/easy-table/table/data_table.rb",
37
+ "lib/easy-table/tag.rb",
38
+ "lib/easy-table/util.rb",
39
+ "lib/easy-table/view_extension.rb",
40
+ "spec/easy-table/cell_spec.rb",
41
+ "spec/easy-table/row/data_row_spec.rb",
42
+ "spec/easy-table/row/row_spec.rb",
43
+ "spec/easy-table/table/base_spec.rb",
44
+ "spec/easy-table/table/data_table_spec.rb",
45
+ "spec/easy-table/table/table_spec.rb",
46
+ "spec/easy-table/tag_spec.rb",
47
+ "spec/easy-table/util_spec.rb",
48
+ "spec/spec_helper.rb"
49
+ ]
50
+ s.homepage = %q{http://github.com/kristianmandrup/easy-table}
51
+ s.rdoc_options = ["--charset=UTF-8"]
52
+ s.require_paths = ["lib"]
53
+ s.rubygems_version = %q{1.3.7}
54
+ s.summary = %q{Simple table helper DSL similar to the well known form helpers}
55
+ s.test_files = [
56
+ "spec/easy-table/cell_spec.rb",
57
+ "spec/easy-table/row/data_row_spec.rb",
58
+ "spec/easy-table/row/row_spec.rb",
59
+ "spec/easy-table/table/base_spec.rb",
60
+ "spec/easy-table/table/data_table_spec.rb",
61
+ "spec/easy-table/table/table_spec.rb",
62
+ "spec/easy-table/tag_spec.rb",
63
+ "spec/easy-table/util_spec.rb",
64
+ "spec/spec_helper.rb"
65
+ ]
66
+
67
+ if s.respond_to? :specification_version then
68
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
+ s.specification_version = 3
70
+
71
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
73
+ s.add_development_dependency(%q<rspec-action_view>, [">= 0.3.0"])
74
+ s.add_runtime_dependency(%q<rails3_plugin_toolbox>, [">= 0.3.4"])
75
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.rc"])
76
+ s.add_runtime_dependency(%q<sugar-high>, [">= 0.1.4"])
77
+ s.add_runtime_dependency(%q<sugar-high>, [">= 0.1.4"])
78
+ else
79
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
80
+ s.add_dependency(%q<rspec-action_view>, [">= 0.3.0"])
81
+ s.add_dependency(%q<rails3_plugin_toolbox>, [">= 0.3.4"])
82
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.rc"])
83
+ s.add_dependency(%q<sugar-high>, [">= 0.1.4"])
84
+ s.add_dependency(%q<sugar-high>, [">= 0.1.4"])
85
+ end
86
+ else
87
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.19"])
88
+ s.add_dependency(%q<rspec-action_view>, [">= 0.3.0"])
89
+ s.add_dependency(%q<rails3_plugin_toolbox>, [">= 0.3.4"])
90
+ s.add_dependency(%q<activesupport>, [">= 3.0.0.rc"])
91
+ s.add_dependency(%q<sugar-high>, [">= 0.1.4"])
92
+ s.add_dependency(%q<sugar-high>, [">= 0.1.4"])
93
+ end
94
+ end
95
+
@@ -0,0 +1,2 @@
1
+ require 'easy-table/view_extension'
2
+ require 'easy-table/rails_config'
@@ -0,0 +1,38 @@
1
+ require 'easy-table/util'
2
+ require 'easy-table/tag'
3
+
4
+ module EasyTable::ViewExt
5
+ module Cell
6
+ def header_row heads
7
+ content = []
8
+ heads.each do |head|
9
+ content << indent_tag(3, :th, head)
10
+ content << ''.indent(2) if head == heads.last
11
+ end
12
+ content.join.html_safe
13
+ end
14
+
15
+ def cells object, attributes, options = {}
16
+ content = []
17
+ reset_cycle('cells')
18
+ attributes.each_with_index do |attrib, index|
19
+ cls_opt = class_option(:classes, options, :name => 'cells')
20
+
21
+ content << cell(object, attrib, options.merge(cls_opt))
22
+ content << ''.indent(2) if attrib == attributes.last
23
+ end
24
+ content.join.html_safe
25
+ end
26
+
27
+ def cell object, attribute, options = {}
28
+ options.delete(:classes)
29
+ options.delete(:cell_classes)
30
+ options.delete(:row_classes)
31
+ options.delete(:row)
32
+ value = object.send(attribute) || "Unknown attribute: #{attribute}"
33
+ indent_tag(3, :td, value, options).html_safe
34
+ end
35
+
36
+ include EasyTable::ViewExt::Util
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ require 'sugar-high/module'
2
+
3
+ # create namespaces
4
+ module EasyTable
5
+ module ViewExt
6
+ modules :table, :row, :cell, :tag
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails3_plugin_toolbox'
2
+
3
+ Rails3::PluginExtender.new do
4
+ extend_rails :view do
5
+ with EasyTable::ViewExt
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ require 'require_all'
2
+ require_all File.dirname(__FILE__) + '/row'
3
+ require 'easy-table/cell'
4
+
5
+ module EasyTable::ViewExt
6
+ module Row
7
+ def render_header heads
8
+ return nil if heads.empty?
9
+
10
+ indent_tag 1, :thead do
11
+ indent_tag 2, :tr do
12
+ header_row heads
13
+ end.indent 1
14
+ end.html_safe
15
+ end
16
+
17
+ def render_footer footer, headers
18
+ size = case headers
19
+ when Fixnum
20
+ headers
21
+ when Array
22
+ headers.size
23
+ else
24
+ raise ArgumentError, "Must take a 2nd argument that indicates number of columns the footer should span"
25
+ end
26
+ return nil if footer.blank?
27
+ indent_tag 1, :tfoot do
28
+ indent_tag 2, :tr do
29
+ indent_tag(3, :th, footer, :colspan => size).indent 2
30
+ end.indent(1)
31
+ end.html_safe
32
+ end
33
+
34
+ def row object, options={}, &block
35
+ content = with_output_buffer { yield object }
36
+ indent_tag(2, :tr, content, options).html_safe
37
+ end
38
+
39
+ includes :data
40
+ end
41
+ end