table-for 0.0.16 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/app/views/table_for/_table_for.html.erb +16 -15
- data/lib/table-for.rb +1 -1
- data/lib/table_for/{table_for.rb → base.rb} +2 -2
- data/lib/table_for/helper_methods.rb +3 -3
- metadata +36 -8
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.17
|
@@ -1,23 +1,23 @@
|
|
1
|
-
|
1
|
+
<% table.define :table do |options| %>
|
2
2
|
<%= content_tag :table, options[:table_html] do %>
|
3
3
|
<%= table.use :thead %>
|
4
4
|
<%= table.use :tbody %>
|
5
5
|
<% end %>
|
6
6
|
<% end %>
|
7
7
|
|
8
|
-
|
8
|
+
<% table.define :thead do |options| %>
|
9
9
|
<%= content_tag :thead, options[:thead_html] do %>
|
10
10
|
<%= table.use :header_row %>
|
11
11
|
<% end %>
|
12
12
|
<% end %>
|
13
13
|
|
14
|
-
|
14
|
+
<% table.define :header_row do |options| %>
|
15
15
|
<%= content_tag :tr, options[:header_row_html] do %>
|
16
16
|
<%= table.use :header_columns %>
|
17
17
|
<% end %>
|
18
18
|
<% end %>
|
19
19
|
|
20
|
-
|
20
|
+
<% table.define :header_columns do |options| %>
|
21
21
|
<% table.columns.each do |column| %>
|
22
22
|
<% header_html = options.merge(column.options)[:header_html] %>
|
23
23
|
<% if options.merge(column.options)[:sortable] %>
|
@@ -36,7 +36,7 @@
|
|
36
36
|
<% end %>
|
37
37
|
|
38
38
|
<% table.columns.each do |column| %>
|
39
|
-
|
39
|
+
<% table.define "#{column.name.to_s}_header", :column => column do |options| %>
|
40
40
|
<% if options[:sortable] %>
|
41
41
|
<%= table.use "#{options[:column].name.to_s}_header_sortable_link", options %>
|
42
42
|
<% else %>
|
@@ -44,12 +44,12 @@
|
|
44
44
|
<% end %>
|
45
45
|
<% end %>
|
46
46
|
|
47
|
-
|
47
|
+
<% table.define "#{column.name.to_s}_header_sortable_link", :column => column do |options| %>
|
48
48
|
<%= table.use :header_sortable_link, options %>
|
49
49
|
<% end %>
|
50
50
|
<% end %>
|
51
51
|
|
52
|
-
|
52
|
+
<% table.define :header_sortable_link do |options| %>
|
53
53
|
<% order = options[:order] ? options[:order].to_s : options[:column].name.to_s %>
|
54
54
|
<% label = (options[:label] ? options[:label] : options[:column].name.to_s.titleize) %>
|
55
55
|
<% sort_mode = ((params[:order] != order or params[:sort_mode] == "desc") ? "asc" : "desc") %>
|
@@ -60,25 +60,25 @@
|
|
60
60
|
<%= link_to label, "#{url}?#{parameters.to_query}" %>
|
61
61
|
<% end %>
|
62
62
|
|
63
|
-
|
63
|
+
<% table.define :tbody do |options| %>
|
64
64
|
<%= content_tag :tbody, options[:tbody_html] do %>
|
65
65
|
<%= table.use :rows %>
|
66
66
|
<% end %>
|
67
67
|
<% end %>
|
68
68
|
|
69
|
-
|
69
|
+
<% table.define :rows do %>
|
70
70
|
<% records.each do |record| %>
|
71
71
|
<%= table.use :row, record %>
|
72
72
|
<% end %>
|
73
73
|
<% end %>
|
74
74
|
|
75
|
-
|
75
|
+
<% table.define :row do |record, options| %>
|
76
76
|
<%= content_tag :tr, table_for_options(options[:row_html], options) do %>
|
77
77
|
<%= table.use :data_columns, record, options %>
|
78
78
|
<% end %>
|
79
79
|
<% end %>
|
80
80
|
|
81
|
-
|
81
|
+
<% table.define :data_columns do |record, options| %>
|
82
82
|
<% table.columns.each do |column| %>
|
83
83
|
<%= content_tag :td, options.merge(column.options)[:column_html] do %>
|
84
84
|
<%= table.use column, record, options.merge(:column => column) %>
|
@@ -86,22 +86,23 @@
|
|
86
86
|
<% end %>
|
87
87
|
<% end %>
|
88
88
|
|
89
|
-
|
89
|
+
<% table.define :edit, :action => :edit, :link_label => "Edit" do |record, options| %>
|
90
90
|
<%= link_to options[:link_label], [options[:action], options[:scope], record].flatten, options[:link_html] %>
|
91
91
|
<% end %>
|
92
92
|
|
93
|
-
|
93
|
+
<% table.define :show, :action => nil, :link_label => "Show" do |record, options| %>
|
94
94
|
<%= link_to options[:link_label], [options[:action], options[:scope], record].flatten, options[:link_html] %>
|
95
95
|
<% end %>
|
96
96
|
|
97
|
-
|
97
|
+
<% table.define :delete, :link_html => {}, :link_label => "Delete" do |record, options| %>
|
98
98
|
<%= link_to options[:link_label], [options[:scope], record].flatten, {:method => "delete", :confirm => "Are you sure you want to delete this #{record.class.to_s.titleize}?"}.merge(options[:link_html]) %>
|
99
99
|
<% end %>
|
100
100
|
|
101
101
|
<% table.columns.each do |column| %>
|
102
|
-
|
102
|
+
<% table.define column.name, :column => column do |record, options| %>
|
103
103
|
<%= record.send(options[:column].name) %>
|
104
104
|
<% end %>
|
105
105
|
<% end %>
|
106
106
|
|
107
|
+
<%# Now that all the blocks are defined, render the table %>
|
107
108
|
<%= table.use :table %>
|
data/lib/table-for.rb
CHANGED
@@ -2,8 +2,8 @@ require 'building-blocks'
|
|
2
2
|
|
3
3
|
module TableFor
|
4
4
|
class Base < BuildingBlocks::Base
|
5
|
-
alias columns
|
6
|
-
alias column
|
5
|
+
alias columns queued_blocks
|
6
|
+
alias column queue
|
7
7
|
|
8
8
|
def header(name, options={}, &block)
|
9
9
|
define("#{name.to_s}_header", options, &block)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module TableFor
|
2
2
|
module HelperMethods
|
3
3
|
def table_for_options(options={}, parameters={})
|
4
|
+
return nil if options.nil?
|
5
|
+
|
4
6
|
evaluated_options = {}
|
5
7
|
options.each_pair { |k, v| evaluated_options[k] = (v.is_a?(Proc) ? v.call(parameters) : v)}
|
6
8
|
evaluated_options
|
@@ -8,12 +10,10 @@ module TableFor
|
|
8
10
|
|
9
11
|
def table_for(records, options={}, &block)
|
10
12
|
options[:records] = records
|
11
|
-
options[:row_html] = {:class => lambda { |parameters| cycle('odd', 'even')}} if options[:row_html].nil?
|
12
13
|
options[:template] = "table_for/table_for"
|
13
14
|
options[:templates_folder] = "table_for"
|
14
|
-
options[:record_variable] = "records"
|
15
15
|
options[:variable] = "table"
|
16
|
-
|
16
|
+
|
17
17
|
TableFor::Base.new(self, options, &block).render
|
18
18
|
end
|
19
19
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table-for
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 61
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 17
|
10
|
+
version: 0.0.17
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Hunter
|
@@ -53,17 +53,45 @@ dependencies:
|
|
53
53
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
54
|
none: false
|
55
55
|
requirements:
|
56
|
-
- - "
|
56
|
+
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
hash:
|
58
|
+
hash: 15
|
59
59
|
segments:
|
60
60
|
- 0
|
61
61
|
- 0
|
62
|
-
-
|
63
|
-
version: 0.0.
|
62
|
+
- 8
|
63
|
+
version: 0.0.8
|
64
64
|
prerelease: false
|
65
65
|
type: :runtime
|
66
66
|
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: jeweler
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
prerelease: false
|
79
|
+
type: :development
|
80
|
+
requirement: *id004
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: jeweler
|
83
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
prerelease: false
|
93
|
+
type: :development
|
94
|
+
requirement: *id005
|
67
95
|
description: table-for is a table builder for an array of objects, easily allowing overriding of how any aspect of the table is generated
|
68
96
|
email: hunterae@gmail.com
|
69
97
|
executables: []
|
@@ -78,9 +106,9 @@ files:
|
|
78
106
|
- VERSION
|
79
107
|
- app/views/table_for/_table_for.html.erb
|
80
108
|
- lib/table-for.rb
|
109
|
+
- lib/table_for/base.rb
|
81
110
|
- lib/table_for/engine.rb
|
82
111
|
- lib/table_for/helper_methods.rb
|
83
|
-
- lib/table_for/table_for.rb
|
84
112
|
- rails/init.rb
|
85
113
|
has_rdoc: true
|
86
114
|
homepage: http://github.com/hunterae/table-for
|