admin_model 0.1.2 → 0.2.0

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: '058844618f73072571d2302ea717c31883ef58b0a82444fff503036dc25f4e99'
4
- data.tar.gz: 942b16e015124d4ebe1ee4973089b8b201c1b352dc020a819dc00a5e2060c242
3
+ metadata.gz: 5e6313bfb853eb9c2ffdb532ead82e060e628de9be0a6e1c8e15da81cd672ce7
4
+ data.tar.gz: 91cc1e5a97dc2c40c004f70923d2be7db773db3f763b242329a94380f3c44f42
5
5
  SHA512:
6
- metadata.gz: 5c6c9927edbe561973f00aa1960e5eb7046b3b833a038921f88bd83ba4b3a0facd00eb5e3c72548784c192ce10f99e868671819de84963ac461ee3904a0f3ab7
7
- data.tar.gz: 3a873e903ca6887791c9045b88cba7558220ad14e89d8ba387f1f9dde72f9ae786cacffb205a4dc9fca8d5a21d922b0eeef883ae6b3d58d5e77f9666866097a1
6
+ metadata.gz: d28ad2798145eb3c47a4f4b6b2b6d149d7ff72745d3e9480d062e0f58fccd6d0a78864f66110e901d8d069d2fd93223007e3849a766b004e3501c058240ac3ca
7
+ data.tar.gz: 89e8057bee38550f0ae1caddbcee4c74c76d083b9f126b936e9dc0bcf88b87f16b58d7c7b9660a0a4224f658a6415ebdb9644055843917f15900011c9e039092
data/README.md CHANGED
@@ -4,7 +4,7 @@ Admin model is a rails gem who includes a generator to quickly create rails admi
4
4
  ## Usage
5
5
  This gem use the same syntax as the rails model generator
6
6
  ```sh
7
- $ rails generate model ModelName FieldName:FieldType FieldName:FieldType
7
+ $ rails generate admin_model ModelName FieldName:FieldType FieldName:FieldType
8
8
  ```
9
9
 
10
10
  ## Installation
@@ -1,3 +1,3 @@
1
1
  module AdminModels
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/admin_model.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "admin_model/railtie"
2
2
 
3
- module AdminModels
3
+ module AdminModel
4
4
  # Your code goes here...
5
5
  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
 
@@ -8,6 +10,7 @@ class AdminModelGenerator < Rails::Generators::NamedBase
8
10
  end
9
11
 
10
12
  def crate_rails_admin_concern
13
+ @class_name = class_name
11
14
  @fields_list = ''
12
15
  @attributes.each do |attribute|
13
16
  @fields_list << "\n field :#{attribute.name}"
@@ -19,7 +22,40 @@ class AdminModelGenerator < Rails::Generators::NamedBase
19
22
  inject_into_class "app/models/#{file_name}.rb", class_name, " include RailsAdmin::#{class_name}\n"
20
23
  end
21
24
 
22
- 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
23
59
  inject_into_file 'config/locales/pt-BR.yml', after: "\n models:\n" do
24
60
  <<-YML
25
61
  #{name}:
@@ -27,16 +63,29 @@ class AdminModelGenerator < Rails::Generators::NamedBase
27
63
  other: please fill me
28
64
  YML
29
65
  end
30
- model_attriutes = ''
31
- @attributes.each do |attribute|
32
- 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"
33
71
  end
34
- 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
35
74
  <<-YML
36
- #{name}: please fill me#{model_attriutes}
75
+ #{name}:\n <<: *default_attributes#{model_attriutes}
37
76
  YML
38
77
  end
39
78
  end
40
79
 
41
-
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
42
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.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alberto Bazilio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2021-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails