redde 0.3.16 → 0.3.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -0
- data/app/form_builders/redde_form_builder.rb +1 -1
- data/app/helpers/redde/index_helper.rb +14 -6
- data/lib/redde/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f3a8ebbbbabc634c7d635fc1866cfc7037e79e7
|
4
|
+
data.tar.gz: ba57b0cdfcdddad068b33e3ea9d2589f3ed2fc51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdad516c267d2bc606de509e742c73348d813c85784b0aaa31a322e562bfad5fedda6400f551a87f5227045c95049fc05151dfaf04e2005c7c886210da80913f
|
7
|
+
data.tar.gz: 8a29e5419cf76aa24aca38188cad5dd4552a2521287f4ba2376a8250579d0ae15b0c7f2fb7e898510caac8522cc32dc6b4fc89e40b72e7f93c133e5638202023
|
data/README.md
CHANGED
@@ -163,3 +163,33 @@ ru:
|
|
163
163
|
position: Позиция
|
164
164
|
visible: Отображать на сайте
|
165
165
|
```
|
166
|
+
|
167
|
+
## Index view customization
|
168
|
+
|
169
|
+
By default, gem will render view with all fields.
|
170
|
+
You can customize this in two ways:
|
171
|
+
|
172
|
+
### Array
|
173
|
+
|
174
|
+
You can `INDEX_COLUMNS` array to your model to customize index fields and ther sort order by defining constant inside model
|
175
|
+
|
176
|
+
```
|
177
|
+
INDEX_COLUMNS = %w(title created_at)
|
178
|
+
```
|
179
|
+
|
180
|
+
### Hash
|
181
|
+
|
182
|
+
If you need to add, for example, link to nested model, you can define hash inside model:
|
183
|
+
|
184
|
+
```
|
185
|
+
class Calculator < ActiveRecord::Base
|
186
|
+
INDEX_COLUMNS = {
|
187
|
+
name: '',
|
188
|
+
hop: "link_to \"Live (#{2 * 2})\", root_url"
|
189
|
+
}
|
190
|
+
FORM_COLUMNS = %w(name)
|
191
|
+
end
|
192
|
+
|
193
|
+
```
|
194
|
+
|
195
|
+
|
@@ -4,7 +4,7 @@ class ReddeFormBuilder < ActionView::Helpers::FormBuilder
|
|
4
4
|
|
5
5
|
def redde_field(name, *args)
|
6
6
|
label(name)
|
7
|
-
case object.class.columns.detect { |column| column.name == name.to_s }.type
|
7
|
+
case object.class.columns.detect { |column| column.name == name.to_s }.try(:type)
|
8
8
|
when :text then redde_text_area(name, *args)
|
9
9
|
when :boolean then redde_check_box(name, *args)
|
10
10
|
when :time then redde_date_time(name, *args)
|
@@ -64,13 +64,16 @@ module Redde::IndexHelper
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def index_columns
|
67
|
-
return
|
68
|
-
|
67
|
+
return column_names unless defined?(model_name::INDEX_COLUMNS)
|
68
|
+
return model_name::INDEX_COLUMNS if model_name::INDEX_COLUMNS.is_a?(Array)
|
69
|
+
model_name::INDEX_COLUMNS.keys
|
69
70
|
end
|
70
71
|
|
71
72
|
def form_column_names
|
73
|
+
return column_names.select { |i| !IGNORED_COLUMNS.include?(i) } unless defined?(model_name::FORM_COLUMNS)
|
72
74
|
return model_name::FORM_COLUMNS if defined?(model_name::FORM_COLUMNS)
|
73
|
-
|
75
|
+
res = model_name::INDEX_COLUMNS
|
76
|
+
res.keys if model_name::INDEX_COLUMNS.is_a?(Hash)
|
74
77
|
end
|
75
78
|
|
76
79
|
def sort_priority(column_name)
|
@@ -134,13 +137,18 @@ module Redde::IndexHelper
|
|
134
137
|
end
|
135
138
|
|
136
139
|
def render_item_column(item, column)
|
137
|
-
value = item
|
140
|
+
value = index_value_for(item, column)
|
138
141
|
return 'Не задано' unless value.present?
|
139
142
|
case value.class.name
|
140
|
-
when 'Time' then l(
|
141
|
-
when 'Date' then l(
|
143
|
+
when 'Time' then l(value, format: '%d %b %Y, %H:%M')
|
144
|
+
when 'Date' then l(value, format: '%d %b %Y')
|
142
145
|
else
|
143
146
|
value
|
144
147
|
end
|
145
148
|
end
|
149
|
+
|
150
|
+
def index_value_for(item, column)
|
151
|
+
return eval(model_name::INDEX_COLUMNS[column.to_sym]) if defined?(model_name::INDEX_COLUMNS) && model_name::INDEX_COLUMNS.is_a?(Hash) && model_name::INDEX_COLUMNS[column.to_sym].present?
|
152
|
+
item.send(column)
|
153
|
+
end
|
146
154
|
end
|
data/lib/redde/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redde
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Bovykin
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-03-
|
12
|
+
date: 2016-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jquery-rails
|
@@ -584,7 +584,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
584
584
|
version: '0'
|
585
585
|
requirements: []
|
586
586
|
rubyforge_project:
|
587
|
-
rubygems_version: 2.
|
587
|
+
rubygems_version: 2.5.1
|
588
588
|
signing_key:
|
589
589
|
specification_version: 4
|
590
590
|
summary: Admin scaffold generator for redde projects
|