iquest-simple_table 0.3.5 → 0.3.6

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: a22a88ebc15153bfbddfa1b076b799834eef673c
4
- data.tar.gz: 14f4ac09b39995cfb23a0336d4b6edffc57280c8
3
+ metadata.gz: 9605388d187db1edcbc45d873ce710cbe8ae4c0b
4
+ data.tar.gz: 739f74b35c801f11e41f95ad1083f37fea20f360
5
5
  SHA512:
6
- metadata.gz: 7356d83577cf0749b74a32d2dd247c89272943297a89365eb4c0362115e23842b26359350ddcc74fe62df5fd7f19dc1e72fb7d1134b9ddef0be0ae730e8e9791
7
- data.tar.gz: deffa5e1599cae4b17533e848962ce8b4a0d4a593ea8a1c6f419e41ac0540213c4c16a62a18c28ea487a6d989522d69c8896a3f2f0a025f14c6ec57f86a2bed3
6
+ metadata.gz: 1d61e21c206fbfab19317fad3d67c681dc284813815615db37cf8e0635cd99c5e4701a0b90b39499d33c047c4900ee6c092dfef17961ea749a5be4d35a2bcd7c
7
+ data.tar.gz: 8fa682beeef5041e90fb3e73e787833f0bb79108f0dacf048aba5528ef1a303fc4aae5830e63691fd8649167254b6bc60a023d76e93ccdc2dd97471ed5c403ac
@@ -0,0 +1,30 @@
1
+ module Iquest
2
+ module SimpleTable
3
+ module AttributeDescription
4
+
5
+ def human_attribute_description(attribute, options = {})
6
+ parts = attribute.to_s.split(".")
7
+ attribute = parts.pop
8
+ namespace = parts.join("/") unless parts.empty?
9
+ attributes_scope = "#{self.i18n_scope}.descriptions"
10
+
11
+ if namespace
12
+ defaults = lookup_ancestors.map do |klass|
13
+ :"#{attributes_scope}.#{klass.model_name.i18n_key}/#{namespace}.#{attribute}"
14
+ end
15
+ defaults << :"#{attributes_scope}.#{namespace}.#{attribute}"
16
+ else
17
+ defaults = lookup_ancestors.map do |klass|
18
+ :"#{attributes_scope}.#{klass.model_name.i18n_key}.#{attribute}"
19
+ end
20
+ end
21
+
22
+ defaults << options.delete(:default) if options[:default]
23
+
24
+ options[:default] = ''
25
+ I18n.translate(defaults.shift, options)
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -227,9 +227,10 @@ module Iquest
227
227
  sort_attr = sort
228
228
  end
229
229
  sort_options.reverse_merge!(method: search_action)
230
- sort_link(@search, sort_attr, label, sort_options)
230
+ sort_link(@search, sort_attr, label, sort_options) << description(attr)
231
231
  else
232
- label
232
+ label << description(attr)
233
+ label.html_safe
233
234
  end
234
235
  end
235
236
 
@@ -337,12 +338,23 @@ module Iquest
337
338
  if attr_class(attr).respond_to?(:human_attribute_name)
338
339
  attr_class(attr).try(:human_attribute_name, attr)
339
340
  elsif @search
340
- Ransack::Translate.attribute(attr.to_s.tr('.','_'), context: @search.context)
341
+ Ransack::Translate.attribute(attr.to_s.tr('.','_'), context: @search.context)
341
342
  else
342
343
  attr.to_s.humanize
343
- end
344
+ end
344
345
  end
345
346
 
347
+ def description(attr)
348
+ if attr_class(attr).respond_to?(:human_attribute_description)
349
+ description = attr_class(attr).try(:human_attribute_description, attr)
350
+ end
351
+ if description.present?
352
+ "<div class=\"description\">#{description}</div>".html_safe
353
+ else
354
+ "".html_safe
355
+ end
356
+ end
357
+
346
358
  def attr_class(attr)
347
359
  attr.to_s.split('.')[0..-2].inject(@klass) {|klass, assoc| klass.try(:reflect_on_association, assoc).try(:klass)}
348
360
  end
@@ -1,5 +1,5 @@
1
1
  module Iquest
2
2
  module SimpleTable
3
- VERSION = '0.3.5'
3
+ VERSION = '0.3.6'
4
4
  end
5
5
  end
@@ -1,6 +1,7 @@
1
1
  require "iquest/simple_table/version"
2
2
  require "iquest/simple_table/table_builder"
3
3
  require "iquest/simple_table/table_helper"
4
+ require "iquest/simple_table/attribute_description"
4
5
 
5
6
  module Iquest
6
7
  module SimpleTable
@@ -9,4 +10,4 @@ module Iquest
9
10
  end
10
11
 
11
12
  ActionController::Base.helper Iquest::SimpleTable::TableHelper
12
-
13
+ ActiveRecord::Base.extend Iquest::SimpleTable::AttributeDescription
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iquest-simple_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Dusanek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-16 00:00:00.000000000 Z
11
+ date: 2015-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ransack_simple_form
@@ -68,6 +68,7 @@ files:
68
68
  - config/locale/en.yml
69
69
  - iquest-simple_table.gemspec
70
70
  - lib/iquest/simple_table.rb
71
+ - lib/iquest/simple_table/attribute_description.rb
71
72
  - lib/iquest/simple_table/table_builder.rb
72
73
  - lib/iquest/simple_table/table_helper.rb
73
74
  - lib/iquest/simple_table/version.rb