gridion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,11 @@ module Gridion
20
20
  @footer=block if block_given?
21
21
  @footer
22
22
  end
23
+
24
+ def paginator(&block)
25
+ @paginator=block if block_given?
26
+ @paginator
27
+ end
23
28
 
24
29
 
25
30
  end
@@ -27,12 +32,39 @@ module Gridion
27
32
  def grid(collection, options={}, &block)
28
33
  grid_binding=GridBinding.new
29
34
 
35
+ initialize_grid_binding(grid_binding)
36
+
37
+ content=with_output_buffer {block.call(grid_binding) } if block_given?
38
+
39
+ # we need to initialize the procs in the helper context otherwise other helpers inside the proc object (e.g. link_to) wont work
40
+
41
+
42
+
43
+ unless collection.blank?
44
+ grid_binding.header.call(collection.first.class, collection, options)
45
+
46
+ collection.each {|object| grid_binding.row.call(object.class, object, options) }
47
+
48
+ grid_binding.paginator.call(collection.first.class, collection, options) if collection.respond_to?(:current_page) && defined?(Kaminari) # we assume only Kaminari is supported
49
+
50
+
51
+ grid_binding.footer.call(collection.first.class, collection, options)
52
+
53
+ end
54
+
55
+ return nil
56
+
57
+ end
58
+ def initialize_grid_binding(grid_binding)
30
59
  with_output_buffer do
31
60
  grid_binding.header do |klass, collection, options={}|
32
61
  safe_concat("<table class=\"#{klass.name.downcase}\">")
33
62
  safe_concat("<tr>")
63
+
34
64
  (options[:columns]||klass.column_names).each do |col|
35
- safe_concat("<th>#{klass.human_attribute_name(col)}</th>")
65
+ col_label=klass.human_attribute_name(col)
66
+ col_label = sort_link(options[:q], col, col_label) if defined?(:sort_link) && options.has_key?(:q)
67
+ safe_concat("<th>#{col_label}</th>")
36
68
  end
37
69
  safe_concat("<th>Actions</th>")
38
70
  safe_concat("</tr>")
@@ -51,33 +83,26 @@ module Gridion
51
83
 
52
84
  end
53
85
 
86
+ grid_binding.paginator do |klass, collection, options|
87
+ colspans=(options[:columns]||klass.column_names).count + 2 #TODO: change this to number of action columns
88
+ result = ""
89
+ result << "<tr class=\"footer\">"
90
+ result << "<td colspan=\"#{colspans}\">"
91
+ result << paginate(collection)
92
+ result << "</td>"
93
+ result << "</tr>"
94
+ safe_concat(result)
95
+ end
96
+
54
97
  grid_binding.footer do |klass, collection, options={}|
55
98
  safe_concat("</table>")
56
99
  end
100
+
57
101
 
58
102
  end
59
-
60
- content=with_output_buffer {block.call(grid_binding) } if block_given?
61
-
62
- # we need to initialize the procs in the helper context otherwise other helpers inside the proc object (e.g. link_to) wont work
63
-
64
-
65
-
66
- unless collection.blank?
67
- grid_binding.header.call(collection.first.class, collection, options)
68
-
69
- collection.each {|object| grid_binding.row.call(object.class, object, options) }
70
-
71
- grid_binding.footer.call(collection.first.class, collection, options)
72
-
73
- end
74
-
75
- return nil
76
-
77
103
  end
78
104
 
79
105
 
80
106
 
81
-
82
107
  end
83
108
  end
@@ -1,3 +1,3 @@
1
1
  module Gridion
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gridion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-18 00:00:00.000000000Z
12
+ date: 2011-09-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
16
- requirement: &2152627000 !ruby/object:Gem::Requirement
16
+ requirement: &70140114563720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,18 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2152627000
24
+ version_requirements: *70140114563720
25
+ - !ruby/object:Gem::Dependency
26
+ name: kaminari
27
+ requirement: &70140114563280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70140114563280
25
36
  description: Simple grid helper for rails
26
37
  email:
27
38
  - william@tofugear.com
@@ -79,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
90
  version: '0'
80
91
  segments:
81
92
  - 0
82
- hash: 3113714939252299406
93
+ hash: 1779692905437522479
83
94
  required_rubygems_version: !ruby/object:Gem::Requirement
84
95
  none: false
85
96
  requirements:
@@ -88,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
99
  version: '0'
89
100
  segments:
90
101
  - 0
91
- hash: 3113714939252299406
102
+ hash: 1779692905437522479
92
103
  requirements: []
93
104
  rubyforge_project:
94
105
  rubygems_version: 1.8.10