babylonia 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +29 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/README.rdoc +85 -0
- data/babylonia.gemspec +22 -0
- data/lib/babylonia.rb +1 -0
- data/lib/babylonia/class_methods.rb +63 -0
- data/lib/babylonia/version.rb +3 -0
- data/spec/babylonia/class_methods_spec.rb +243 -0
- data/spec/spec_helper.rb +21 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 073d7b1426c878adc6e781b9f92c312ffc839b24
|
4
|
+
data.tar.gz: 1a2e6c6ee29702aa1a4e2dce7cd9dc0532d1dd52
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b100a52c1ec74ee94b59389474f0e41b5518d379f10df37344d244edceeda4cc7cda92f925ad8338d888a1bea7f59f4418bcf6bcc85393028feac458d38c9d22
|
7
|
+
data.tar.gz: 4698094b8e16d962b870b02b37c8b8fad5fba9d928a77456120bfe3d2d155a4415a60bdb5622136ca71daa5b524455f89eeeeebfbaa36452a4feef23e2ae1417
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
babylonia (0.1.0)
|
5
|
+
i18n (>= 0.5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
i18n (0.6.5)
|
12
|
+
rspec (2.14.1)
|
13
|
+
rspec-core (~> 2.14.0)
|
14
|
+
rspec-expectations (~> 2.14.0)
|
15
|
+
rspec-mocks (~> 2.14.0)
|
16
|
+
rspec-core (2.14.7)
|
17
|
+
rspec-expectations (2.14.4)
|
18
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
19
|
+
rspec-mocks (2.14.4)
|
20
|
+
yard (0.8.7.3)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
babylonia!
|
27
|
+
bundler (>= 1.0.0)
|
28
|
+
rspec
|
29
|
+
yard (>= 0.7.4)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Beat
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
= babylonia {<img src="https://secure.travis-ci.org/beatrichartz/babylonia.png?branch=master" />}[http://travis-ci.org/beatrichartz/babylonia] {<img src="https://gemnasium.com/beatrichartz/babylonia.png" alt="Dependency Status" />}[https://gemnasium.com/beatrichartz/babylonia] {<img src="https://codeclimate.com/github/beatrichartz/babylonia.png" />}[https://codeclimate.com/github/beatrichartz/babylonia]
|
2
|
+
Let there be languages for your users!
|
3
|
+
|
4
|
+
== Installation
|
5
|
+
In your gemfile
|
6
|
+
gem "babylonia"
|
7
|
+
Or via the gem command
|
8
|
+
gem install babylonia
|
9
|
+
|
10
|
+
== For Rails
|
11
|
+
Try {babylonia-rails}[http://github.com/beatrichartz/babylonia-rails]
|
12
|
+
|
13
|
+
== Why
|
14
|
+
Out of the necessity to let users translate page content. This gem does not add columns or records to your tables, or tables to your database. It is implemented based on YAML and stores the given data in a string.
|
15
|
+
|
16
|
+
== Persistence is all yours
|
17
|
+
Persistence is all yours. There will be a string for you to store, and you should just make sure it can get stored. That means that depending on the count of languages you let your users handle, and on the length of strings you expect to put them in, you should have a look at the different BLOB types your storage offers. A mysql TEXT field can soon run out of space (it takes up to 21,844 characters), but a MEDIUMTEXT e.g. is pretty gigantic and should keep the crocodiles out of your sewers.
|
18
|
+
|
19
|
+
== Gotchas
|
20
|
+
Since the entire string will get stored in one field, you'll have to stop and ask yourself a question: Do you want to do database queries on the data in different languages? (like, let's say, sort by the translation users put in as an english translation for the field) If yes, it might be better for you to take a column based approach.
|
21
|
+
|
22
|
+
== Basic Usage
|
23
|
+
Let's assume a pretty basic class. Extend it with the Babylonian Class method
|
24
|
+
class Transsylvania
|
25
|
+
extend Babylonia::ClassMethods
|
26
|
+
attr_accessor :text
|
27
|
+
#now, build that tower
|
28
|
+
build_babylonian_tower_on :text
|
29
|
+
end
|
30
|
+
|
31
|
+
Now, do this:
|
32
|
+
|
33
|
+
t = Transsylvania.new
|
34
|
+
I18n.locale = :en
|
35
|
+
t.text = 'Pretty french, ist es nicht?'
|
36
|
+
I18n.locale = :de
|
37
|
+
t.text #=> nil
|
38
|
+
I18n.locale = :en
|
39
|
+
t.text #=> 'Pretty french, ist es nicht?'
|
40
|
+
|
41
|
+
Or this:
|
42
|
+
|
43
|
+
t.text = {en: 'This is english', fr: 'This is french'}
|
44
|
+
I18n.locale = :fr
|
45
|
+
t.text #=> :fr
|
46
|
+
|
47
|
+
== Extended Usage
|
48
|
+
Let's once assume a pretty basic class. Extend it with the Babylonian Class method and add some options
|
49
|
+
class Transsylvania
|
50
|
+
attr_accessor :text, :name
|
51
|
+
|
52
|
+
extend Babylonia::ClassMethods
|
53
|
+
|
54
|
+
def some_locale
|
55
|
+
:it
|
56
|
+
end
|
57
|
+
|
58
|
+
def locale
|
59
|
+
:en
|
60
|
+
end
|
61
|
+
|
62
|
+
#now, build that tower
|
63
|
+
build_babylonian_tower_on :text, :name,
|
64
|
+
locale: :some_locale, # will call the method some_locale on the instance
|
65
|
+
default_locale: lambda {|instance, field| field == :text ? instance.locale : :de}, #will get evaluated at runtime
|
66
|
+
fallback: false #=> will not fallback to default locale if no translation for locale is present
|
67
|
+
placeholder: "<span class='translation missing'>Translation missing in Transsylvania</span>" a placeholder if no translation is present
|
68
|
+
end
|
69
|
+
== Contributing to babylonia
|
70
|
+
|
71
|
+
Please note that only open source APIs can be accepted as contributions to this gem. Private / Premium APIs have to be written as your own extension and will not be added to the gem code.
|
72
|
+
|
73
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
74
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
75
|
+
* Fork the project.
|
76
|
+
* Start a feature/bugfix branch.
|
77
|
+
* Commit and push until you are happy with your contribution.
|
78
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
79
|
+
* Make sure to add documentation for it. This is important so everyone else can see what your code can do.
|
80
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
81
|
+
|
82
|
+
== Copyright
|
83
|
+
|
84
|
+
Copyright (c) 2013 Beat Richartz. See LICENSE.txt for
|
85
|
+
further details.
|
data/babylonia.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
|
3
|
+
require 'babylonia/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "babylonia"
|
7
|
+
s.version = Babylonia::VERSION
|
8
|
+
s.authors = ["Beat Richartz"]
|
9
|
+
s.description = "Let your users translate their content into their languages without additional tables or columns in your tables"
|
10
|
+
s.email = "attr_accessor@gmail.com"
|
11
|
+
s.licenses = ["MIT"]
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.summary = "Let there be languages!"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.add_dependency "i18n", ">= 0.5.0"
|
20
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
21
|
+
end
|
22
|
+
|
data/lib/babylonia.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "babylonia/class_methods"
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'i18n'
|
3
|
+
|
4
|
+
module Babylonia
|
5
|
+
module ClassMethods
|
6
|
+
def build_babylonian_tower_on(*fields)
|
7
|
+
babylonian_options = fields.last.is_a?(Hash) ? fields.pop : {}
|
8
|
+
babylonian_options[:locale] ||= lambda { |r, f| I18n.locale }
|
9
|
+
babylonian_options[:default_locale] ||= lambda { |r, f| I18n.default_locale }
|
10
|
+
babylonian_options[:fallback] = true if babylonian_options[:fallback].nil?
|
11
|
+
|
12
|
+
# loop through fields to define methods such as "name" and "description"
|
13
|
+
fields.each do |field|
|
14
|
+
instance_variable_set(:"@babylonian_options_for_#{field}", babylonian_options)
|
15
|
+
|
16
|
+
define_method :"#{field}_translated" do |locale=nil|
|
17
|
+
field_hash = send(:"#{field}_hash")
|
18
|
+
translation = field_hash[locale || evaluate_babylonian_option!(:locale, field)]
|
19
|
+
translation = field_hash[evaluate_babylonian_option!(:default_locale, field)] if (translation.nil? or translation.empty?) and evaluate_babylonian_option!(:fallback, field)
|
20
|
+
(translation.nil? or translation.empty?) ? evaluate_babylonian_option!(:placeholder, field) : translation
|
21
|
+
end
|
22
|
+
alias_method :"#{field}_raw", field
|
23
|
+
alias_method field, :"#{field}_translated"
|
24
|
+
|
25
|
+
define_method :"#{field}_hash" do
|
26
|
+
field_content = send(:"#{field}_raw")
|
27
|
+
field_content.is_a?(String) ? YAML.load(field_content) : {}
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method :"#{field}_languages" do
|
31
|
+
send(:"#{field}_hash").keys
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method :"#{field}_translated=" do |data|
|
35
|
+
current_hash = send(:"#{field}_hash")
|
36
|
+
|
37
|
+
if data.is_a?(String)
|
38
|
+
current_hash.merge! evaluate_babylonian_option!(:locale, field) => data
|
39
|
+
elsif data.is_a?(Hash)
|
40
|
+
current_hash.merge! data
|
41
|
+
end
|
42
|
+
|
43
|
+
send(:"#{field}_raw=", YAML.dump(current_hash))
|
44
|
+
end
|
45
|
+
alias_method :"#{field}_raw=", :"#{field}="
|
46
|
+
alias_method :"#{field}=", :"#{field}_translated="
|
47
|
+
end
|
48
|
+
|
49
|
+
define_method :evaluate_babylonian_option! do |option, field|
|
50
|
+
options = self.class.instance_variable_get :"@babylonian_options_for_#{field}"
|
51
|
+
|
52
|
+
o = options[option]
|
53
|
+
if o.is_a? Proc
|
54
|
+
o.call self, field
|
55
|
+
elsif o.is_a? Symbol
|
56
|
+
send o
|
57
|
+
else
|
58
|
+
o
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,243 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Babylonia::ClassMethods do
|
4
|
+
|
5
|
+
class BabylonianFields
|
6
|
+
extend Babylonia::ClassMethods
|
7
|
+
|
8
|
+
attr_accessor :marshes, :grasslands, :desert, :sky
|
9
|
+
|
10
|
+
build_babylonian_tower_on :marshes
|
11
|
+
build_babylonian_tower_on :grasslands, locales: %i(pi de en), locale: :architects_tongue, default_locale: lambda {|r, f| r.builders_tongue || :en }
|
12
|
+
build_babylonian_tower_on :desert, :sky, fallback: false, placeholder: lambda {|r, field| "<span class='missing translation'>Translation missing for " + field.to_s + "</span>"}
|
13
|
+
|
14
|
+
def architects_tongue
|
15
|
+
:pi
|
16
|
+
end
|
17
|
+
|
18
|
+
def builders_tongue
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "without options" do
|
24
|
+
subject { BabylonianFields.new }
|
25
|
+
before(:each) do
|
26
|
+
I18n.stub locale: :en, default_locale: :de
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#marshes" do
|
30
|
+
context "with no data" do
|
31
|
+
it "should return nil" do
|
32
|
+
subject.marshes.should be_nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "with some raw data" do
|
36
|
+
before(:each) do
|
37
|
+
subject.stub marshes_raw: "---\n:en: TRANSLATION\n:de: FALLBACK"
|
38
|
+
end
|
39
|
+
it "should return the data" do
|
40
|
+
subject.marshes.should == "TRANSLATION"
|
41
|
+
end
|
42
|
+
context "with a locale argument" do
|
43
|
+
it "should return the translation in that locale" do
|
44
|
+
subject.marshes(:de).should == 'FALLBACK'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
context "with only fallback data" do
|
49
|
+
before(:each) do
|
50
|
+
subject.stub marshes_raw: "---\n:de: FALLBACK"
|
51
|
+
end
|
52
|
+
it "should return the fallback data" do
|
53
|
+
subject.marshes.should == "FALLBACK"
|
54
|
+
end
|
55
|
+
context "with a locale argument" do
|
56
|
+
it "should return the fallback" do
|
57
|
+
subject.marshes(:en).should == 'FALLBACK'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
context "with data in neither the current nor the fallback language" do
|
62
|
+
before(:each) do
|
63
|
+
subject.stub marshes_raw: "---\n:it: NO_FALLBACK"
|
64
|
+
end
|
65
|
+
it "should return the fallback data" do
|
66
|
+
subject.marshes.should be_nil
|
67
|
+
end
|
68
|
+
context "with a locale argument" do
|
69
|
+
it "should return the fallback" do
|
70
|
+
subject.marshes(:en).should be_nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
describe "marshes=" do
|
76
|
+
context "with no existing data" do
|
77
|
+
context "with a string" do
|
78
|
+
it "should set the current locales data" do
|
79
|
+
subject.marshes = 'SOME ENGLISH'
|
80
|
+
subject.marshes_raw.should == "---\n:en: SOME ENGLISH\n"
|
81
|
+
subject.marshes.should == 'SOME ENGLISH'
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context "with a hash" do
|
85
|
+
it "should merge that hash with the existing data, if any" do
|
86
|
+
subject.marshes = {en: 'SOME ENGLISH', de: 'SOME DEUTSCH'}
|
87
|
+
subject.marshes_raw.should == "---\n:en: SOME ENGLISH\n:de: SOME DEUTSCH\n"
|
88
|
+
subject.marshes.should == 'SOME ENGLISH'
|
89
|
+
subject.marshes(:de).should == 'SOME DEUTSCH'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
context "with existing data" do
|
94
|
+
before(:each) do
|
95
|
+
subject.marshes_raw = "---\n:it: SOME ITALIAN"
|
96
|
+
end
|
97
|
+
context "with a string" do
|
98
|
+
it "should set the current locales data" do
|
99
|
+
subject.marshes = 'SOME ENGLISH'
|
100
|
+
subject.marshes_raw.should == "---\n:it: SOME ITALIAN\n:en: SOME ENGLISH\n"
|
101
|
+
subject.marshes.should == 'SOME ENGLISH'
|
102
|
+
subject.marshes(:it).should == 'SOME ITALIAN'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
context "with a hash" do
|
106
|
+
it "should merge that hash with the existing data, if any" do
|
107
|
+
subject.marshes = {en: 'SOME ENGLISH', de: 'SOME DEUTSCH'}
|
108
|
+
subject.marshes_raw.should == "---\n:it: SOME ITALIAN\n:en: SOME ENGLISH\n:de: SOME DEUTSCH\n"
|
109
|
+
subject.marshes.should == 'SOME ENGLISH'
|
110
|
+
subject.marshes(:de).should == 'SOME DEUTSCH'
|
111
|
+
subject.marshes(:it).should == 'SOME ITALIAN'
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
describe "marshes_hash" do
|
117
|
+
before(:each) do
|
118
|
+
subject.marshes_raw = "---\n:it: SOME ITALIAN\n:en: SOME ENGLISH\n:de: SOME DEUTSCH\n"
|
119
|
+
end
|
120
|
+
it "should return the loaded hash of the field" do
|
121
|
+
subject.marshes_hash.should == {it: 'SOME ITALIAN', en: 'SOME ENGLISH', de: 'SOME DEUTSCH'}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
describe "marshes_languages" do
|
125
|
+
before(:each) do
|
126
|
+
subject.marshes_raw = "---\n:it: SOME ITALIAN\n:en: SOME ENGLISH\n:de: SOME DEUTSCH\n"
|
127
|
+
end
|
128
|
+
it "should return the translated languages of the field" do
|
129
|
+
subject.marshes_languages.sort.should == %i(de en it)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "with options" do
|
135
|
+
subject { BabylonianFields.new }
|
136
|
+
before(:each) do
|
137
|
+
I18n.stub locale: :en, default_locale: :de
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "#grasslands" do
|
141
|
+
context "with no data" do
|
142
|
+
it "should return nil" do
|
143
|
+
subject.grasslands.should be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
context "with some raw data" do
|
147
|
+
before(:each) do
|
148
|
+
subject.stub grasslands_raw: "---\n:pi: TRANSLATION\n:de: FALLBACK"
|
149
|
+
end
|
150
|
+
it "should return the data" do
|
151
|
+
subject.grasslands.should == "TRANSLATION"
|
152
|
+
end
|
153
|
+
context "with a locale argument" do
|
154
|
+
it "should return the translation in that locale" do
|
155
|
+
subject.grasslands(:de).should == 'FALLBACK'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
context "with only fallback data" do
|
160
|
+
before(:each) do
|
161
|
+
subject.stub grasslands_raw: "---\n:en: FALLBACK"
|
162
|
+
end
|
163
|
+
it "should return the fallback data" do
|
164
|
+
subject.grasslands.should == "FALLBACK"
|
165
|
+
end
|
166
|
+
context "with a locale argument" do
|
167
|
+
it "should return the fallback" do
|
168
|
+
subject.grasslands(:pi).should == 'FALLBACK'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
context "with data in neither the current nor the fallback language" do
|
173
|
+
before(:each) do
|
174
|
+
subject.stub grasslands_raw: "---\n:it: NO_FALLBACK"
|
175
|
+
end
|
176
|
+
it "should return the fallback data" do
|
177
|
+
subject.grasslands.should be_nil
|
178
|
+
end
|
179
|
+
context "with a locale argument" do
|
180
|
+
it "should return the fallback" do
|
181
|
+
subject.grasslands(:en).should be_nil
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
context "with fallback data, but fallback disabled" do
|
186
|
+
before(:each) do
|
187
|
+
subject.stub desert_raw: "---\n:it: NO_FALLBACK"
|
188
|
+
end
|
189
|
+
it "should not return the fallback data and display the placeholder" do
|
190
|
+
subject.desert.should == "<span class='missing translation'>Translation missing for desert</span>"
|
191
|
+
end
|
192
|
+
context "with a locale argument" do
|
193
|
+
it "should not return the fallback and display the placeholder" do
|
194
|
+
subject.desert(:pi).should == "<span class='missing translation'>Translation missing for desert</span>"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
describe "grasslands=" do
|
200
|
+
context "with no existing data" do
|
201
|
+
context "with a string" do
|
202
|
+
it "should set the current locales data" do
|
203
|
+
subject.grasslands = 'SOME PIRATE'
|
204
|
+
subject.grasslands_raw.should == "---\n:pi: SOME PIRATE\n"
|
205
|
+
subject.grasslands.should == 'SOME PIRATE'
|
206
|
+
end
|
207
|
+
end
|
208
|
+
context "with a hash" do
|
209
|
+
it "should merge that hash with the existing data, if any" do
|
210
|
+
subject.grasslands = {pi: 'SOME PIRATE', de: 'SOME DEUTSCH'}
|
211
|
+
subject.grasslands_raw.should == "---\n:pi: SOME PIRATE\n:de: SOME DEUTSCH\n"
|
212
|
+
subject.grasslands.should == 'SOME PIRATE'
|
213
|
+
subject.grasslands(:de).should == 'SOME DEUTSCH'
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
context "with existing data" do
|
218
|
+
before(:each) do
|
219
|
+
subject.grasslands_raw = "---\n:it: SOME ITALIAN"
|
220
|
+
end
|
221
|
+
context "with a string" do
|
222
|
+
it "should set the current locales data" do
|
223
|
+
subject.grasslands = 'SOME PIRATE'
|
224
|
+
subject.grasslands_raw.should == "---\n:it: SOME ITALIAN\n:pi: SOME PIRATE\n"
|
225
|
+
subject.grasslands.should == 'SOME PIRATE'
|
226
|
+
subject.grasslands(:it).should == 'SOME ITALIAN'
|
227
|
+
end
|
228
|
+
end
|
229
|
+
context "with a hash" do
|
230
|
+
it "should merge that hash with the existing data, if any" do
|
231
|
+
subject.grasslands = {pi: 'SOME PIRATE', de: 'SOME DEUTSCH'}
|
232
|
+
subject.grasslands_raw.should == "---\n:it: SOME ITALIAN\n:pi: SOME PIRATE\n:de: SOME DEUTSCH\n"
|
233
|
+
subject.grasslands.should == 'SOME PIRATE'
|
234
|
+
subject.grasslands(:de).should == 'SOME DEUTSCH'
|
235
|
+
subject.grasslands(:it).should == 'SOME ITALIAN'
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler'
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :test)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'babylonia'
|
16
|
+
|
17
|
+
module HelperMethods
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.configuration.include(HelperMethods)
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: babylonia
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Beat Richartz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: i18n
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.5.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
description: Let your users translate their content into their languages without additional
|
42
|
+
tables or columns in your tables
|
43
|
+
email: attr_accessor@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .rspec
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- README.md
|
54
|
+
- README.rdoc
|
55
|
+
- babylonia.gemspec
|
56
|
+
- lib/babylonia.rb
|
57
|
+
- lib/babylonia/class_methods.rb
|
58
|
+
- lib/babylonia/version.rb
|
59
|
+
- spec/babylonia/class_methods_spec.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
homepage:
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Let there be languages!
|
85
|
+
test_files:
|
86
|
+
- spec/babylonia/class_methods_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
has_rdoc:
|