datagrid 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.markdown +6 -6
- data/VERSION +1 -1
- data/app/views/datagrid/_row.html.erb +1 -1
- data/datagrid.gemspec +5 -6
- data/lib/datagrid/columns.rb +38 -11
- data/lib/datagrid/columns/column.rb +6 -2
- data/lib/datagrid/core.rb +0 -5
- data/lib/datagrid/helper.rb +19 -10
- data/lib/datagrid/renderer.rb +0 -8
- data/lib/datagrid/scaffold.rb +36 -8
- data/spec/datagrid/columns_spec.rb +41 -0
- data/spec/datagrid/helper_spec.rb +35 -35
- data/spec/support/test_partials/client/datagrid/_row.html.erb +1 -1
- data/templates/controller.rb.erb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 652aabb87668eb9c636d3a0b03249f79f8df4c1b
|
4
|
+
data.tar.gz: 71de05a4267561305a3e2badc2aa33e1eb88cf35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5db3557c03071721e24d355ac939ab76f29167c252c9cfda160a618e4f1b7737dfc241c808de1ccd1a75a8c7b2a9c16490a1d96500065c196413f6548e47b9ed
|
7
|
+
data.tar.gz: c34e6068303b5aa6d351869fe7d734cc4034305de5e649ea9480e74ec3dddb39b2d34ff16277f1f4a792c670d36b09cf8b826a0888a8d23906c1682facd68ac9
|
data/Readme.markdown
CHANGED
@@ -40,19 +40,19 @@ class UsersGrid
|
|
40
40
|
User.includes(:group)
|
41
41
|
end
|
42
42
|
|
43
|
-
filter(:category, :enum, :
|
43
|
+
filter(:category, :enum, select: ["first", "second"])
|
44
44
|
filter(:disabled, :xboolean)
|
45
|
-
filter(:group_id, :integer, :
|
46
|
-
filter(:logins_count, :integer, :
|
47
|
-
filter(:group_name, :string, :
|
45
|
+
filter(:group_id, :integer, multiple: true)
|
46
|
+
filter(:logins_count, :integer, range: true)
|
47
|
+
filter(:group_name, :string, header: "Group") do |value|
|
48
48
|
self.joins(:group).where(:groups => {:name => value})
|
49
49
|
end
|
50
50
|
|
51
51
|
column(:name)
|
52
|
-
column(:group, :
|
52
|
+
column(:group, order: -> { joins(:group).order(groups: :name) }) do |user|
|
53
53
|
user.name
|
54
54
|
end
|
55
|
-
column(:active, :
|
55
|
+
column(:active, header: "Activated") do |user|
|
56
56
|
!user.disabled
|
57
57
|
end
|
58
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.4
|
data/datagrid.gemspec
CHANGED
@@ -2,21 +2,20 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: datagrid 1.4.
|
5
|
+
# stub: datagrid 1.4.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "datagrid"
|
9
|
-
s.version = "1.4.
|
9
|
+
s.version = "1.4.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Bogdan Gusiev"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-07-22"
|
15
15
|
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
16
16
|
s.email = "agresso@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
18
|
-
"LICENSE.txt"
|
19
|
-
"Readme.markdown"
|
18
|
+
"LICENSE.txt"
|
20
19
|
]
|
21
20
|
s.files = [
|
22
21
|
".document",
|
@@ -129,7 +128,7 @@ Gem::Specification.new do |s|
|
|
129
128
|
]
|
130
129
|
s.homepage = "http://github.com/bogdan/datagrid"
|
131
130
|
s.licenses = ["MIT"]
|
132
|
-
s.rubygems_version = "2.
|
131
|
+
s.rubygems_version = "2.5.1"
|
133
132
|
s.summary = "Ruby gem to create datagrids"
|
134
133
|
|
135
134
|
if s.respond_to? :specification_version then
|
data/lib/datagrid/columns.rb
CHANGED
@@ -21,10 +21,13 @@ module Datagrid
|
|
21
21
|
self.columns_array = []
|
22
22
|
|
23
23
|
class_attribute :dynamic_block, :instance_writer => false
|
24
|
-
|
24
|
+
|
25
25
|
class_attribute :cached
|
26
26
|
self.cached = false
|
27
27
|
|
28
|
+
|
29
|
+
class_attribute :decorator, instance_writer: false
|
30
|
+
|
28
31
|
end
|
29
32
|
base.send :include, InstanceMethods
|
30
33
|
end # self.included
|
@@ -184,7 +187,7 @@ module Datagrid
|
|
184
187
|
# # ]
|
185
188
|
def dynamic(&block)
|
186
189
|
previous_block = dynamic_block
|
187
|
-
self.dynamic_block =
|
190
|
+
self.dynamic_block =
|
188
191
|
if previous_block
|
189
192
|
proc {
|
190
193
|
instance_eval(&previous_block)
|
@@ -195,6 +198,23 @@ module Datagrid
|
|
195
198
|
end
|
196
199
|
end
|
197
200
|
|
201
|
+
# Defines a model decorator that will be used to define a column value.
|
202
|
+
# All column blocks will be given a decorated version of the model.
|
203
|
+
#
|
204
|
+
# decorate { |user| UserPresenter.new(user) }
|
205
|
+
#
|
206
|
+
# decorate { UserPresenter } # a shortcut
|
207
|
+
def decorate(model = nil, &block)
|
208
|
+
if !model && !block
|
209
|
+
raise ArgumentError, "decorate needs either a block to define decoration or a model to decorate"
|
210
|
+
end
|
211
|
+
return self.decorator = block unless model
|
212
|
+
return model unless decorator
|
213
|
+
presenter = ::Datagrid::Utils.apply_args(model, &decorator)
|
214
|
+
presenter = presenter.is_a?(Class) ? presenter.new(model) : presenter
|
215
|
+
block_given? ? yield(presenter) : presenter
|
216
|
+
end
|
217
|
+
|
198
218
|
def inherited(child_class) #:nodoc:
|
199
219
|
super(child_class)
|
200
220
|
child_class.columns_array = self.columns_array.clone
|
@@ -342,7 +362,7 @@ module Datagrid
|
|
342
362
|
# grid.columns # => id and name columns
|
343
363
|
# grid.columns(:id, :category) # => id and category column
|
344
364
|
def columns(*args)
|
345
|
-
self.class.filter_columns(columns_array, *args).select {|column| column.enabled?(self)}
|
365
|
+
self.class.filter_columns(columns_array, *args).select {|column| column.enabled?(self)}
|
346
366
|
end
|
347
367
|
|
348
368
|
# Returns all columns that can be represented in plain data(non-html) way
|
@@ -425,19 +445,21 @@ module Datagrid
|
|
425
445
|
end
|
426
446
|
|
427
447
|
# Returns all columns available for current grid configuration.
|
428
|
-
#
|
448
|
+
#
|
429
449
|
# class MyGrid
|
430
|
-
# filter(:search)
|
450
|
+
# filter(:search) {|scope, value| scope.full_text_search(value)}
|
431
451
|
# column(:id)
|
432
452
|
# column(:name, :mandatory => true)
|
433
|
-
# column(:search_match, :if => proc {|grid| grid.search.present? }
|
453
|
+
# column(:search_match, :if => proc {|grid| grid.search.present? }) do |model, grid|
|
454
|
+
# search_match_line(model.searchable_content, grid.search)
|
455
|
+
# end
|
434
456
|
# end
|
435
457
|
#
|
436
458
|
# grid = MyGrid.new
|
437
|
-
# grid.columns # => [
|
438
|
-
# grid.available_columns # => [
|
459
|
+
# grid.columns # => [ #<Column:name> ]
|
460
|
+
# grid.available_columns # => [ #<Column:id>, #<Column:name> ]
|
439
461
|
# grid.search = "keyword"
|
440
|
-
# grid.available_columns # => [
|
462
|
+
# grid.available_columns # => [ #<Column:id>, #<Column:name>, #<Column:search_match> ]
|
441
463
|
#
|
442
464
|
def available_columns
|
443
465
|
columns_array.select do |column|
|
@@ -468,17 +490,22 @@ module Datagrid
|
|
468
490
|
end
|
469
491
|
end
|
470
492
|
|
493
|
+
# Returns a decorated version of given model if decorator is specified or the model otherwise.
|
494
|
+
def decorate(model)
|
495
|
+
self.class.decorate(model)
|
496
|
+
end
|
471
497
|
|
472
498
|
def generic_value(column, model) #:nodoc:
|
473
499
|
cache(column, model, :generic_value) do
|
500
|
+
presenter = decorate(model)
|
474
501
|
unless column.enabled?(self)
|
475
502
|
raise Datagrid::ColumnUnavailableError, "Column #{column.name} disabled for #{inspect}"
|
476
503
|
end
|
477
504
|
|
478
505
|
if column.data_block.arity >= 1
|
479
|
-
Datagrid::Utils.apply_args(
|
506
|
+
Datagrid::Utils.apply_args(presenter, self, data_row(model), &column.data_block)
|
480
507
|
else
|
481
|
-
|
508
|
+
presenter.instance_eval(&column.data_block)
|
482
509
|
end
|
483
510
|
end
|
484
511
|
|
@@ -20,6 +20,10 @@ class Datagrid::Columns::Column
|
|
20
20
|
data_block.call
|
21
21
|
end
|
22
22
|
|
23
|
+
def to_s
|
24
|
+
call_data.to_s
|
25
|
+
end
|
26
|
+
|
23
27
|
def call_html(context)
|
24
28
|
context.instance_eval(&html_block)
|
25
29
|
end
|
@@ -54,7 +58,7 @@ class Datagrid::Columns::Column
|
|
54
58
|
end
|
55
59
|
|
56
60
|
def header
|
57
|
-
if header = options[:header]
|
61
|
+
if header = options[:header]
|
58
62
|
callable(header)
|
59
63
|
else
|
60
64
|
Datagrid::Utils.translate_from_namespace(:columns, grid_class, name)
|
@@ -137,7 +141,7 @@ class Datagrid::Columns::Column
|
|
137
141
|
when Proc
|
138
142
|
option.call(grid)
|
139
143
|
when Symbol, String
|
140
|
-
grid.send(option.to_sym)
|
144
|
+
grid.send(option.to_sym)
|
141
145
|
else
|
142
146
|
raise Datagrid::ConfigurationError, "Incorrect column availability option: #{option.insepct}"
|
143
147
|
end
|
data/lib/datagrid/core.rb
CHANGED
@@ -115,11 +115,6 @@ module Datagrid
|
|
115
115
|
attributes
|
116
116
|
end
|
117
117
|
|
118
|
-
def paginate(*args, &block) # :nodoc:
|
119
|
-
::Datagrid::Utils.warn_once("#paginate is deprecated. Call it like object.assets.paginate(...).")
|
120
|
-
self.assets.paginate(*args, &block)
|
121
|
-
end
|
122
|
-
|
123
118
|
# Redefines scope at instance level
|
124
119
|
#
|
125
120
|
# class MyGrid
|
data/lib/datagrid/helper.rb
CHANGED
@@ -22,19 +22,19 @@ module Datagrid
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Renders html table with columns defined in grid class.
|
25
|
-
# In the most common used you need to pass paginated collection
|
25
|
+
# In the most common used you need to pass paginated collection
|
26
26
|
# to datagrid table because datagrid do not have pagination compatibilities:
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# assets = grid.assets.page(params[:page])
|
29
29
|
# datagrid_table(grid, assets, options)
|
30
30
|
#
|
31
31
|
# Supported options:
|
32
32
|
#
|
33
33
|
# * <tt>:html</tt> - hash of attributes for <table> tag
|
34
|
-
# * <tt>:order</tt> - If false do not generate ordering controlls.
|
34
|
+
# * <tt>:order</tt> - If false do not generate ordering controlls.
|
35
35
|
# Default: true.
|
36
|
-
# * <tt>:columns</tt> - Array of column names to display.
|
37
|
-
# Used in case when same grid class is used in different places
|
36
|
+
# * <tt>:columns</tt> - Array of column names to display.
|
37
|
+
# Used in case when same grid class is used in different places
|
38
38
|
# and needs different columns. Default: all defined columns.
|
39
39
|
# * <tt>:partials</tt> - Path for partials lookup.
|
40
40
|
# Default: 'datagrid'.
|
@@ -59,8 +59,8 @@ module Datagrid
|
|
59
59
|
#
|
60
60
|
# Supported options:
|
61
61
|
#
|
62
|
-
# * <tt>:columns</tt> - Array of column names to display.
|
63
|
-
# Used in case when same grid class is used in different places
|
62
|
+
# * <tt>:columns</tt> - Array of column names to display.
|
63
|
+
# Used in case when same grid class is used in different places
|
64
64
|
# and needs different columns. Default: all defined columns.
|
65
65
|
# * <tt>:partials</tt> - Path for partials lookup.
|
66
66
|
# Default: 'datagrid'.
|
@@ -108,12 +108,21 @@ module Datagrid
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
|
112
|
-
|
111
|
+
# Represents a datagrid row that provides access to column values for the given asset
|
112
|
+
#
|
113
|
+
# row = datagrid_row(grid, user)
|
114
|
+
# row.first_name # => "<strong>Bogdan</strong>"
|
115
|
+
# row.grid # => Grid object
|
116
|
+
# row.asset # => User object
|
117
|
+
class HtmlRow
|
118
|
+
|
119
|
+
attr_reader :grid, :asset
|
120
|
+
|
121
|
+
def initialize(context, grid, asset) # :nodoc:
|
113
122
|
@context = context
|
114
123
|
@grid = grid
|
115
124
|
@asset = asset
|
116
|
-
end
|
125
|
+
end
|
117
126
|
|
118
127
|
def method_missing(method, *args, &blk)
|
119
128
|
if column = @grid.column_by_name(method)
|
data/lib/datagrid/renderer.rb
CHANGED
@@ -38,15 +38,7 @@ module Datagrid
|
|
38
38
|
options = args.extract_options!
|
39
39
|
options[:html] ||= {}
|
40
40
|
options[:html][:class] ||= "datagrid #{@template.dom_class(grid)}"
|
41
|
-
if options[:cycle]
|
42
|
-
::Datagrid::Utils.warn_once("datagrid_table cycle option is deprecated. Use css to style odd/even rows instead.")
|
43
|
-
end
|
44
41
|
assets = args.any? ? args.shift : grid.assets
|
45
|
-
paginate = options[:paginate]
|
46
|
-
if paginate
|
47
|
-
::Datagrid::Utils.warn_once(":paginate option is deprecated. Look to https://github.com/bogdan/datagrid/wiki/Frontend.")
|
48
|
-
assets = assets.paginate(paginate)
|
49
|
-
end
|
50
42
|
|
51
43
|
_render_partial('table', options[:partials],
|
52
44
|
{
|
data/lib/datagrid/scaffold.rb
CHANGED
@@ -10,12 +10,12 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
|
|
10
10
|
def create_scaffold
|
11
11
|
template "grid.rb.erb", "app/grids/#{grid_class_name.underscore}.rb"
|
12
12
|
if File.exists?(grid_controller_file)
|
13
|
-
inject_into_file grid_controller_file, index_action, :after => %r{class .*#{
|
13
|
+
inject_into_file grid_controller_file, index_action, :after => %r{class .*#{grid_controller_class_name}.*\n}
|
14
14
|
else
|
15
15
|
template "controller.rb.erb", grid_controller_file
|
16
16
|
end
|
17
|
-
template "index.html.erb",
|
18
|
-
route("resources :#{grid_controller_short_name}")
|
17
|
+
template "index.html.erb", view_file
|
18
|
+
route(generate_routing_namespace("resources :#{grid_controller_short_name}"))
|
19
19
|
unless defined?(::Kaminari) || defined?(::WillPaginate)
|
20
20
|
gem 'kaminari'
|
21
21
|
end
|
@@ -33,20 +33,24 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
def view_file
|
37
|
+
Rails.root.join("app/views").join(controller_file_path).join("index.html.erb")
|
38
|
+
end
|
39
|
+
|
36
40
|
def grid_class_name
|
37
41
|
file_name.camelize.pluralize + "Grid"
|
38
42
|
end
|
39
43
|
|
40
|
-
def
|
41
|
-
|
44
|
+
def grid_controller_class_name
|
45
|
+
controller_class_name.camelize + "Controller"
|
42
46
|
end
|
43
47
|
|
44
48
|
def grid_controller_file
|
45
|
-
Rails.root.join("app/controllers
|
49
|
+
Rails.root.join("app/controllers").join("#{grid_controller_class_name.underscore}.rb")
|
46
50
|
end
|
47
51
|
|
48
52
|
def grid_controller_short_name
|
49
|
-
|
53
|
+
controller_file_name
|
50
54
|
end
|
51
55
|
|
52
56
|
def grid_model_name
|
@@ -68,7 +72,7 @@ class Datagrid::Scaffold < Rails::Generators::NamedBase
|
|
68
72
|
end
|
69
73
|
|
70
74
|
def grid_route_name
|
71
|
-
|
75
|
+
controller_class_name.underscore.gsub("/", "_") + "_path"
|
72
76
|
end
|
73
77
|
|
74
78
|
def index_action
|
@@ -81,4 +85,28 @@ end
|
|
81
85
|
RUBY
|
82
86
|
end
|
83
87
|
|
88
|
+
protected
|
89
|
+
def generate_routing_namespace(code)
|
90
|
+
depth = regular_class_path.length
|
91
|
+
# Create 'namespace' ladder
|
92
|
+
# namespace :foo do
|
93
|
+
# namespace :bar do
|
94
|
+
namespace_ladder = regular_class_path.each_with_index.map do |ns, i|
|
95
|
+
indent("namespace :#{ns} do\n", i * 2)
|
96
|
+
end.join
|
97
|
+
|
98
|
+
# Create route
|
99
|
+
# get 'baz/index'
|
100
|
+
route = indent(code, depth * 2)
|
101
|
+
|
102
|
+
# Create `end` ladder
|
103
|
+
# end
|
104
|
+
# end
|
105
|
+
end_ladder = (1..depth).reverse_each.map do |i|
|
106
|
+
indent("end\n", i * 2)
|
107
|
+
end.join
|
108
|
+
|
109
|
+
# Combine the 3 parts to generate complete route entry
|
110
|
+
namespace_ladder + route + "\n" + end_ladder
|
111
|
+
end
|
84
112
|
end
|
@@ -521,4 +521,45 @@ describe Datagrid::Columns do
|
|
521
521
|
expect(row.random2).to_not eq(row.random1)
|
522
522
|
end
|
523
523
|
end
|
524
|
+
|
525
|
+
describe "decoration" do
|
526
|
+
class EntryDecorator
|
527
|
+
attr_reader :model
|
528
|
+
def initialize(model)
|
529
|
+
@model = model
|
530
|
+
end
|
531
|
+
def capitalized_name
|
532
|
+
model.name.capitalize
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
let!(:entry) do
|
537
|
+
Entry.create!(name: 'hello', category: 'first')
|
538
|
+
end
|
539
|
+
|
540
|
+
it "delegates column values to decorator" do
|
541
|
+
grid = test_report do
|
542
|
+
scope { Entry }
|
543
|
+
decorate { |model| EntryDecorator.new(model) }
|
544
|
+
column(:capitalized_name)
|
545
|
+
column(:category) do |presenter|
|
546
|
+
presenter.model.category
|
547
|
+
end
|
548
|
+
column(:capitalized_name_dup) do |_, _, row|
|
549
|
+
row.capitalized_name
|
550
|
+
end
|
551
|
+
end
|
552
|
+
|
553
|
+
expect(grid.rows).to eq([['Hello', 'first', 'Hello']])
|
554
|
+
end
|
555
|
+
|
556
|
+
it "allows class decorator" do
|
557
|
+
grid = test_report do
|
558
|
+
scope { Entry }
|
559
|
+
decorate { EntryDecorator }
|
560
|
+
column(:capitalized_name)
|
561
|
+
end
|
562
|
+
expect(grid.rows).to eq([['Hello']])
|
563
|
+
end
|
564
|
+
end
|
524
565
|
end
|
@@ -90,14 +90,6 @@ describe Datagrid::Helper do
|
|
90
90
|
})
|
91
91
|
end
|
92
92
|
|
93
|
-
it "should support cycle option" do
|
94
|
-
expect(subject.datagrid_rows(grid, [entry], :cycle => ["odd", "even"])).to match_css_pattern({
|
95
|
-
"tr.odd td.group" => "Pop",
|
96
|
-
"tr.odd td.name" => "Star"
|
97
|
-
})
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
93
|
it "should support no order given" do
|
102
94
|
expect(subject.datagrid_table(grid, [entry], :order => false)).to match_css_pattern("table.datagrid th .order" => 0)
|
103
95
|
end
|
@@ -383,7 +375,7 @@ describe Datagrid::Helper do
|
|
383
375
|
it "should escape html" do
|
384
376
|
entry.update_attributes!(:name => "<div>hello</div>")
|
385
377
|
expect(subject.datagrid_rows(grid, [entry], :columns => [:name])).to equal_to_dom(<<-HTML)
|
386
|
-
<tr
|
378
|
+
<tr><td class="name"><div>hello</div></td></tr>
|
387
379
|
HTML
|
388
380
|
end
|
389
381
|
|
@@ -393,7 +385,7 @@ describe Datagrid::Helper do
|
|
393
385
|
model.name.html_safe
|
394
386
|
end
|
395
387
|
expect(subject.datagrid_rows(grid, [entry], :columns => [:safe_name])).to equal_to_dom(<<-HTML)
|
396
|
-
<tr
|
388
|
+
<tr><td class="safe_name"><div>hello</div></td></tr>
|
397
389
|
HTML
|
398
390
|
|
399
391
|
end
|
@@ -513,6 +505,7 @@ describe Datagrid::Helper do
|
|
513
505
|
expect(r.name).to eq("Hello")
|
514
506
|
expect(r.category).to eq("greetings")
|
515
507
|
end
|
508
|
+
|
516
509
|
it "should yield block" do
|
517
510
|
subject.datagrid_row(grid, entry) do |row|
|
518
511
|
expect(row.name).to eq("Hello")
|
@@ -528,30 +521,11 @@ describe Datagrid::Helper do
|
|
528
521
|
end
|
529
522
|
expect(name).to eq("Hello,greetings")
|
530
523
|
end
|
531
|
-
end
|
532
|
-
|
533
|
-
describe ".datagrid_value" do
|
534
|
-
it "should format value by column name" do
|
535
|
-
report = test_report do
|
536
|
-
scope {Entry}
|
537
|
-
column(:name) do |e|
|
538
|
-
"<b>#{e.name}</b>"
|
539
|
-
end
|
540
|
-
end
|
541
524
|
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
scope {Entry}
|
547
|
-
column(:name) do |e|
|
548
|
-
format(e.name) do |value|
|
549
|
-
link_to value, "/profile"
|
550
|
-
end
|
551
|
-
end
|
552
|
-
end
|
553
|
-
expect(subject.datagrid_value(report, :name, entry)).to be_html_safe
|
554
|
-
expect(subject.datagrid_value(report, :name, entry)).to eq("<a href=\"/profile\">Star</a>")
|
525
|
+
it "should give access to grid and asset" do
|
526
|
+
r = subject.datagrid_row(grid, entry)
|
527
|
+
expect(r.grid).to eq(grid)
|
528
|
+
expect(r.asset).to eq(entry)
|
555
529
|
end
|
556
530
|
|
557
531
|
it "should use cache" do
|
@@ -576,11 +550,37 @@ describe Datagrid::Helper do
|
|
576
550
|
expect(data_row.random2).to_not eq(html_row.random2)
|
577
551
|
expect(data_row.random2).to_not eq(html_row.random1)
|
578
552
|
end
|
579
|
-
|
553
|
+
|
554
|
+
end
|
555
|
+
|
556
|
+
describe ".datagrid_value" do
|
557
|
+
it "should format value by column name" do
|
558
|
+
report = test_report do
|
559
|
+
scope {Entry}
|
560
|
+
column(:name) do |e|
|
561
|
+
"<b>#{e.name}</b>"
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
expect(subject.datagrid_value(report, :name, entry)).to eq("<b>Star</b>")
|
566
|
+
end
|
567
|
+
it "should support format in column" do
|
568
|
+
report = test_report do
|
569
|
+
scope {Entry}
|
570
|
+
column(:name) do |e|
|
571
|
+
format(e.name) do |value|
|
572
|
+
link_to value, "/profile"
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
expect(subject.datagrid_value(report, :name, entry)).to be_html_safe
|
577
|
+
expect(subject.datagrid_value(report, :name, entry)).to eq("<a href=\"/profile\">Star</a>")
|
578
|
+
end
|
579
|
+
|
580
580
|
end
|
581
581
|
|
582
582
|
describe ".datagrid_header" do
|
583
|
-
|
583
|
+
|
584
584
|
it "should support order_by_value colums" do
|
585
585
|
grid = test_report(:order => "category") do
|
586
586
|
scope { Entry }
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<tr
|
1
|
+
<tr>
|
2
2
|
<p>Namespaced row partial.</p>
|
3
3
|
<% grid.html_columns(*options[:columns]).each do |column| %>
|
4
4
|
<td class="<%= datagrid_column_classes(grid, column) %>"><%= datagrid_value(grid, column, asset) %></td>
|
data/templates/controller.rb.erb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datagrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -199,7 +199,6 @@ executables: []
|
|
199
199
|
extensions: []
|
200
200
|
extra_rdoc_files:
|
201
201
|
- LICENSE.txt
|
202
|
-
- Readme.markdown
|
203
202
|
files:
|
204
203
|
- ".document"
|
205
204
|
- ".rspec"
|
@@ -328,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
328
327
|
version: '0'
|
329
328
|
requirements: []
|
330
329
|
rubyforge_project:
|
331
|
-
rubygems_version: 2.
|
330
|
+
rubygems_version: 2.5.1
|
332
331
|
signing_key:
|
333
332
|
specification_version: 4
|
334
333
|
summary: Ruby gem to create datagrids
|