mongoid_i18n_embedded 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +13 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +25 -0
- data/lib/mongoid/i18n/configuration.rb +11 -0
- data/lib/mongoid/i18n/internationalized_data.rb +14 -0
- data/lib/mongoid/i18n.rb +46 -0
- metadata +65 -0
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
group :development, :test do
|
4
|
+
gem "bson_ext"
|
5
|
+
gem "rails", "3.0.10"
|
6
|
+
gem "capybara", "~> 1.0.1"
|
7
|
+
gem "rspec-rails", "~> 2.6"
|
8
|
+
gem "simplecov", :require => false
|
9
|
+
gem "factory_girl_rails"
|
10
|
+
gem "ffaker"
|
11
|
+
end
|
12
|
+
|
13
|
+
gemspec
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
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.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'MongoidI18nEmbedded'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module I18n
|
3
|
+
module InternationalizedData
|
4
|
+
def self.generate(parent)
|
5
|
+
obj = Class.new do
|
6
|
+
include Mongoid::Document
|
7
|
+
field :language
|
8
|
+
embedded_in parent.name.downcase.to_sym, :inverse_of => :internationalized_data
|
9
|
+
end
|
10
|
+
parent.const_set(:InternationalizedData, obj)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/mongoid/i18n.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require "mongoid"
|
2
|
+
require "mongoid/i18n/configuration"
|
3
|
+
require "mongoid/i18n/internationalized_data"
|
4
|
+
|
5
|
+
module Mongoid
|
6
|
+
module I18n
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
Mongoid::I18n::InternationalizedData.generate(self)
|
11
|
+
embeds_many :internationalized_data, :class_name => "#{self.name}::InternationalizedData"
|
12
|
+
accepts_nested_attributes_for :internationalized_data
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_reader :configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.setup
|
20
|
+
@configuration = Mongoid::I18n::Configuration.new
|
21
|
+
yield(@configuration)
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def internationalized_field(name, options = {})
|
26
|
+
"#{self.name}::InternationalizedData".constantize.field name, options
|
27
|
+
|
28
|
+
define_method(name) do
|
29
|
+
i18n_data ||= self.internationalized_data.where(:language => ::I18n.locale.to_s).first
|
30
|
+
i18n_data.nil? ? "" : i18n_data.send(name)
|
31
|
+
end
|
32
|
+
|
33
|
+
Mongoid::I18n.configuration.locales.each do |l|
|
34
|
+
n = "#{name}_#{l.to_s.gsub('-', '_')}"
|
35
|
+
define_method(n) do
|
36
|
+
i18n_data ||= self.internationalized_data.where(:language => l.to_s).first
|
37
|
+
i18n_data.nil? ? "" : i18n_data.send(name)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module InstanceMethods
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_i18n_embedded
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- lucas renan
|
9
|
+
- tiago godinho
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-11-07 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mongoid
|
17
|
+
requirement: &2153538220 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.2'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2153538220
|
26
|
+
description: This gem provides functionalities to manipulate internationalized data
|
27
|
+
using Mongoid.
|
28
|
+
email: contato@lucasrenan.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/mongoid/i18n/configuration.rb
|
34
|
+
- lib/mongoid/i18n/internationalized_data.rb
|
35
|
+
- lib/mongoid/i18n.rb
|
36
|
+
- MIT-LICENSE
|
37
|
+
- Rakefile
|
38
|
+
- Gemfile
|
39
|
+
- README.rdoc
|
40
|
+
homepage: https://github.com/lucasrenan/mongoid-i18n-embedded
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.11
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: This gem provides functionalities to manipulate internationalized data using
|
64
|
+
Mongoid.
|
65
|
+
test_files: []
|