globalize3_accessors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ globalize3_accessors (0.1.0)
5
+ activemodel (>= 3.0.0)
6
+ activerecord (>= 3.0.0)
7
+ globalize3 (>= 0.1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ activemodel (3.0.9)
13
+ activesupport (= 3.0.9)
14
+ builder (~> 2.1.2)
15
+ i18n (~> 0.5.0)
16
+ activerecord (3.0.9)
17
+ activemodel (= 3.0.9)
18
+ activesupport (= 3.0.9)
19
+ arel (~> 2.0.10)
20
+ tzinfo (~> 0.3.23)
21
+ activesupport (3.0.9)
22
+ arel (2.0.10)
23
+ builder (2.1.2)
24
+ columnize (0.3.4)
25
+ database_cleaner (0.5.2)
26
+ globalize3 (0.1.0)
27
+ activemodel (>= 3.0.0)
28
+ activerecord (>= 3.0.0)
29
+ i18n (0.5.0)
30
+ linecache (0.46)
31
+ rbx-require-relative (> 0.0.4)
32
+ mocha (0.9.12)
33
+ pathname_local (0.0.2)
34
+ rbx-require-relative (0.0.5)
35
+ ruby-debug (0.10.4)
36
+ columnize (>= 0.1)
37
+ ruby-debug-base (~> 0.10.4.0)
38
+ ruby-debug-base (0.10.4)
39
+ linecache (>= 0.3)
40
+ sqlite3 (1.3.3)
41
+ sqlite3-ruby (1.3.3)
42
+ sqlite3 (>= 1.3.3)
43
+ test_declarative (0.0.5)
44
+ tzinfo (0.3.29)
45
+
46
+ PLATFORMS
47
+ ruby
48
+
49
+ DEPENDENCIES
50
+ database_cleaner (= 0.5.2)
51
+ globalize3_accessors!
52
+ mocha
53
+ pathname_local
54
+ ruby-debug
55
+ sqlite3-ruby
56
+ test_declarative
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tomasz Stachewicz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ h1. Globalize3 Accessors
2
+
3
+ h2. Introduction
4
+
5
+ Generator of easy accessor methods for models using "Globalize3":http://github.com/svenfuchs/globalize3.
6
+
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
+
9
+ This way a single form can be used to edit given model fields with all anticipated translations.
10
+
11
+
12
+ h2. Installation
13
+
14
+ Add this line to Gemfile:
15
+
16
+ gem "globalize3_accessors", :git => 'git://github.com/tomash/globalize3_accessors.git'
17
+
18
+ h2. Example
19
+
20
+ Definition like this:
21
+
22
+ class Product
23
+ translates :title, :description
24
+ globalize_accessors :pl, :en, :de
25
+ end
26
+
27
+ Gives you methods: title_pl, title_en, title_de, title_pl=, title_en=, title_de= (and similar set of description_* methods). And they work seamlessly with Globalize3 (not even touching the "core" title, title= methods used by Globalize3 itself).
28
+
29
+ h2. TODO
30
+
31
+ * Make it work with full-blown locales including dash character (minus sign) like en-US, en-GB, pl-PL etc.
32
+
33
+ h2. License
34
+
35
+ Copyright (c) 2011 Tomek "Tomash" Stachewicz ("homepage":http://tomash.wrug.eu), released under the MIT license.
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the easy_globalize_accessors plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the easy_globalize_accessors plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'EasyGlobalizeAccessors'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,38 @@
1
+ module ActiveRecord
2
+ module GlobalizeAccessors
3
+ def self.included(base)
4
+ base.extend ActMethods
5
+ end
6
+
7
+ module ActMethods
8
+ def globalize_accessors(*attr_names)
9
+ languages = attr_names
10
+ attribs = translated_attribute_names
11
+ attribs.each do |attr_name|
12
+ languages.each do |with_locale|
13
+ define_method :"#{attr_name}_#{with_locale}" do
14
+ if @temp_attributes and @temp_attributes[with_locale][attr_name]
15
+ @temp_attributes[with_locale][attr_name]
16
+ else
17
+ globalize.fetch with_locale, attr_name
18
+ end
19
+ end
20
+
21
+ define_method :"#{attr_name}_#{with_locale}=" do |val|
22
+ initialize_temp_attributes unless @temp_attributes
23
+ @temp_attributes[with_locale][attr_name] = val
24
+ globalize.stash.write with_locale, attr_name, val
25
+ self[attr_name] = val
26
+ end
27
+ end
28
+ end
29
+
30
+ define_method :initialize_temp_attributes do
31
+ @temp_attributes = Hash[*languages.collect { |v| [v, {}]}.flatten]
32
+ end
33
+
34
+ after_save :initialize_temp_attributes
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.send :include, ActiveRecord::GlobalizeAccessors
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: globalize3_accessors
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Tomasz Stachewicz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-10 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activemodel
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 3
48
+ - 0
49
+ - 0
50
+ version: 3.0.0
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: globalize3
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 0
64
+ - 1
65
+ - 0
66
+ version: 0.1.0
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: database_cleaner
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - "="
76
+ - !ruby/object:Gem::Version
77
+ hash: 15
78
+ segments:
79
+ - 0
80
+ - 5
81
+ - 2
82
+ version: 0.5.2
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: mocha
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ type: :development
98
+ version_requirements: *id005
99
+ - !ruby/object:Gem::Dependency
100
+ name: pathname_local
101
+ prerelease: false
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ type: :development
112
+ version_requirements: *id006
113
+ - !ruby/object:Gem::Dependency
114
+ name: test_declarative
115
+ prerelease: false
116
+ requirement: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ type: :development
126
+ version_requirements: *id007
127
+ - !ruby/object:Gem::Dependency
128
+ name: ruby-debug
129
+ prerelease: false
130
+ requirement: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ hash: 3
136
+ segments:
137
+ - 0
138
+ version: "0"
139
+ type: :development
140
+ version_requirements: *id008
141
+ - !ruby/object:Gem::Dependency
142
+ name: sqlite3-ruby
143
+ prerelease: false
144
+ requirement: &id009 !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ hash: 3
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ type: :development
154
+ version_requirements: *id009
155
+ description: Easy accessors for ActiveRecord attributes translated using Globalize3.
156
+ email: tomekrs@o2.pl
157
+ executables: []
158
+
159
+ extensions: []
160
+
161
+ extra_rdoc_files: []
162
+
163
+ files:
164
+ - lib/globalize3_accessors.rb
165
+ - lib/active_record/globalize_accessors.rb
166
+ - Gemfile
167
+ - MIT-LICENSE
168
+ - Rakefile
169
+ - README.textile
170
+ - Gemfile.lock
171
+ has_rdoc: true
172
+ homepage: http://github.com/tomash/globalize3_accessors
173
+ licenses: []
174
+
175
+ post_install_message:
176
+ rdoc_options: []
177
+
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ hash: 3
186
+ segments:
187
+ - 0
188
+ version: "0"
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ none: false
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ hash: 3
195
+ segments:
196
+ - 0
197
+ version: "0"
198
+ requirements: []
199
+
200
+ rubyforge_project: "[none]"
201
+ rubygems_version: 1.3.7
202
+ signing_key:
203
+ specification_version: 3
204
+ summary: Easy accessors for ActiveRecord attributes translated using Globalize3
205
+ test_files: []
206
+