localized_fields 0.0.2 → 0.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.
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +6 -3
- data/README.md +1 -1
- data/lib/localized_fields/form_builder.rb +9 -5
- data/lib/localized_fields/version.rb +1 -1
- data/localized_fields.gemspec +1 -1
- data/spec/localized_fields_spec.rb +45 -0
- metadata +10 -10
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
localized_fields (0.0
|
4
|
+
localized_fields (0.1.0)
|
5
5
|
actionpack (>= 3.1.0)
|
6
6
|
mongoid (>= 2.4.0)
|
7
7
|
|
@@ -26,6 +26,8 @@ GEM
|
|
26
26
|
activesupport (3.1.3)
|
27
27
|
multi_json (~> 1.0)
|
28
28
|
bson (1.5.2)
|
29
|
+
bson_ext (1.5.2)
|
30
|
+
bson (= 1.5.2)
|
29
31
|
builder (3.0.0)
|
30
32
|
diff-lcs (1.1.3)
|
31
33
|
erubis (2.7.0)
|
@@ -33,7 +35,7 @@ GEM
|
|
33
35
|
i18n (0.6.0)
|
34
36
|
mongo (1.5.2)
|
35
37
|
bson (= 1.5.2)
|
36
|
-
mongoid (2.4.
|
38
|
+
mongoid (2.4.1)
|
37
39
|
activemodel (~> 3.1)
|
38
40
|
mongo (~> 1.3)
|
39
41
|
tzinfo (~> 0.3.22)
|
@@ -65,6 +67,7 @@ PLATFORMS
|
|
65
67
|
ruby
|
66
68
|
|
67
69
|
DEPENDENCIES
|
70
|
+
bson_ext
|
68
71
|
localized_fields!
|
69
72
|
rake
|
70
|
-
rspec
|
73
|
+
rspec (~> 2.8.0)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Localized Fields [](http://travis-ci.org/tiagogodinho/localized_fields)
|
1
|
+
# Localized Fields [](http://travis-ci.org/tiagogodinho/localized_fields) [](http://gemnasium.com/tiagogodinho/localized_fields)
|
2
2
|
|
3
3
|
Helps you to create forms with localized fields using Mongoid.
|
4
4
|
|
@@ -8,7 +8,7 @@ module LocalizedFields
|
|
8
8
|
if @options.has_key?(:language)
|
9
9
|
language = @options[:language]
|
10
10
|
|
11
|
-
super(attribute, :for => "#{object_name}_#{attribute}_translations_#{language}").html_safe
|
11
|
+
super(attribute, options.merge(:for => "#{object_name}_#{attribute}_translations_#{language}")).html_safe
|
12
12
|
else
|
13
13
|
field_name = @object_name.match(/.*\[(.*)_translations\]/)[1].capitalize
|
14
14
|
super(attribute, field_name, options).html_safe
|
@@ -23,11 +23,13 @@ module LocalizedFields
|
|
23
23
|
|
24
24
|
value = translations.has_key?(language.to_s) ? translations[language.to_s] : nil
|
25
25
|
|
26
|
-
|
26
|
+
options = options.merge(:value => value, :id => "#{object_name}_#{attribute}_translations_#{language}", :name => "#{object_name}[#{attribute}_translations][#{language}]")
|
27
27
|
else
|
28
28
|
value = @object ? @object[attribute.to_s] : nil
|
29
|
-
|
29
|
+
options = options.merge(:value => value)
|
30
30
|
end
|
31
|
+
|
32
|
+
super(attribute, options).html_safe
|
31
33
|
end
|
32
34
|
|
33
35
|
def text_area(attribute, options = {})
|
@@ -38,12 +40,14 @@ module LocalizedFields
|
|
38
40
|
|
39
41
|
value = translations.has_key?(language.to_s) ? translations[language.to_s] : nil
|
40
42
|
|
41
|
-
|
43
|
+
options = options.merge(:value => value, :id => "#{object_name}_#{attribute}_translations_#{language}", :name => "#{object_name}[#{attribute}_translations][#{language}]")
|
42
44
|
else
|
43
45
|
value = @object ? @object[attribute.to_s] : nil
|
44
46
|
|
45
|
-
|
47
|
+
options = options.merge(:value => value)
|
46
48
|
end
|
49
|
+
|
50
|
+
super(attribute, options).html_safe
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
data/localized_fields.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.add_dependency 'mongoid', '>= 2.4.0'
|
12
12
|
gem.add_dependency 'actionpack', '>= 3.1.0'
|
13
13
|
|
14
|
-
gem.add_development_dependency 'rspec'
|
14
|
+
gem.add_development_dependency 'rspec', '~> 2.8.0'
|
15
15
|
|
16
16
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
17
|
gem.files = `git ls-files`.split("\n")
|
@@ -53,6 +53,18 @@ describe 'LocalizedFields' do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
+
describe 'language' do
|
57
|
+
it 'should return the language' do
|
58
|
+
output = @builder.localized_fields do |localized_field|
|
59
|
+
"<h2>#{localized_field.language}</h2>".html_safe
|
60
|
+
end
|
61
|
+
|
62
|
+
expected = '<h2>en</h2><h2>pt</h2>'
|
63
|
+
|
64
|
+
output.should eq(expected)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
56
68
|
describe 'label' do
|
57
69
|
it 'should return a label tag for en' do
|
58
70
|
output = @builder.localized_fields(:title) do |localized_field|
|
@@ -74,6 +86,17 @@ describe 'LocalizedFields' do
|
|
74
86
|
|
75
87
|
output.should eq(expected)
|
76
88
|
end
|
89
|
+
|
90
|
+
it 'should return label tags with options' do
|
91
|
+
output = @builder.localized_fields do |localized_field|
|
92
|
+
localized_field.label :title, :class => 'field'
|
93
|
+
end
|
94
|
+
|
95
|
+
expected = '<label class="field" for="post_title_translations_en">Title</label>' +
|
96
|
+
'<label class="field" for="post_title_translations_pt">Title</label>'
|
97
|
+
|
98
|
+
output.should eq(expected)
|
99
|
+
end
|
77
100
|
end
|
78
101
|
|
79
102
|
describe 'text_field' do
|
@@ -97,6 +120,17 @@ describe 'LocalizedFields' do
|
|
97
120
|
|
98
121
|
output.should eq(expected)
|
99
122
|
end
|
123
|
+
|
124
|
+
it 'should return text_field tags with options' do
|
125
|
+
output = @builder.localized_fields do |localized_field|
|
126
|
+
localized_field.text_field :title, :class => 'field'
|
127
|
+
end
|
128
|
+
|
129
|
+
expected = '<input class="field" id="post_title_translations_en" name="post[title_translations][en]" size="30" type="text" />' +
|
130
|
+
'<input class="field" id="post_title_translations_pt" name="post[title_translations][pt]" size="30" type="text" />'
|
131
|
+
|
132
|
+
output.should eq(expected)
|
133
|
+
end
|
100
134
|
end
|
101
135
|
|
102
136
|
describe 'text_area' do
|
@@ -121,6 +155,17 @@ describe 'LocalizedFields' do
|
|
121
155
|
output.should eq(expected)
|
122
156
|
end
|
123
157
|
|
158
|
+
it 'should return text_area tags with options' do
|
159
|
+
output = @builder.localized_fields do |localized_field|
|
160
|
+
localized_field.text_area :title, :class => 'field'
|
161
|
+
end
|
162
|
+
|
163
|
+
expected = '<textarea class="field" cols="40" id="post_title_translations_en" name="post[title_translations][en]" rows="20"></textarea>' +
|
164
|
+
'<textarea class="field" cols="40" id="post_title_translations_pt" name="post[title_translations][pt]" rows="20"></textarea>'
|
165
|
+
|
166
|
+
output.should eq(expected)
|
167
|
+
end
|
168
|
+
|
124
169
|
context 'post with values' do
|
125
170
|
before do
|
126
171
|
@post = Post.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localized_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mongoid
|
16
|
-
requirement: &
|
16
|
+
requirement: &2151861200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.4.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2151861200
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: actionpack
|
27
|
-
requirement: &
|
27
|
+
requirement: &2151859980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,18 +32,18 @@ dependencies:
|
|
32
32
|
version: 3.1.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2151859980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &2151859240 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
|
-
- -
|
41
|
+
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 2.8.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2151859240
|
47
47
|
description: Helps you to create forms with localized fields using Mongoid.
|
48
48
|
email:
|
49
49
|
- tiagogodinho3@gmail.com
|