code-box 0.4.0 → 0.4.1
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.
- data/Gemfile.lock +1 -1
- data/lib/code-box/acts_as_code.rb +14 -1
- data/lib/code-box/version.rb +1 -1
- data/lib/code-box.rb +13 -2
- data/test/code-box/test_acts_as_code.rb +9 -0
- data/test/resources/locale/de.yml +4 -0
- data/test/resources/locale/en.yml +4 -0
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -91,6 +91,8 @@ module CodeBox
|
|
91
91
|
|
92
92
|
# translator
|
93
93
|
class << self
|
94
|
+
attr_accessor :code_box_i18n_options_select_key
|
95
|
+
|
94
96
|
def translate_#{code_attr}(*code)
|
95
97
|
options = code.extract_options!
|
96
98
|
codes = code.first
|
@@ -114,6 +116,17 @@ module CodeBox
|
|
114
116
|
code_cache[code]
|
115
117
|
end
|
116
118
|
|
119
|
+
def self.build_options(*args)
|
120
|
+
options = args.extract_options!
|
121
|
+
codes = args.empty? ? All#{code_attr.pluralize.camelize} : args
|
122
|
+
include_nil = !!options[:include_nil]
|
123
|
+
|
124
|
+
options = translate_#{code_attr}(codes, build: :zip)
|
125
|
+
options << [I18n.t(CodeBox.i18n_empty_options_key), nil] if include_nil
|
126
|
+
|
127
|
+
options
|
128
|
+
end
|
129
|
+
|
117
130
|
def self.initialize_cache
|
118
131
|
Hash[all.map{ |code| [code.#{code_attr}, code] }]
|
119
132
|
end
|
@@ -237,7 +250,7 @@ module CodeBox
|
|
237
250
|
end
|
238
251
|
|
239
252
|
return if self.code_box_model_type == :active_record
|
240
|
-
|
253
|
+
|
241
254
|
code_constants = {}
|
242
255
|
codes.each do |code|
|
243
256
|
constant_name = "#{code.to_s.camelize}"
|
data/lib/code-box/version.rb
CHANGED
data/lib/code-box.rb
CHANGED
@@ -4,7 +4,10 @@ require 'code-box/code_attribute'
|
|
4
4
|
require 'code-box/acts_as_code'
|
5
5
|
|
6
6
|
module CodeBox
|
7
|
-
Config = {
|
7
|
+
Config = {
|
8
|
+
:i18n_model_segment => :activerecord,
|
9
|
+
:i18n_empty_options_key => 'shared.options.pls_select',
|
10
|
+
}
|
8
11
|
|
9
12
|
def i18n_model_segment=(segment)
|
10
13
|
Config[:i18n_model_segment] = segment
|
@@ -14,5 +17,13 @@ module CodeBox
|
|
14
17
|
Config[:i18n_model_segment]
|
15
18
|
end
|
16
19
|
|
17
|
-
|
20
|
+
def i18n_empty_options_key=(key)
|
21
|
+
Config[:i18n_empty_options_key] = key
|
22
|
+
end
|
23
|
+
|
24
|
+
def i18n_empty_options_key
|
25
|
+
Config[:i18n_empty_options_key]
|
26
|
+
end
|
27
|
+
|
28
|
+
module_function :i18n_model_segment, :i18n_model_segment=, :i18n_empty_options_key, :i18n_empty_options_key=
|
18
29
|
end
|
@@ -73,4 +73,13 @@ class TestActsAsCode < Test::Unit::TestCase
|
|
73
73
|
assert_equal code.translated_code(:de), 'verheiratet'
|
74
74
|
end
|
75
75
|
|
76
|
+
def test_options_building
|
77
|
+
options_array = Codes::CivilStatus.build_options
|
78
|
+
assert_equal options_array.size, 2
|
79
|
+
|
80
|
+
options_array = Codes::CivilStatus.build_options(include_nil: true)
|
81
|
+
puts arrrr: options_array
|
82
|
+
assert_equal options_array.size, 3
|
83
|
+
end
|
84
|
+
|
76
85
|
end
|