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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bed0244de3a491709a6fbd0463718ca5aff7ace
4
- data.tar.gz: 3e816ac527d2e03f74464dd57fb000246ecdeed2
3
+ metadata.gz: 4f3a8ebbbbabc634c7d635fc1866cfc7037e79e7
4
+ data.tar.gz: ba57b0cdfcdddad068b33e3ea9d2589f3ed2fc51
5
5
  SHA512:
6
- metadata.gz: ec49025bd08b8a5f4a356decf45bbfcf1d4713cb0cc3369bc39a67bd2ed48aa8ea7401f2d2294d6a75951b81931cd34ed4e82adf19c04c9fe9037fe9bc0547c4
7
- data.tar.gz: 0ae6e02f0d2b781b02a89422e4c6cf17cdd518d7a041731e16039f54db0fcfcffac9ac95634648c272dfa19ad64ff4c702339a7dbbf8d3e89021759e79ba0e8e
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 model_name::INDEX_COLUMNS if defined?(model_name::INDEX_COLUMNS)
68
- column_names
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
- column_names.select { |i| !IGNORED_COLUMNS.include?(i) }
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.send(column)
140
+ value = index_value_for(item, column)
138
141
  return 'Не задано' unless value.present?
139
142
  case value.class.name
140
- when 'Time' then l(item.send(column), format: '%d %b %Y, %H:%M')
141
- when 'Date' then l(item.send(column), format: '%d %b %Y')
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
@@ -1,3 +1,3 @@
1
1
  module Redde
2
- VERSION = '0.3.16'.freeze
2
+ VERSION = '0.3.17'.freeze
3
3
  end
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.16
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-13 00:00:00.000000000 Z
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.4.5.1
587
+ rubygems_version: 2.5.1
588
588
  signing_key:
589
589
  specification_version: 4
590
590
  summary: Admin scaffold generator for redde projects