same_table_translation 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate translation Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,19 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ I18n.available_locales.each do |locale|
4
+ <% attachment_names.each do |attribute| -%>
5
+ add_column :<%= table_name %>, [:<%= attribute %>, locale].join("_").to_sym, :string
6
+ <% end -%>
7
+ end
8
+
9
+ <% attachment_names.each do |attribute| -%>
10
+ <% klass = table_name.to_s.classify.constantize -%>
11
+ <% if klass.attribute_names.include? attribute.to_s -%>
12
+ <%= klass %>.all.each do |<%= klass.to_s.singularize.downcase %>|
13
+ <%= klass.to_s.singularize.downcase %>.update_attribute :<%= [attribute, I18n.default_locale].join("_") %>, <%= klass.to_s.singularize.downcase %>.<%= attribute %>
14
+ end
15
+ remove_column :<%= table_name %>, :<%= attribute %>
16
+ <% end -%>
17
+ <% end -%>
18
+ end
19
+ end
@@ -0,0 +1,37 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/active_record'
3
+
4
+ module SameTableTranslation
5
+
6
+ class TranslateGenerator < Rails::Generators::NamedBase
7
+ include Rails::Generators::Migration
8
+
9
+ argument :attachment_names, required: true, type: :array, desc: "The names of the attributes to translate."
10
+
11
+ def self.source_root
12
+ @source_root ||= File.expand_path('../templates', __FILE__)
13
+ end
14
+
15
+ def self.next_migration_number(path)
16
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
17
+ end
18
+
19
+ def generate_migration
20
+ migration_template "translate_migration.rb.erb", "db/migrate/#{migration_file_name}"
21
+ end
22
+
23
+ protected
24
+
25
+ def migration_name
26
+ "translate_#{attachment_names.join("_")}_to_#{name.underscore.pluralize}"
27
+ end
28
+
29
+ def migration_file_name
30
+ "#{migration_name}.rb"
31
+ end
32
+
33
+ def migration_class_name
34
+ migration_name.camelize
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
- module SameTableTranslation
2
- VERSION = "0.0.3"
3
- end
1
+ module SameTableTranslation
2
+ VERSION = "0.0.5"
3
+ end
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["anthony.estebe@gmail.com"]
11
11
  gem.description = %q{Translate a simple attribute in all your locales }
12
12
  gem.summary = %q{This is similar to most of other translation plugin in rails but usefull if you want to translate in few language because we don't need any join like others plugins. }
13
- gem.homepage = "https://github.com/antho1404/translatable"
13
+ gem.homepage = "https://github.com/antho1404/same_table_translation"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: same_table_translation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-20 00:00:00.000000000 Z
12
+ date: 2012-10-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Translate a simple attribute in all your locales '
15
15
  email:
@@ -23,12 +23,13 @@ files:
23
23
  - LICENSE.txt
24
24
  - README.md
25
25
  - Rakefile
26
+ - lib/generators/same_table_translation/USAGE
27
+ - lib/generators/same_table_translation/templates/translate_migration.rb.erb
28
+ - lib/generators/same_table_translation/translate_generator.rb
26
29
  - lib/same_table_translation.rb
27
30
  - lib/same_table_translation/version.rb
28
31
  - same_table_translation.gemspec
29
- - untitled.sublime-project
30
- - untitled.sublime-workspace
31
- homepage: https://github.com/antho1404/translatable
32
+ homepage: https://github.com/antho1404/same_table_translation
32
33
  licenses: []
33
34
  post_install_message:
34
35
  rdoc_options: []
@@ -1,8 +0,0 @@
1
- {
2
- "folders":
3
- [
4
- {
5
- "path": "/home/antho/prog/same_table_translation"
6
- }
7
- ]
8
- }