easy_globalize3_accessors 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,8 @@
1
- = EasyGlobalizeAccessors
1
+ = EasyGlobalize3Accessors
2
2
 
3
3
  == Introduction
4
4
 
5
- Generator of easy accessor methods for models using Globalize2.
5
+ Generator of easy accessor methods for models using Globalize3.
6
6
 
7
7
  Use globalize_accessors with list of translated fields you want easy access to and extra :locales array listing locales for which you want the accessors to be generated.
8
8
 
@@ -11,7 +11,7 @@ This way a single form can be used to edit given model fields with all anticipat
11
11
 
12
12
  == Installation
13
13
 
14
- script/plugin install git://github.com/tomash/easy_globalize2_accessors.git
14
+ gem install easy_globalize3_accessors
15
15
 
16
16
  == Example
17
17
 
@@ -19,14 +19,32 @@ Definition like this:
19
19
 
20
20
  class Product
21
21
  translates :title, :description
22
- globalize_accessors :pl, :en, :de
22
+ globalize_accessors :locales => [:en, :pl], :attributes => [:title]
23
23
  end
24
24
 
25
- Gives you access to methods: title_pl, title_en, title_de, title_pl=, title_en=, title_de= (and similar set of description_* methods). And they work seamlessly with Globalize2 (not even touching the "core" title, title= methods used by Globalize2 itself).
25
+ Gives you access to methods: title_pl, title_en, title_pl=, title_en= (and similar set of description_* methods). And they work seamlessly with Globalize3 (not even touching the "core" title, title= methods used by Globalize3 itself).
26
26
 
27
- == TODO
27
+ :locales and :attributes are optional. Default values are:
28
+ :locales => I18n.available_locales
29
+ :attributes => translated_attribute_names
28
30
 
29
- * Make it work with full-blown locales including dash character (minus sign) like en-US, en-GB, pl-PL etc.
31
+ which means that skipping all options will generate you accessor method for all translated fields and available languages
32
+
33
+ == Always define accessors
34
+
35
+ If you wish to always define accessors and don't want to write globalize_accessors in every class, you can extend ActiveRecord::Base with such module:
36
+
37
+ module TranslatesWithAccessors
38
+
39
+ def translates(*params)
40
+ options = params.extract_options!
41
+ options.reverse_merge!(:globalize_accessors => true)
42
+ accessors = options.delete(:globalize_accessors)
43
+ super
44
+ globalize_accessors if accessors
45
+ end
46
+
47
+ end
30
48
 
31
49
  == blah blah
32
50
 
@@ -4,9 +4,9 @@ require 'globalize3'
4
4
  module EasyGlobalize3Accessors
5
5
 
6
6
  def globalize_accessors(options = {})
7
- options.reverse_merge!(:languages => I18n.available_locales, :attributes => translated_attribute_names)
7
+ options.reverse_merge!(:locales => I18n.available_locales, :attributes => translated_attribute_names)
8
8
 
9
- each_attribute_and_language(options) do |attr_name, locale|
9
+ each_attribute_and_locale(options) do |attr_name, locale|
10
10
  define_accessors(attr_name, locale)
11
11
  end
12
12
  end
@@ -33,9 +33,9 @@ module EasyGlobalize3Accessors
33
33
  end
34
34
  end
35
35
 
36
- def each_attribute_and_language(options)
36
+ def each_attribute_and_locale(options)
37
37
  options[:attributes].each do |attr_name|
38
- options[:languages].each do |locale|
38
+ options[:locales].each do |locale|
39
39
  yield attr_name, locale
40
40
  end
41
41
  end
@@ -1,3 +1,3 @@
1
1
  module EasyGlobalize3Accessors
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Tomasz Stachewicz