administrate-field-select 2.0.0 → 2.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f58e24ffac45ca27057850b2fcf50872125d39b
4
- data.tar.gz: a196debcaf2a0fb6bc5d847647ed510ee212c6df
3
+ metadata.gz: c7795e86d5ca03e395741b70058a0b276df95791
4
+ data.tar.gz: d541cc67d30d5f1dd681866cf5f38ea1d1450f83
5
5
  SHA512:
6
- metadata.gz: 731bbc98159c6a0cd66c23ff2db0d0338a7832642b364d6105c83b07edfde8443a0852b5c0f51342caf6a391b23c57a2852b4e8fdbd1fe0ec07bccd8308627b9
7
- data.tar.gz: b6a3a85382d25098f359a63d2ca6bffdb19b18f605fb73cf9156aefea6cadfa0414cebe987e01163ebed51a411b57fed8348c4f364d45565726307179c0e898f
6
+ metadata.gz: bd526757ab59f12cd0119bde2c6f8252bacde9a860962db0d42d38729e3e726bd3b1a590c5a8c90c444eb0a8d38e5c3ac3f61cb72bffeb962fefbfe28feebd22
7
+ data.tar.gz: 6cbb72e22c4ccdc154a1049dbfd1b870bd97d76971ab5a8b11539693fdc90cf9c782d73b0f92a320efe11ea7a4781494c20aa80702d6cc0e08688fbc5a5e4cd2
data/README.md CHANGED
@@ -5,7 +5,7 @@ Adds basic select/dropdown fields to ThoughtBot's [Administrate](https://github.
5
5
  [![Gem Version](https://img.shields.io/gem/v/administrate-field-select.svg?style=flat)](https://rubygems.org/gems/administrate-field-select)
6
6
  [![Build Status](https://img.shields.io/travis/fishpercolator/administrate-field-select/master.svg?style=flat)](https://travis-ci.org/fishpercolator/administrate-field-select)
7
7
 
8
- '''NOTE''': Since v0.1.15, Administrate now supports its own Field::Select with a slightly different mechanic. So this has been renamed to Field::SelectBasic. Please update your Gemfiles (as below) and rename your calls to this field.
8
+ **NOTE**: Since v0.1.15, Administrate now supports its own Field::Select with a slightly different mechanic. So this has been renamed to Field::SelectBasic. Please update your Gemfiles (as below) and rename your calls to this field.
9
9
 
10
10
  ## Installation
11
11
 
@@ -38,13 +38,16 @@ Additional options that are available:
38
38
 
39
39
  * `include_blank`: If true or a string, includes a blank option in the dropdown (with the string as its text).
40
40
  * `prettify`: If true, passes all choices through [`titleize`](http://api.rubyonrails.org/classes/String.html#method-i-titleize) before displaying them (in all views). If a lambda, that lambda is used instead of `titleize`.
41
+ * `i18n`: If true, passes all choices through [`i18n`](https://github.com/svenfuchs/i18n) before displaying them (in all views).
42
+
43
+ If both `prettify` and `i18n` are specified then `prettify` takes
44
+ precedence.
41
45
 
42
46
  ## Todo
43
47
 
44
48
  Some ideas for possible enhancements:
45
49
 
46
- 1. Support i18n instead of prettify
47
- 2. Be more magic with enum types and reflect the choices
50
+ 1. Be more magic with enum types and reflect the choices
48
51
 
49
52
  ## Contributing
50
53
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "administrate-field-select"
7
- spec.version = "2.0.0"
7
+ spec.version = "2.1.0"
8
8
  spec.authors = ["Rich Daley"]
9
9
  spec.email = ["rich@fishpercolator.co.uk"]
10
10
 
@@ -5,33 +5,55 @@ module Administrate
5
5
  module Field
6
6
  class SelectBasic < Base
7
7
  class Engine < ::Rails::Engine
8
- end
9
-
8
+ end
9
+
10
10
  def choices
11
- options.fetch(:choices, []).
12
- map { |o| prettify? ? [prettify(o), o] : o }
11
+ options.fetch(:choices, []).map { |o| convert_to_array(o) }
13
12
  end
14
-
13
+
15
14
  def to_s
16
- prettify? ? prettify(data) : data
15
+ convert(data)
17
16
  end
18
-
17
+
19
18
  def include_blank
20
19
  options.fetch(:include_blank, false)
21
20
  end
22
-
21
+
23
22
  private
24
-
23
+
24
+ def convert_to_array item
25
+ return item if do_not_modify_contents?
26
+ item.respond_to?(:each) ? [convert(item.first), item.last] : [convert(item), item]
27
+ end
28
+
29
+ def convert item
30
+ return prettify(item) if prettify?
31
+ return internationalise(item) if i18n?
32
+ return item
33
+ end
34
+
35
+ def do_not_modify_contents?
36
+ !(prettify? || i18n?)
37
+ end
38
+
25
39
  def prettify?
26
40
  !!options[:prettify]
27
41
  end
28
-
42
+
43
+ def i18n?
44
+ !!options[:i18n]
45
+ end
46
+
47
+ def callable_prettify?
48
+ options[:prettify].respond_to? :call
49
+ end
50
+
29
51
  def prettify(str)
30
- if options[:prettify].respond_to? :call
31
- options[:prettify].call(str)
32
- else
33
- str.titleize
34
- end
52
+ callable_prettify? ? options[:prettify].call(str) : str.titleize
53
+ end
54
+
55
+ def internationalise item
56
+ return I18n.t(item)
35
57
  end
36
58
  end
37
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-select
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Daley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
- rubygems_version: 2.2.2
116
+ rubygems_version: 2.5.1
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Dropdown/select fields for Administrate dashboards