admin_model 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 5c140069752e4e57c2601b57e5f0bdc3e61c85e31413ae560ccb2037d257a598
4
- data.tar.gz: f0d87591488971541832032deca1916904840626456e41a1b2ed43939844c17f
3
+ metadata.gz: e8030d6044ba3d098814a0c8bdab11afffa09974a7501af67529d46d4010fb5f
4
+ data.tar.gz: f6a7bd13edc44eb74dbc89c98e806275dc96dd0ec57492c51116efe5c0370796
5
5
  SHA512:
6
- metadata.gz: 8c4409d2192cbc95b9d431bc3385d94450c4307c94a0f1147238ca2e2984f619c1e6f0d8d4604ff3f59adbbacc63201181ce8da50c4fc00611b990358d738339
7
- data.tar.gz: 7253bb158e81f07594023007a03b2313fca768abb422402d0f7a15f7881c9c603710f874aeb3dbcd558e0a6e870bcf77a7d49e94f4c91e991fc7f11bf9c21bfe
6
+ metadata.gz: 9853593cb88cf29a2ac90a4ecc517216a0c82ec23ce58a6b49bafbb34728feb1717fd1a22bf9511f37bad7cb32e12c627467ec304a97ee89ee67529460e0af37
7
+ data.tar.gz: 67cc136fb042d51ff8f71b12501193dfa054ef95d46b2c81fb8562af977052e428bc6ae51a4449c359485458a7aaa65dc207e54dec6f228e23002ef1c20dcfdf
@@ -1,3 +1,3 @@
1
1
  module AdminModels
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'yaml'
2
+
1
3
  class AdminModelGenerator < Rails::Generators::NamedBase
2
4
  source_root File.expand_path('templates', __dir__)
3
5
 
@@ -20,7 +22,40 @@ class AdminModelGenerator < Rails::Generators::NamedBase
20
22
  inject_into_class "app/models/#{file_name}.rb", class_name, " include RailsAdmin::#{class_name}\n"
21
23
  end
22
24
 
23
- def create_translation_keys
25
+ def get_translation_file
26
+ ptbr = File.read('config/locales/pt-BR.yml')
27
+ @ptbr_hash = YAML.load(ptbr)
28
+ end
29
+
30
+ def insert_deafult_attributes_translations_if_necessary
31
+ if @ptbr_hash["pt-BR"]["activerecord"]["attributes"]["default_attributes"].nil?
32
+ inject_into_file 'config/locales/pt-BR.yml', after: "\n attributes:\n" do
33
+ <<-YML
34
+ default_attributes: &default_attributes
35
+ id: '#'
36
+ name: Nome
37
+ created_at: Data de criação
38
+ updated_at: Data de atualização
39
+ YML
40
+ end
41
+ end
42
+ end
43
+
44
+ def insert_base_errors_translations_if_necessary
45
+ if @ptbr_hash["pt-BR"]["activerecord"]["errors"]["models"]["base_errors"].nil?
46
+ inject_into_file 'config/locales/pt-BR.yml', after: " errors:\n models:\n" do
47
+ <<-YML
48
+ base_errors: &base_errors
49
+ blank: não pode ficar em branco
50
+ invalid: invalido
51
+ required: é requirido
52
+ taken: já existe e deve ser único
53
+ YML
54
+ end
55
+ end
56
+ end
57
+
58
+ def inssert_model_translation_keys
24
59
  inject_into_file 'config/locales/pt-BR.yml', after: "\n models:\n" do
25
60
  <<-YML
26
61
  #{name}:
@@ -28,16 +63,29 @@ class AdminModelGenerator < Rails::Generators::NamedBase
28
63
  other: please fill me
29
64
  YML
30
65
  end
31
- model_attriutes = ''
32
- @attributes.each do |attribute|
33
- model_attriutes << "\n #{attribute.name}: please fill me"
66
+ end
67
+
68
+ def insert_attributes_translation_keys
69
+ model_attriutes = @attributes.reduce('') do |acc, attribute|
70
+ "#{acc}\n #{attribute.name}: please fill me"
34
71
  end
35
- inject_into_file 'config/locales/pt-BR.yml', after: "\n attributes:\n" do
72
+ ptbr = File.read("config/locales/pt-BR.yml")
73
+ inject_into_file 'config/locales/pt-BR.yml', after: ptbr[/pt-BR:\n(.*\n)* {2}activerecord:\n(.*\n)* {4}attributes:\n( {6}.+(\n( {8}.+\n)+))+/] do
36
74
  <<-YML
37
- #{name}:#{model_attriutes}
75
+ #{name}:\n <<: *default_attributes#{model_attriutes}
38
76
  YML
39
77
  end
40
78
  end
41
79
 
42
-
80
+ def insert_attributes_errors_translation_keys
81
+ model_attriutes = @attributes.reduce('') do |acc, attribute|
82
+ "#{acc}\n #{attribute.name}:\n <<: *base_errors"
83
+ end
84
+ ptbr = File.read("config/locales/pt-BR.yml")
85
+ inject_into_file 'config/locales/pt-BR.yml', after: ptbr[/pt-BR:\n(.*\n)* {2}activerecord:\n(.*\n)* {4}errors:\n(.*\n)* {6}models:\n( {8}.+(\n( {10}.+\n)+))+/] do
86
+ <<-YML
87
+ #{name}:\n attributes:#{model_attriutes}
88
+ YML
89
+ end
90
+ end
43
91
  end
@@ -7,6 +7,7 @@ module RailsAdmin::<%= @class_name %>
7
7
  field :created_at
8
8
  field :updated_at
9
9
  end
10
+
10
11
  create do<%= @fields_list %>
11
12
  end
12
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: admin_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alberto Bazilio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-03 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails