datagrid 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.md +7 -2
- data/VERSION +1 -1
- data/datagrid.gemspec +3 -2
- data/lib/datagrid/core.rb +4 -0
- data/lib/datagrid/filters.rb +1 -1
- data/lib/datagrid/filters/base_filter.rb +2 -1
- data/lib/datagrid/helper.rb +28 -27
- data/spec/datagrid/filters_spec.rb +12 -0
- data/spec/support/simple_report.rb +12 -1
- metadata +53 -52
data/Readme.md
CHANGED
@@ -6,7 +6,12 @@ Ruby library that helps you to build and repsend table like data with:
|
|
6
6
|
* Columns
|
7
7
|
* Sort order
|
8
8
|
* Localization
|
9
|
-
*
|
9
|
+
* Export to CSV
|
10
|
+
|
11
|
+
|
12
|
+
*NOTE:* This gem is still under heavy development. If you find a bug don't consider this a peace of shit, just report it and I'll fix it shortly.
|
13
|
+
|
14
|
+
*This is not trivial staff, so a really need your help guys.*
|
10
15
|
|
11
16
|
|
12
17
|
### Grid DSL
|
@@ -66,7 +71,7 @@ report = SimpleReport.new(:order => "group", :reverse => true, :group_id => [1,2
|
|
66
71
|
report.assets # => Array of User instances:
|
67
72
|
# SELECT * FROM users WHERE users.group_id in (1,2) AND users.logins_count >= 1 AND users.category = 'first' ORDER BY groups.name DESC
|
68
73
|
|
69
|
-
report.header # => ["Group", "Name", "
|
74
|
+
report.header # => ["Group", "Name", "Activated"]
|
70
75
|
report.rows # => [
|
71
76
|
# ["Steve", "Spammers", true],
|
72
77
|
# [ "John", "Spoilers", true],
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/datagrid.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{datagrid}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bogdan Gusiev"]
|
12
|
-
s.date = %q{2011-06-
|
12
|
+
s.date = %q{2011-06-22}
|
13
13
|
s.description = %q{This allows you to easily build datagrid aka data tables with sortable columns and filters}
|
14
14
|
s.email = %q{agresso@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
"lib/datagrid/helper.rb",
|
44
44
|
"lib/datagrid/rspec.rb",
|
45
45
|
"spec/datagrid/columns_spec.rb",
|
46
|
+
"spec/datagrid/filters_spec.rb",
|
46
47
|
"spec/datagrid/form_builder_spec.rb",
|
47
48
|
"spec/datagrid/helper_spec.rb",
|
48
49
|
"spec/datagrid_spec.rb",
|
data/lib/datagrid/core.rb
CHANGED
data/lib/datagrid/filters.rb
CHANGED
@@ -103,7 +103,7 @@ module Datagrid
|
|
103
103
|
def filter(attribute, type = :string, options = {}, &block)
|
104
104
|
|
105
105
|
klass = type.is_a?(Class) ? type : FILTER_TYPES[type]
|
106
|
-
raise ConfigurationError, "filter class not found" unless klass
|
106
|
+
raise ConfigurationError, "filter class #{type.inspect} not found" unless klass
|
107
107
|
|
108
108
|
block ||= default_filter(attribute)
|
109
109
|
|
data/lib/datagrid/helper.rb
CHANGED
@@ -12,7 +12,7 @@ module Datagrid
|
|
12
12
|
when :url
|
13
13
|
link_to(column.label ? asset.send(column.label) : I18n.t("datagrid.table.url_label", :default => "URL"), value)
|
14
14
|
else
|
15
|
-
value
|
15
|
+
_safe(value)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -21,14 +21,11 @@ module Datagrid
|
|
21
21
|
options = args.extract_options!
|
22
22
|
html = options[:html] || {}
|
23
23
|
html[:class] ||= "datagrid"
|
24
|
-
|
25
|
-
paginate
|
26
|
-
assets =
|
27
|
-
content_tag(:
|
28
|
-
|
29
|
-
table << datagrid_rows(report.columns, assets, options)
|
30
|
-
table
|
31
|
-
end
|
24
|
+
assets = report.assets
|
25
|
+
paginate = options[:paginate]
|
26
|
+
assets = assets.paginate(paginate) if paginate
|
27
|
+
content = content_tag(:tr, datagrid_header(report, options)) + datagrid_rows(report.columns, assets, options)
|
28
|
+
content_tag(:table, content, html)
|
32
29
|
end
|
33
30
|
|
34
31
|
protected
|
@@ -36,7 +33,7 @@ module Datagrid
|
|
36
33
|
def datagrid_header(grid, options)
|
37
34
|
header = empty_string
|
38
35
|
grid.columns.each do |column|
|
39
|
-
data = column.header
|
36
|
+
data = _safe(column.header)
|
40
37
|
if column.order
|
41
38
|
data << datagrid_order_for(grid, column)
|
42
39
|
end
|
@@ -46,32 +43,36 @@ module Datagrid
|
|
46
43
|
end
|
47
44
|
|
48
45
|
def datagrid_rows(columns, assets, options)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
html
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
rows
|
46
|
+
result = assets.map do |asset|
|
47
|
+
content = columns.map do |column|
|
48
|
+
content_tag(:td, datagrid_format_value(column, asset))
|
49
|
+
end.join(empty_string)
|
50
|
+
content_tag(:tr, _safe(content), :class => cycle("odd", "even"))
|
51
|
+
end.join(empty_string)
|
52
|
+
_safe(result)
|
61
53
|
end
|
62
54
|
|
63
55
|
def datagrid_order_for(grid, column)
|
64
56
|
content_tag(:div, :class => "order") do
|
65
57
|
link_to(
|
66
|
-
I18n.t("datagrid.table.order.asc", :default => "ASC"),
|
67
|
-
|
68
|
-
|
58
|
+
I18n.t("datagrid.table.order.asc", :default => "ASC"),
|
59
|
+
url_for(grid.param_name => grid.attributes.merge(:order => column.name)),
|
60
|
+
:class => "order asc"
|
61
|
+
) + " " + link_to(
|
62
|
+
I18n.t("datagrid.table.order.desc", :default => "DESC"),
|
63
|
+
url_for(grid.param_name => grid.attributes.merge(:order => column.name, :reverse => true )),
|
64
|
+
:class => "order desc"
|
65
|
+
)
|
69
66
|
end
|
70
67
|
end
|
71
68
|
|
69
|
+
protected
|
72
70
|
def empty_string
|
73
|
-
|
74
|
-
|
71
|
+
_safe("")
|
72
|
+
end
|
73
|
+
|
74
|
+
def _safe(string)
|
75
|
+
string.respond_to?(:html_safe) ? string.html_safe : string
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -1,8 +1,18 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
def test_report(&block)
|
4
|
+
klass = Class.new
|
5
|
+
klass.class_eval do
|
6
|
+
include Datagrid
|
7
|
+
end
|
8
|
+
klass.class_eval(&block)
|
9
|
+
klass.new
|
10
|
+
end
|
11
|
+
|
1
12
|
class SimpleReport
|
2
13
|
|
3
14
|
include Datagrid
|
4
15
|
|
5
|
-
|
6
16
|
scope do
|
7
17
|
::Entry.includes(:group).order("entries.created_at")
|
8
18
|
end
|
@@ -11,6 +21,7 @@ class SimpleReport
|
|
11
21
|
filter(:category, :enum, :select => ["first", "second"])
|
12
22
|
filter(:disabled, :eboolean)
|
13
23
|
filter(:confirmed, :boolean)
|
24
|
+
|
14
25
|
filter(:name) do |value|
|
15
26
|
self.scoped(:conditions => {:name => value})
|
16
27
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|
@@ -15,12 +15,11 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-22 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
23
|
none: false
|
25
24
|
requirements:
|
26
25
|
- - ">="
|
@@ -29,12 +28,12 @@ dependencies:
|
|
29
28
|
segments:
|
30
29
|
- 0
|
31
30
|
version: "0"
|
32
|
-
|
31
|
+
requirement: *id001
|
33
32
|
type: :runtime
|
34
|
-
|
33
|
+
name: rails
|
34
|
+
prerelease: false
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
37
|
none: false
|
39
38
|
requirements:
|
40
39
|
- - "="
|
@@ -45,12 +44,12 @@ dependencies:
|
|
45
44
|
- 8
|
46
45
|
- 7
|
47
46
|
version: 0.8.7
|
48
|
-
|
47
|
+
requirement: *id002
|
49
48
|
type: :development
|
50
|
-
|
49
|
+
name: rake
|
50
|
+
prerelease: false
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
53
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
54
53
|
none: false
|
55
54
|
requirements:
|
56
55
|
- - ">="
|
@@ -59,12 +58,12 @@ dependencies:
|
|
59
58
|
segments:
|
60
59
|
- 0
|
61
60
|
version: "0"
|
62
|
-
|
61
|
+
requirement: *id003
|
63
62
|
type: :development
|
64
|
-
|
63
|
+
name: mocha
|
64
|
+
prerelease: false
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
|
67
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
68
67
|
none: false
|
69
68
|
requirements:
|
70
69
|
- - "="
|
@@ -75,12 +74,12 @@ dependencies:
|
|
75
74
|
- 6
|
76
75
|
- 0
|
77
76
|
version: 2.6.0
|
78
|
-
|
77
|
+
requirement: *id004
|
79
78
|
type: :development
|
80
|
-
|
79
|
+
name: rspec
|
80
|
+
prerelease: false
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
|
83
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
84
83
|
none: false
|
85
84
|
requirements:
|
86
85
|
- - ~>
|
@@ -91,12 +90,12 @@ dependencies:
|
|
91
90
|
- 0
|
92
91
|
- 0
|
93
92
|
version: 1.0.0
|
94
|
-
|
93
|
+
requirement: *id005
|
95
94
|
type: :development
|
96
|
-
|
95
|
+
name: bundler
|
96
|
+
prerelease: false
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
|
99
|
-
requirement: &id006 !ruby/object:Gem::Requirement
|
98
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
100
99
|
none: false
|
101
100
|
requirements:
|
102
101
|
- - ~>
|
@@ -107,12 +106,12 @@ dependencies:
|
|
107
106
|
- 6
|
108
107
|
- 0
|
109
108
|
version: 1.6.0
|
110
|
-
|
109
|
+
requirement: *id006
|
111
110
|
type: :development
|
112
|
-
|
111
|
+
name: jeweler
|
112
|
+
prerelease: false
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
|
-
|
115
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
114
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
116
115
|
none: false
|
117
116
|
requirements:
|
118
117
|
- - ">="
|
@@ -121,12 +120,12 @@ dependencies:
|
|
121
120
|
segments:
|
122
121
|
- 0
|
123
122
|
version: "0"
|
124
|
-
|
123
|
+
requirement: *id007
|
125
124
|
type: :development
|
126
|
-
|
125
|
+
name: rcov
|
126
|
+
prerelease: false
|
127
127
|
- !ruby/object:Gem::Dependency
|
128
|
-
|
129
|
-
requirement: &id008 !ruby/object:Gem::Requirement
|
128
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
130
129
|
none: false
|
131
130
|
requirements:
|
132
131
|
- - ">="
|
@@ -135,12 +134,12 @@ dependencies:
|
|
135
134
|
segments:
|
136
135
|
- 0
|
137
136
|
version: "0"
|
138
|
-
|
137
|
+
requirement: *id008
|
139
138
|
type: :development
|
140
|
-
|
139
|
+
name: ruby-debug
|
140
|
+
prerelease: false
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
|
-
|
143
|
-
requirement: &id009 !ruby/object:Gem::Requirement
|
142
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
144
143
|
none: false
|
145
144
|
requirements:
|
146
145
|
- - ">="
|
@@ -149,12 +148,12 @@ dependencies:
|
|
149
148
|
segments:
|
150
149
|
- 0
|
151
150
|
version: "0"
|
152
|
-
|
151
|
+
requirement: *id009
|
153
152
|
type: :development
|
154
|
-
|
153
|
+
name: sqlite3-ruby
|
154
|
+
prerelease: false
|
155
155
|
- !ruby/object:Gem::Dependency
|
156
|
-
|
157
|
-
requirement: &id010 !ruby/object:Gem::Requirement
|
156
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
158
157
|
none: false
|
159
158
|
requirements:
|
160
159
|
- - ">="
|
@@ -163,12 +162,12 @@ dependencies:
|
|
163
162
|
segments:
|
164
163
|
- 0
|
165
164
|
version: "0"
|
166
|
-
|
165
|
+
requirement: *id010
|
167
166
|
type: :development
|
168
|
-
|
167
|
+
name: fastercsv
|
168
|
+
prerelease: false
|
169
169
|
- !ruby/object:Gem::Dependency
|
170
|
-
|
171
|
-
requirement: &id011 !ruby/object:Gem::Requirement
|
170
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
172
171
|
none: false
|
173
172
|
requirements:
|
174
173
|
- - ">="
|
@@ -177,12 +176,12 @@ dependencies:
|
|
177
176
|
segments:
|
178
177
|
- 0
|
179
178
|
version: "0"
|
180
|
-
|
179
|
+
requirement: *id011
|
181
180
|
type: :development
|
182
|
-
|
181
|
+
name: nokogiri
|
182
|
+
prerelease: false
|
183
183
|
- !ruby/object:Gem::Dependency
|
184
|
-
|
185
|
-
requirement: &id012 !ruby/object:Gem::Requirement
|
184
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
186
185
|
none: false
|
187
186
|
requirements:
|
188
187
|
- - "="
|
@@ -193,9 +192,10 @@ dependencies:
|
|
193
192
|
- 3
|
194
193
|
- 15
|
195
194
|
version: 2.3.15
|
196
|
-
|
195
|
+
requirement: *id012
|
197
196
|
type: :development
|
198
|
-
|
197
|
+
name: will_paginate
|
198
|
+
prerelease: false
|
199
199
|
description: This allows you to easily build datagrid aka data tables with sortable columns and filters
|
200
200
|
email: agresso@gmail.com
|
201
201
|
executables: []
|
@@ -232,6 +232,7 @@ files:
|
|
232
232
|
- lib/datagrid/helper.rb
|
233
233
|
- lib/datagrid/rspec.rb
|
234
234
|
- spec/datagrid/columns_spec.rb
|
235
|
+
- spec/datagrid/filters_spec.rb
|
235
236
|
- spec/datagrid/form_builder_spec.rb
|
236
237
|
- spec/datagrid/helper_spec.rb
|
237
238
|
- spec/datagrid_spec.rb
|