the_grid 1.0.7 → 1.0.8
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.
- checksums.yaml +8 -8
- data/Gemfile +0 -1
- data/lib/the_grid/builder/context.rb +26 -7
- data/lib/the_grid/builder/json.rb +1 -1
- data/lib/the_grid/version.rb +1 -1
- data/spec/builder/context_spec.rb +22 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MzdhN2E2MTBhNzFlMTIxZjVlNTI0ZWEyMzEzZmRiZjU0OWMxMGUwNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGU5MzBiZGVhNDYxN2ZjZDhjYTA5MWY3NGNlZDlkZWIyODM0MzBkNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTZjNTBkYTQ2MGZlOTZiYThkOTE4OWY5OTQzMjYwMzA5ZmI3NGVkMzJhZTI3
|
10
|
+
MWM5OWFhYzhiM2M4OThlZWY5ZmVkMjdkMjg4MWYwM2E5ZTFmNWIwMTg5MmFm
|
11
|
+
MjIyZTEyMTJkYTgyMWExYTU4YjU0Yjc0Zjc1YTJkMmZhZDQ2ZjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
M2Q0ZDlkODY4Yzg2MjZmM2VhMjJiYWFhMWQwMTA2OWU5MmI2YzAxNjYwMzY4
|
14
|
+
NjZkZTRkZTJlZTYxYWNmNzQwZTE0MjA1MzE5OWM0ZGYyY2E4ODc2MmRjNzdi
|
15
|
+
OGJlMTY5MTc5YmFmNWJlNzU4ZTAxMTMzYmM4MzFkOGZlN2E4MzI=
|
data/Gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module TheGrid
|
2
2
|
class Builder::Context
|
3
|
-
attr_reader :columns, :
|
3
|
+
attr_reader :columns, :scope
|
4
4
|
|
5
5
|
def initialize(options = {}, &dsl)
|
6
|
-
@scope
|
7
|
-
@
|
8
|
-
@
|
6
|
+
@scope = options.delete(:scope)
|
7
|
+
@columns = build_columns_with(options.delete(:id))
|
8
|
+
@options = options.merge(:features => [])
|
9
9
|
|
10
10
|
self.instance_eval(&dsl)
|
11
11
|
end
|
@@ -21,9 +21,8 @@ module TheGrid
|
|
21
21
|
if @scope.respond_to?(method_name)
|
22
22
|
@scope.send(method_name, *args, &block)
|
23
23
|
elsif method_name.to_s.ends_with?("ble_columns")
|
24
|
-
|
25
|
-
mark_columns_with(
|
26
|
-
@options[method_name.to_sym] = args
|
24
|
+
@options[:features] << method_name.to_s.chomp("_columns").to_sym
|
25
|
+
mark_columns_with(@options[:features].last, args)
|
27
26
|
else
|
28
27
|
@options[method_name] = args.size == 1 ? args.first : args
|
29
28
|
end
|
@@ -34,6 +33,14 @@ module TheGrid
|
|
34
33
|
column name, attributes.merge(:as => Builder::Context.new(:scope => scope, &block), :scope_name => scope_name)
|
35
34
|
end
|
36
35
|
|
36
|
+
def options
|
37
|
+
@options.except(:features)
|
38
|
+
end
|
39
|
+
|
40
|
+
def params
|
41
|
+
self.options.merge self.featured_columns
|
42
|
+
end
|
43
|
+
|
37
44
|
def visible_columns
|
38
45
|
columns.each_with_object({}) do |column, vc|
|
39
46
|
name, options = column
|
@@ -48,6 +55,12 @@ module TheGrid
|
|
48
55
|
|
49
56
|
protected
|
50
57
|
|
58
|
+
def build_columns_with(id_field)
|
59
|
+
columns = {}
|
60
|
+
columns[id_field || :id] = {:hidden => true} unless id_field === false
|
61
|
+
columns
|
62
|
+
end
|
63
|
+
|
51
64
|
def find_or_build_column(name)
|
52
65
|
@columns[name.to_sym] ||= {}
|
53
66
|
end
|
@@ -58,6 +71,12 @@ module TheGrid
|
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
74
|
+
def featured_columns
|
75
|
+
@options[:features].each_with_object({}) do |feature, types|
|
76
|
+
types[:"#{feature}_columns"] = columns.select{ |name, attrs| attrs[feature] }.keys
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
61
80
|
def assemble_row_for(record)
|
62
81
|
columns.each_with_object({}) do |column, row|
|
63
82
|
name, options = column
|
data/lib/the_grid/version.rb
CHANGED
@@ -7,10 +7,20 @@ describe TheGrid::Builder::Context do
|
|
7
7
|
let(:options) {{ :per_page => 25, :scope => parent_scope }}
|
8
8
|
|
9
9
|
context "by default" do
|
10
|
-
it "
|
10
|
+
it "creates hidden id column" do
|
11
11
|
build_context.columns[:id].should have_key(:hidden)
|
12
12
|
end
|
13
13
|
|
14
|
+
it "creates hidden column with specified primary key name" do
|
15
|
+
options[:id] = :key
|
16
|
+
build_context.columns[:key].should have_key(:hidden)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not create column for primary key if :id equals false" do
|
20
|
+
options[:id] = false
|
21
|
+
build_context.columns.should have(0).items
|
22
|
+
end
|
23
|
+
|
14
24
|
it "stores specified options" do
|
15
25
|
build_context.options[:per_page].should eql options[:per_page]
|
16
26
|
end
|
@@ -39,13 +49,17 @@ describe TheGrid::Builder::Context do
|
|
39
49
|
columns[:name].values_at(:test, :value).should eql [true, 5]
|
40
50
|
end
|
41
51
|
|
42
|
-
it "marks columns as
|
52
|
+
it "marks columns as featured" do
|
43
53
|
columns = build_context{ searchable_columns :name, :text }.columns
|
44
54
|
columns.slice(:name, :text).should be_all{ |k, v| v[:searchable] == true }
|
45
55
|
end
|
46
56
|
|
47
|
-
it "
|
48
|
-
build_context{ searchable_columns :name, :text }.
|
57
|
+
it "defines featured columns in params" do
|
58
|
+
build_context{ searchable_columns :name, :text }.params[:searchable_columns].should eql [:name, :text]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "does not define featured columns in options" do
|
62
|
+
build_context{ searchable_columns :name, :text }.options[:searchable_columns].should be_blank
|
49
63
|
end
|
50
64
|
|
51
65
|
it "accepts single option's values" do
|
@@ -92,7 +106,7 @@ describe TheGrid::Builder::Context do
|
|
92
106
|
let(:fields) {{ :title => "item", :id => 5, :live? => false, :short_details => "details" }}
|
93
107
|
let(:records) {[ double(fields), double(fields.merge :live? => true) ]}
|
94
108
|
|
95
|
-
|
109
|
+
describe "result" do
|
96
110
|
subject { context.assemble(records) }
|
97
111
|
let(:context) { build_plane_context }
|
98
112
|
|
@@ -102,7 +116,7 @@ describe TheGrid::Builder::Context do
|
|
102
116
|
it { should be_all{ |r| r.keys == context.columns.keys }}
|
103
117
|
end
|
104
118
|
|
105
|
-
|
119
|
+
describe "any structure" do
|
106
120
|
subject{ build_plane_context }
|
107
121
|
after(:each){ subject.assemble(records) }
|
108
122
|
|
@@ -119,7 +133,7 @@ describe TheGrid::Builder::Context do
|
|
119
133
|
end
|
120
134
|
end
|
121
135
|
|
122
|
-
|
136
|
+
describe "tree-like structure" do
|
123
137
|
let(:conditional_option) { :if }
|
124
138
|
let(:fields) {{ :id => 5, :live? => false, :permanent => [], :conditional => [], :conditional_block => [] }}
|
125
139
|
after(:each) { build_tree_like_context(conditional_option).assemble(records) }
|
@@ -179,4 +193,4 @@ describe TheGrid::Builder::Context do
|
|
179
193
|
TheGrid::Builder::Context.new(options, &dsl)
|
180
194
|
end
|
181
195
|
|
182
|
-
end
|
196
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergiy Stotskiy
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|