venomi 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddfc04a06214a2d1493f1c0cd68959115f2b8e64
4
- data.tar.gz: 3ae0fec69397ea89bf515707dd9c534a9eaf1404
3
+ metadata.gz: bdfe5cb92d029ab926fd9516985cdd6d7ce4c847
4
+ data.tar.gz: dbe657a8ff762bdc06c30b91d6d73d837831c179
5
5
  SHA512:
6
- metadata.gz: 1238996bb5132f1fa6a76df4a552381fa7df4b1fa6ba75f8cc23a885335457e6ea3580593a4db92b61d92744eb4400863afefda39cdb914f4d0580240988ca3f
7
- data.tar.gz: bcea754bcf97742e0ce50896bd7683d5b2e3301cb26f9eabda23b8822088f912b44dbe08237c33574257033921532f7641d2c4088b67159554747ca7a9d308b4
6
+ metadata.gz: 8c2c90aee469846e71ed0ef5e475b60399d390779e857808781dd9fa702c4708304233f25ef116386f39c0804b8f9876374c62ceafcfc339e376724947a88826
7
+ data.tar.gz: 523e59f67875eb800bf2e862e1af6e5bcaad380ec0250c8dd329deee8aff668f73a006dbd0de636c60cea20b03f55760f14051cd5515d18fb9e32af146d98330
data/README.md CHANGED
@@ -28,11 +28,11 @@ Or install it yourself as:
28
28
 
29
29
  ## Usage
30
30
 
31
- rails g venomi:install
31
+ rails g venomi:install TRANSLATION_TABLE_NAME
32
32
 
33
33
  ## Uninstall
34
34
 
35
- rails d venomi:install
35
+ rails d venomi:install TRANSLATION_TABLE_NAME
36
36
 
37
37
  ## Contributing
38
38
 
@@ -1,3 +1,3 @@
1
1
  require_relative("../../lib/i18n/backend/mongoid")
2
2
 
3
- I18n.backend = I18n::Backend::Chain.new( I18n::Backend::Simple.new, I18n::Backend::Mongoid.new(Translation) )
3
+ I18n.backend = I18n::Backend::Chain.new( I18n::Backend::Simple.new, I18n::Backend::Mongoid.new(<%= table_name %>) )
@@ -1,4 +1,4 @@
1
- class Translation
1
+ class <%= table_name %>
2
2
  include Mongoid::Document
3
3
 
4
4
  after_save do
@@ -8,11 +8,13 @@ module Venomi
8
8
  include Venomi::Generators::Utils::InstanceMethods
9
9
  source_root File.expand_path("../../templates", __FILE__)
10
10
 
11
+ argument :translation_table_name, :type => :string
12
+
11
13
  def copy_initializer
12
14
  if libraries_available?("mongoid", "rails-i18n")
13
15
  template "mongoid.rb", "lib/i18n/backend/mongoid.rb"
14
- template "translation.rb", "app/models/translation.rb"
15
- template "locale.rb", "config/initializers/locale.rb"
16
+ template "translation.rb.erb", "app/models/#{table_name.downcase}.rb"
17
+ template "locale.rb.erb", "config/initializers/locale.rb"
16
18
  else
17
19
  say("Mongoid or rails-i18n aren't installed!", :yellow)
18
20
  end
@@ -22,15 +24,20 @@ module Venomi
22
24
  case self.behavior
23
25
  when :invoke
24
26
  if libraries_available?("mongoid","rails_admin")
25
- Venomi::RailsAdmin.configure
27
+ Venomi::RailsAdmin.configure table_name
26
28
  else
27
29
  say("Rails-admin isn`t required or installed!", :yellow)
28
30
  end
29
31
  when :revoke
30
- Venomi::RailsAdmin.rollback
32
+ Venomi::RailsAdmin.rollback table_name
31
33
  end
32
34
  end
33
35
 
36
+ private
37
+ def table_name
38
+ translation_table_name.downcase.capitalize
39
+ end
40
+
34
41
  end
35
42
  end
36
43
  end
@@ -19,7 +19,8 @@ module Venomi
19
19
  class << self
20
20
  include Venomi::Generators::Utils::InstanceMethods
21
21
 
22
- def configure
22
+ def configure(table = "Translation")
23
+ init_parts_for(table)
23
24
  if file?(@rails_admin_root)
24
25
  unless file_include?(@rails_admin_root, "config.model Translation do")
25
26
  replace(@rails_admin_root, "RailsAdmin.config do |config|", ("RailsAdmin.config do |config|\n" + @translation))
@@ -35,7 +36,8 @@ module Venomi
35
36
  end
36
37
  end
37
38
 
38
- def rollback
39
+ def rollback(table = "Translation")
40
+ init_parts_for(table)
39
41
  if file? @rails_admin_root
40
42
  text = File.read(@rails_admin_root)
41
43
  text.gsub!(@delete, " delete\n")
@@ -44,34 +46,37 @@ module Venomi
44
46
  File.open(@rails_admin_root, "w") {|file| file.puts text }
45
47
  end
46
48
  end
47
- end
48
49
 
49
- @new = <<-MSG
50
+ def init_parts_for(table_name)
51
+ @table = table_name
52
+ @new = <<-MSG
50
53
  new do
51
- except [:Translation]
54
+ except [:#{@table}]
52
55
  end
53
56
  MSG
54
57
 
55
- @delete = <<-MSG
58
+ @delete = <<-MSG
56
59
  delete do
57
- except [:Translation]
60
+ except [:#{@table}]
58
61
  end
59
62
  MSG
60
63
 
61
- @translation = <<-MSG
62
- config.model Translation do
63
- list do
64
- field :key
65
- field :value
66
- end
67
- edit do
68
- field :key do
69
- read_only true
64
+ @translation = <<-MSG
65
+ config.model #{@table} do
66
+ list do
67
+ field :key
68
+ field :value
69
+ end
70
+ edit do
71
+ field :key do
72
+ read_only true
73
+ end
74
+ field :value
70
75
  end
71
- field :value
72
76
  end
73
- end
74
- MSG
77
+ MSG
78
+ end
75
79
 
80
+ end
76
81
  end
77
82
  end
@@ -1,3 +1,3 @@
1
1
  module Venomi
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: venomi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandr Turchyn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -114,9 +114,9 @@ files:
114
114
  - bin/console
115
115
  - bin/setup
116
116
  - lib/debug/initializers/rails_admin.rb
117
- - lib/generators/templates/locale.rb
117
+ - lib/generators/templates/locale.rb.erb
118
118
  - lib/generators/templates/mongoid.rb
119
- - lib/generators/templates/translation.rb
119
+ - lib/generators/templates/translation.rb.erb
120
120
  - lib/generators/utils.rb
121
121
  - lib/generators/venomi/install_generator.rb
122
122
  - lib/tasks/venomi.rake