lolita-translation 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
- module LolitaHasTranslation
2
- class Engine < Rails::Engine
3
-
4
- end
1
+ module LolitaHasTranslation
2
+ class Engine < Rails::Engine
3
+
4
+ end
5
5
  end
@@ -1,19 +1,19 @@
1
- class String
2
- attr_accessor :origin_model, :origin_name
3
- def set_origins obj, name
4
- self.origin_model = obj
5
- self.origin_name = name
6
- self
7
- end
8
- # forces given locale
9
- # I18n.locale = :lv
10
- # a = Article.find 18
11
- # a.title
12
- # => "LV title"
13
- # a.title.in(:en)
14
- # => "EN title"
15
- def in locale
16
- return self unless self.origin_model
17
- translation = self.origin_model.in(locale) and translation.send(self.origin_name)
18
- end
1
+ class String
2
+ attr_accessor :origin_model, :origin_name
3
+ def set_origins obj, name
4
+ self.origin_model = obj
5
+ self.origin_name = name
6
+ self
7
+ end
8
+ # forces given locale
9
+ # I18n.locale = :lv
10
+ # a = Article.find 18
11
+ # a.title
12
+ # => "LV title"
13
+ # a.title.in(:en)
14
+ # => "EN title"
15
+ def in locale
16
+ return self unless self.origin_model
17
+ translation = self.origin_model.in(locale) and translation.send(self.origin_name)
18
+ end
19
19
  end
@@ -1,4 +1,4 @@
1
- # desc "Explaining what the task does"
2
- # task :has_translations do
3
- # # Task goes here
4
- # end
1
+ # desc "Explaining what the task does"
2
+ # task :has_translations do
3
+ # # Task goes here
4
+ # end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{lolita-translation}
8
- s.version = "0.0.4"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["ITHouse", "Gatis Tomsons", "Arturs Meisters"]
12
- s.date = %q{2011-08-10}
11
+ s.authors = [%q{ITHouse}, %q{Gatis Tomsons}, %q{Arturs Meisters}]
12
+ s.date = %q{2011-08-29}
13
13
  s.description = %q{Translates models in Lolita}
14
14
  s.email = %q{support@ithouse.lv}
15
15
  s.extra_rdoc_files = [
@@ -23,27 +23,31 @@ Gem::Specification.new do |s|
23
23
  "README.md",
24
24
  "Rakefile",
25
25
  "VERSION",
26
- "app/views/components/lolita/configuration/tab/translation/_display.html.erb",
26
+ "app/views/components/lolita/translation/_assets.html.erb",
27
+ "app/views/components/lolita/translation/_language_wrap.html.erb",
28
+ "app/views/components/lolita/translation/_switch.html.erb",
27
29
  "config/locales/en.yml",
28
30
  "config/locales/lv.yml",
29
31
  "lib/generators/lolita_translation/USAGE",
32
+ "lib/generators/lolita_translation/assets_generator.rb",
30
33
  "lib/generators/lolita_translation/has_translations_generator.rb",
34
+ "lib/generators/lolita_translation/install_generator.rb",
31
35
  "lib/lolita-translation.rb",
32
- "lib/lolita-translation/configuration/tab/translation.rb",
33
36
  "lib/lolita-translation/has_translations.rb",
34
37
  "lib/lolita-translation/rails.rb",
35
38
  "lib/lolita-translation/string.rb",
36
39
  "lib/tasks/has_translations_tasks.rake",
37
40
  "lolita-translation.gemspec",
38
- "lolita-translations.gemspec",
41
+ "public/javascripts/lolita/translation.js",
42
+ "public/stylesheets/lolita/translation.css",
39
43
  "spec/has_translations_spec.rb",
40
44
  "spec/spec.opts",
41
45
  "spec/spec_helper.rb"
42
46
  ]
43
47
  s.homepage = %q{http://github.com/ithouse/lolita-translations}
44
- s.licenses = ["MIT"]
45
- s.require_paths = ["lib"]
46
- s.rubygems_version = %q{1.6.2}
48
+ s.licenses = [%q{MIT}]
49
+ s.require_paths = [%q{lib}]
50
+ s.rubygems_version = %q{1.8.8}
47
51
  s.summary = %q{Lolita models translation plugin}
48
52
  s.test_files = [
49
53
  "spec/has_translations_spec.rb",
@@ -0,0 +1,10 @@
1
+ $(function(){
2
+ $(".tab-language-switch li").click(function(){
3
+ $(".tab-language-switch li").removeClass("active")
4
+ $(this).addClass("active");
5
+ var locale = $(this).attr("data-locale")
6
+ var tab_name = $(this).attr("data-tab")
7
+ $(".tab-content .language-wrap").hide(0)
8
+ $("#"+locale+"_attributes_for_"+tab_name).show(0)
9
+ })
10
+ })
@@ -0,0 +1,18 @@
1
+ .tab-language-switch{
2
+ float: right;
3
+ overflow: hidden;
4
+ list-style: none;
5
+ margin-right: 25px;
6
+ margin-top: 28px;
7
+ }
8
+ .tab-language-switch li{
9
+ float:left;
10
+ margin-left:10px;
11
+ color: #C3C3C3;
12
+ cursor:pointer;
13
+ }
14
+ .tab-language-switch li.active{
15
+ color: #444;
16
+ font-weight: bold;
17
+ cursor:default;
18
+ }
@@ -1,43 +1,43 @@
1
- # encoding: utf-8
2
- require File.dirname(__FILE__) + '/spec_helper'
3
-
4
- describe 'HasTranslations' do
5
- it "should switch locales" do
6
- g = Group.create!(:name => "Sport")
7
- c = Category.create!(:name => "Golf", :groups => [g])
8
- z = News.create!(:title => "Tiger Woods sucks", :body => Faker::Lorem::paragraphs(10).join, :category_id => c.id)
9
- # translate
10
- g.translations.create!(:locale => 'lv', :name => "Sports")
11
- c.translations.create!(:locale => 'lv', :name => "Golfs")
12
- z.translations.create!(:locale => 'lv', :title => "Taigers Vuds nekam neder")
13
-
14
- g.name.should == "Sport"
15
- c.name.should == "Golf"
16
- z.title.should == "Tiger Woods sucks"
17
-
18
- I18n.locale = :lv
19
-
20
- g.name.should == "Sports"
21
- c.name.should == "Golfs"
22
- z.title.should == "Taigers Vuds nekam neder"
23
-
24
- z.category.name.should == "Golfs"
25
- z.category.groups.first.name.should == "Sports"
26
-
27
- z.destroy
28
- c.destroy
29
- g.destroy
30
- #--------------------------------
31
- I18n.locale = I18n.default_locale
32
- end
33
-
34
- it "should load requested locale with 'in' method" do
35
- g = Group.create!(:name => "Sport")
36
- g.translations.create!(:locale => 'lv', :name => "Sports")
37
-
38
- g = Group.find_by_name "Sport"
39
- g.name.should == "Sport"
40
- g.name.in(:lv).should == "Sports"
41
- g.name.should == "Sport"
42
- end
43
- end
1
+ # encoding: utf-8
2
+ require File.dirname(__FILE__) + '/spec_helper'
3
+
4
+ describe 'HasTranslations' do
5
+ it "should switch locales" do
6
+ g = Group.create!(:name => "Sport")
7
+ c = Category.create!(:name => "Golf", :groups => [g])
8
+ z = News.create!(:title => "Tiger Woods sucks", :body => Faker::Lorem::paragraphs(10).join, :category_id => c.id)
9
+ # translate
10
+ g.translations.create!(:locale => 'lv', :name => "Sports")
11
+ c.translations.create!(:locale => 'lv', :name => "Golfs")
12
+ z.translations.create!(:locale => 'lv', :title => "Taigers Vuds nekam neder")
13
+
14
+ g.name.should == "Sport"
15
+ c.name.should == "Golf"
16
+ z.title.should == "Tiger Woods sucks"
17
+
18
+ I18n.locale = :lv
19
+
20
+ g.name.should == "Sports"
21
+ c.name.should == "Golfs"
22
+ z.title.should == "Taigers Vuds nekam neder"
23
+
24
+ z.category.name.should == "Golfs"
25
+ z.category.groups.first.name.should == "Sports"
26
+
27
+ z.destroy
28
+ c.destroy
29
+ g.destroy
30
+ #--------------------------------
31
+ I18n.locale = I18n.default_locale
32
+ end
33
+
34
+ it "should load requested locale with 'in' method" do
35
+ g = Group.create!(:name => "Sport")
36
+ g.translations.create!(:locale => 'lv', :name => "Sports")
37
+
38
+ g = Group.find_by_name "Sport"
39
+ g.name.should == "Sport"
40
+ g.name.in(:lv).should == "Sports"
41
+ g.name.should == "Sport"
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
- --colour
2
- --reverse
1
+ --colour
2
+ --reverse
3
3
  --backtrace
@@ -1,98 +1,98 @@
1
- # encoding: utf-8
2
- require 'rubygems'
3
- gem 'rails', '~>2.3'
4
- require 'i18n'
5
- require 'active_record'
6
- require 'spec'
7
- require 'faker'
8
-
9
- require 'ruby-debug'
10
-
11
- require File.dirname(__FILE__)+'/../init.rb'
12
- ActiveRecord::Base.logger = Logger.new(File.open("#{File.dirname(__FILE__)}/database.log", 'w+'))
13
- ActiveRecord::Base.establish_connection({ :database => ":memory:", :adapter => 'sqlite3', :timeout => 500 })
14
-
15
- # setup I18n
16
- I18n.available_locales = [:en,:lv,:ru,:fr]
17
- I18n.default_locale = :en
18
- I18n.locale = :en
19
-
20
- # Add models
21
- ActiveRecord::Schema.define do
22
- create_table :news, :force => true do |t|
23
- t.string :title
24
- t.string :slug
25
- t.text :body
26
- t.integer :category_id
27
- t.integer :trx_id
28
- end
29
- create_table :categories, :force => true do |t|
30
- t.string :name
31
- t.string :desc
32
- t.integer :trx_id
33
- end
34
- create_table :groups, :force => true do |t|
35
- t.string :name
36
- end
37
- create_table :categories_groups, :force => true, :id => false do |t|
38
- t.integer :category_id
39
- t.integer :group_id
40
- end
41
- create_table :meta_datas, :force => true do |t|
42
- t.string :title
43
- t.string :url
44
- t.string :keywords
45
- t.text :description
46
- t.string :metaable_type
47
- t.integer :metaable_id
48
- end
49
- end
50
-
51
- class News < ActiveRecord::Base
52
- belongs_to :category, :dependent => :destroy
53
- has_one :meta_data, :as => :metaable, :dependent => :destroy
54
- translations :title, :body
55
- end
56
-
57
- class Category < ActiveRecord::Base
58
- has_many :news
59
- has_and_belongs_to_many :groups
60
- translations :name
61
- end
62
-
63
- class Group < ActiveRecord::Base
64
- has_and_belongs_to_many :categories
65
- translations :name
66
- end
67
-
68
- class MetaData < ActiveRecord::Base
69
- belongs_to :metaable, :polymorphic => true
70
- translations :title, :url, :keywords, :description
71
- end
72
-
73
- # build translation tables
74
-
75
- News.sync_translation_table!
76
- Category.sync_translation_table!
77
- Group.sync_translation_table!
78
- MetaData.sync_translation_table!
79
-
80
- # this is included in Lolita by default
81
- class ::Hash
82
- # converts all keys to symbols, but RECURSIVE
83
- def symbolize_keys!
84
- each do |k,v|
85
- sym = k.respond_to?(:to_sym) ? k.to_sym : k
86
- self[sym] = Hash === v ? v.symbolize_keys! : v
87
- delete(k) unless k == sym
88
- end
89
- self
90
- end
91
- end
92
- Spec::Runner.configure do |config|
93
- config.before(:each) do
94
- News.delete_all
95
- Category.delete_all
96
- MetaData.delete_all
97
- end
98
- end
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ gem 'rails', '~>2.3'
4
+ require 'i18n'
5
+ require 'active_record'
6
+ require 'spec'
7
+ require 'faker'
8
+
9
+ require 'ruby-debug'
10
+
11
+ require File.dirname(__FILE__)+'/../init.rb'
12
+ ActiveRecord::Base.logger = Logger.new(File.open("#{File.dirname(__FILE__)}/database.log", 'w+'))
13
+ ActiveRecord::Base.establish_connection({ :database => ":memory:", :adapter => 'sqlite3', :timeout => 500 })
14
+
15
+ # setup I18n
16
+ I18n.available_locales = [:en,:lv,:ru,:fr]
17
+ I18n.default_locale = :en
18
+ I18n.locale = :en
19
+
20
+ # Add models
21
+ ActiveRecord::Schema.define do
22
+ create_table :news, :force => true do |t|
23
+ t.string :title
24
+ t.string :slug
25
+ t.text :body
26
+ t.integer :category_id
27
+ t.integer :trx_id
28
+ end
29
+ create_table :categories, :force => true do |t|
30
+ t.string :name
31
+ t.string :desc
32
+ t.integer :trx_id
33
+ end
34
+ create_table :groups, :force => true do |t|
35
+ t.string :name
36
+ end
37
+ create_table :categories_groups, :force => true, :id => false do |t|
38
+ t.integer :category_id
39
+ t.integer :group_id
40
+ end
41
+ create_table :meta_datas, :force => true do |t|
42
+ t.string :title
43
+ t.string :url
44
+ t.string :keywords
45
+ t.text :description
46
+ t.string :metaable_type
47
+ t.integer :metaable_id
48
+ end
49
+ end
50
+
51
+ class News < ActiveRecord::Base
52
+ belongs_to :category, :dependent => :destroy
53
+ has_one :meta_data, :as => :metaable, :dependent => :destroy
54
+ translations :title, :body
55
+ end
56
+
57
+ class Category < ActiveRecord::Base
58
+ has_many :news
59
+ has_and_belongs_to_many :groups
60
+ translations :name
61
+ end
62
+
63
+ class Group < ActiveRecord::Base
64
+ has_and_belongs_to_many :categories
65
+ translations :name
66
+ end
67
+
68
+ class MetaData < ActiveRecord::Base
69
+ belongs_to :metaable, :polymorphic => true
70
+ translations :title, :url, :keywords, :description
71
+ end
72
+
73
+ # build translation tables
74
+
75
+ News.sync_translation_table!
76
+ Category.sync_translation_table!
77
+ Group.sync_translation_table!
78
+ MetaData.sync_translation_table!
79
+
80
+ # this is included in Lolita by default
81
+ class ::Hash
82
+ # converts all keys to symbols, but RECURSIVE
83
+ def symbolize_keys!
84
+ each do |k,v|
85
+ sym = k.respond_to?(:to_sym) ? k.to_sym : k
86
+ self[sym] = Hash === v ? v.symbolize_keys! : v
87
+ delete(k) unless k == sym
88
+ end
89
+ self
90
+ end
91
+ end
92
+ Spec::Runner.configure do |config|
93
+ config.before(:each) do
94
+ News.delete_all
95
+ Category.delete_all
96
+ MetaData.delete_all
97
+ end
98
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolita-translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,12 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-08-10 00:00:00.000000000 +03:00
15
- default_executable:
14
+ date: 2011-08-29 00:00:00.000000000Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: rails
19
- requirement: &75726130 !ruby/object:Gem::Requirement
18
+ requirement: &81809440 !ruby/object:Gem::Requirement
20
19
  none: false
21
20
  requirements:
22
21
  - - ! '>='
@@ -24,10 +23,10 @@ dependencies:
24
23
  version: 3.0.0
25
24
  type: :runtime
26
25
  prerelease: false
27
- version_requirements: *75726130
26
+ version_requirements: *81809440
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: shoulda
30
- requirement: &75725890 !ruby/object:Gem::Requirement
29
+ requirement: &81807310 !ruby/object:Gem::Requirement
31
30
  none: false
32
31
  requirements:
33
32
  - - ! '>='
@@ -35,10 +34,10 @@ dependencies:
35
34
  version: '0'
36
35
  type: :development
37
36
  prerelease: false
38
- version_requirements: *75725890
37
+ version_requirements: *81807310
39
38
  - !ruby/object:Gem::Dependency
40
39
  name: bundler
41
- requirement: &75725650 !ruby/object:Gem::Requirement
40
+ requirement: &81785300 !ruby/object:Gem::Requirement
42
41
  none: false
43
42
  requirements:
44
43
  - - ~>
@@ -46,10 +45,10 @@ dependencies:
46
45
  version: 1.0.0
47
46
  type: :development
48
47
  prerelease: false
49
- version_requirements: *75725650
48
+ version_requirements: *81785300
50
49
  - !ruby/object:Gem::Dependency
51
50
  name: jeweler
52
- requirement: &75725410 !ruby/object:Gem::Requirement
51
+ requirement: &81784700 !ruby/object:Gem::Requirement
53
52
  none: false
54
53
  requirements:
55
54
  - - ~>
@@ -57,10 +56,10 @@ dependencies:
57
56
  version: 1.5.2
58
57
  type: :development
59
58
  prerelease: false
60
- version_requirements: *75725410
59
+ version_requirements: *81784700
61
60
  - !ruby/object:Gem::Dependency
62
61
  name: rcov
63
- requirement: &75725170 !ruby/object:Gem::Requirement
62
+ requirement: &81784050 !ruby/object:Gem::Requirement
64
63
  none: false
65
64
  requirements:
66
65
  - - ! '>='
@@ -68,7 +67,7 @@ dependencies:
68
67
  version: '0'
69
68
  type: :development
70
69
  prerelease: false
71
- version_requirements: *75725170
70
+ version_requirements: *81784050
72
71
  description: Translates models in Lolita
73
72
  email: support@ithouse.lv
74
73
  executables: []
@@ -83,23 +82,26 @@ files:
83
82
  - README.md
84
83
  - Rakefile
85
84
  - VERSION
86
- - app/views/components/lolita/configuration/tab/translation/_display.html.erb
85
+ - app/views/components/lolita/translation/_assets.html.erb
86
+ - app/views/components/lolita/translation/_language_wrap.html.erb
87
+ - app/views/components/lolita/translation/_switch.html.erb
87
88
  - config/locales/en.yml
88
89
  - config/locales/lv.yml
89
90
  - lib/generators/lolita_translation/USAGE
91
+ - lib/generators/lolita_translation/assets_generator.rb
90
92
  - lib/generators/lolita_translation/has_translations_generator.rb
93
+ - lib/generators/lolita_translation/install_generator.rb
91
94
  - lib/lolita-translation.rb
92
- - lib/lolita-translation/configuration/tab/translation.rb
93
95
  - lib/lolita-translation/has_translations.rb
94
96
  - lib/lolita-translation/rails.rb
95
97
  - lib/lolita-translation/string.rb
96
98
  - lib/tasks/has_translations_tasks.rake
97
99
  - lolita-translation.gemspec
98
- - lolita-translations.gemspec
100
+ - public/javascripts/lolita/translation.js
101
+ - public/stylesheets/lolita/translation.css
99
102
  - spec/has_translations_spec.rb
100
103
  - spec/spec.opts
101
104
  - spec/spec_helper.rb
102
- has_rdoc: true
103
105
  homepage: http://github.com/ithouse/lolita-translations
104
106
  licenses:
105
107
  - MIT
@@ -115,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
117
  version: '0'
116
118
  segments:
117
119
  - 0
118
- hash: -90868109
120
+ hash: 497866193
119
121
  required_rubygems_version: !ruby/object:Gem::Requirement
120
122
  none: false
121
123
  requirements:
@@ -124,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
126
  version: '0'
125
127
  requirements: []
126
128
  rubyforge_project:
127
- rubygems_version: 1.6.2
129
+ rubygems_version: 1.8.8
128
130
  signing_key:
129
131
  specification_version: 3
130
132
  summary: Lolita models translation plugin