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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e6313bfb853eb9c2ffdb532ead82e060e628de9be0a6e1c8e15da81cd672ce7
|
4
|
+
data.tar.gz: 91cc1e5a97dc2c40c004f70923d2be7db773db3f763b242329a94380f3c44f42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
7
|
+
$ rails generate admin_model ModelName FieldName:FieldType FieldName:FieldType
|
8
8
|
```
|
9
9
|
|
10
10
|
## Installation
|
data/lib/admin_model/version.rb
CHANGED
data/lib/admin_model.rb
CHANGED
@@ -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
|
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
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
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}
|
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
|
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.
|
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:
|
11
|
+
date: 2021-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|