mongomapper_i18n 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,25 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ *.gem
23
+ tmp
24
+ .yardoc
25
+ doc/*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Julio Santos Monteiro
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.
data/README.mkdn ADDED
@@ -0,0 +1,34 @@
1
+ # MongoMapper I18n (mongomapper_i18n)
2
+
3
+ I18n for MongoMapper, just as in ActiveRecord
4
+
5
+ ## Installing
6
+
7
+ * Write in `config/environment.rb` the following line: `gem "mongomapper_i18n", :lib => "mongo_mapper/i18n"`
8
+
9
+ * And at your locale YAML, for example `config/locales/pt.yml`, use this template:
10
+
11
+ pt:
12
+ mongomapper:
13
+ models:
14
+ user: "Usuário"
15
+ attributes:
16
+ user:
17
+ email: "E-mail"
18
+ password: "Senha"
19
+ password_confirmation: "Confirmação de senha"
20
+ remember_me: "Lembrar de mim"
21
+
22
+ ## Note on Patches/Pull Requests
23
+
24
+ * Fork the project.
25
+ * Make your feature addition or bug fix.
26
+ * Add tests for it. This is important so I don't break it in a
27
+ future version unintentionally.
28
+ * Commit, do not mess with rakefile, version, or history.
29
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
30
+ * Send me a pull request. Bonus points for topic branches.
31
+
32
+ ## Copyright
33
+
34
+ Copyright (c) 2010 Julio Monteiro. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,56 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "mongomapper_i18n"
8
+ gem.summary = %Q{I18n for MongoMapper, just as in ActiveRecord}
9
+ gem.description = %Q{I18n for MongoMapper, just as in ActiveRecord}
10
+ gem.email = "julio@monteiro.eti.br"
11
+ gem.homepage = "http://github.com/jmonteiro/mongomapper_i18n"
12
+ gem.authors = ["Julio Monteiro"]
13
+
14
+ gem.add_dependency "mongo_mapper", ">= 0.7.0"
15
+ gem.add_development_dependency 'jnunemaker-matchy', '>= 0.4.0'
16
+ gem.add_development_dependency 'shoulda', ">= 2.10.3"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "mongomapper_i18n #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+
3
+ gem 'mongo_mapper', '>= 0.7.0' if self.class.const_defined?(:Gem)
4
+ require 'mongo_mapper'
5
+
6
+ module MongoMapper
7
+ module Plugins
8
+ module Rails
9
+ module ClassMethods
10
+ def self_and_descendants#nodoc:
11
+ klass = self
12
+ classes = [klass]
13
+ while klass != klass.base_class
14
+ classes << klass = klass.superclass
15
+ end
16
+ classes
17
+ rescue
18
+ [self]
19
+ end
20
+
21
+ # Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example:
22
+ # Person.human_attribute_name("first_name") # => "First name"
23
+ # This used to be depricated in favor of humanize, but is now preferred, because it automatically uses the I18n
24
+ # module now.
25
+ # Specify +options+ with additional translating options.
26
+ def human_attribute_name(attribute_key_name, options = {})
27
+ defaults = self_and_descendants.map do |klass|
28
+ :"#{klass.name.underscore}.#{attribute_key_name}"
29
+ end
30
+ defaults << options[:default] if options[:default]
31
+ defaults.flatten!
32
+ defaults << attribute_key_name.to_s.humanize
33
+ options[:count] ||= 1
34
+ I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => [:mongo_mapper, :attributes]))
35
+ end
36
+
37
+ # Transform the modelname into a more humane format, using I18n.
38
+ # Defaults to the basic humanize method.
39
+ # Default scope of the translation is mongo_mapper.models
40
+ # Specify +options+ with additional translating options.
41
+ def human_name(options = {})
42
+ defaults = self_and_descendants.map do |klass|
43
+ :"#{klass.name.underscore}"
44
+ end
45
+ defaults << self.name.humanize
46
+ I18n.translate(defaults.shift, {:scope => [:mongo_mapper, :models], :count => 1, :default => defaults}.merge(options))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
data/test/helper.rb ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ if self.class.const_defined?(:Gem)
5
+ gem 'jnunemaker-matchy', '0.4.0'
6
+ gem 'shoulda', '>= 2.10.3'
7
+ end
8
+
9
+ require 'matchy'
10
+ require 'shoulda'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'mongo_mapper/i18n'
15
+
16
+ class Test::Unit::TestCase
17
+ def Doc(name=nil, &block)
18
+ klass = Class.new do
19
+ include MongoMapper::Document
20
+ set_collection_name "test#{rand(20)}"
21
+
22
+ if name
23
+ class_eval "def self.name; '#{name}' end"
24
+ class_eval "def self.to_s; '#{name}' end"
25
+ end
26
+ end
27
+
28
+ klass.class_eval(&block) if block_given?
29
+ klass.collection.remove
30
+ klass
31
+ end
32
+
33
+ def EDoc(name=nil, &block)
34
+ klass = Class.new do
35
+ include MongoMapper::EmbeddedDocument
36
+
37
+ if name
38
+ class_eval "def self.name; '#{name}' end"
39
+ class_eval "def self.to_s; '#{name}' end"
40
+ end
41
+ end
42
+
43
+ klass.class_eval(&block) if block_given?
44
+ klass
45
+ end
46
+
47
+ def drop_indexes(klass)
48
+ if klass.database.collection_names.include?(klass.collection.name)
49
+ klass.collection.drop_indexes
50
+ end
51
+ end
52
+ end
53
+
54
+ test_dir = File.expand_path(File.dirname(__FILE__) + '/../tmp')
55
+ FileUtils.mkdir_p(test_dir) unless File.exist?(test_dir)
56
+
57
+ MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, {:logger => Logger.new(test_dir + '/test.log')})
58
+ MongoMapper.database = 'test'
@@ -0,0 +1,46 @@
1
+ require 'helper'
2
+
3
+ class TestI18n < Test::Unit::TestCase
4
+ context "Document" do
5
+ setup do
6
+ @klass = Doc('Post') do
7
+ key :foo, String
8
+ end
9
+ end
10
+
11
+ context "Class methods" do
12
+ should "implement self_and_descendants" do
13
+ @klass.self_and_descendants.should == [@klass]
14
+ end
15
+
16
+ should "implement human_name" do
17
+ @klass.human_name.should == 'Post'
18
+ end
19
+
20
+ should "implement human_attribute_name" do
21
+ @klass.human_attribute_name(:foo).should == 'Foo'
22
+ end
23
+ end
24
+ end
25
+
26
+ context "EmbeddedDocument" do
27
+ setup do
28
+ @klass = EDoc('Post') { key :foo, String }
29
+ end
30
+
31
+ context "Class methods" do
32
+ should "implement self_and_descendants" do
33
+ @klass.self_and_descendants.should == [@klass]
34
+ end
35
+
36
+ should "implement human_name" do
37
+ @klass.human_name.should == 'Post'
38
+ end
39
+
40
+ should "implement human_attribute_name" do
41
+ @klass.human_attribute_name(:foo).should == 'Foo'
42
+ end
43
+ end
44
+ end
45
+ end
46
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongomapper_i18n
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julio Monteiro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-15 00:00:00 -02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongo_mapper
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.7.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: jnunemaker-matchy
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: shoulda
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.10.3
44
+ version:
45
+ description: I18n for MongoMapper, just as in ActiveRecord
46
+ email: julio@monteiro.eti.br
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.mkdn
54
+ files:
55
+ - .gitignore
56
+ - LICENSE
57
+ - README.mkdn
58
+ - Rakefile
59
+ - VERSION
60
+ - lib/mongo_mapper/i18n.rb
61
+ - test/helper.rb
62
+ - test/unit/test_i18n.rb
63
+ has_rdoc: true
64
+ homepage: http://github.com/jmonteiro/mongomapper_i18n
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --charset=UTF-8
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.5
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: I18n for MongoMapper, just as in ActiveRecord
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/unit/test_i18n.rb