admin_model 0.1.4 → 0.2.1

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: bacb984cb5145c08980e17f42291b7614b4ef6767b912794140aee813c70b00c
4
+ data.tar.gz: a01a66662dfd0219aa96b4aa71faf946dc999e38730ff246814ed4b0cbc4924c
5
5
  SHA512:
6
- metadata.gz: 8c4409d2192cbc95b9d431bc3385d94450c4307c94a0f1147238ca2e2984f619c1e6f0d8d4604ff3f59adbbacc63201181ce8da50c4fc00611b990358d738339
7
- data.tar.gz: 7253bb158e81f07594023007a03b2313fca768abb422402d0f7a15f7881c9c603710f874aeb3dbcd558e0a6e870bcf77a7d49e94f4c91e991fc7f11bf9c21bfe
6
+ metadata.gz: e98569a4c4809f7362306c453945cde759240e3553d25ab349c26df56df2e17cf1046afbc669d6f1ec21de3ef0581fa263bc8a20d11f58b1c6045569292a6814
7
+ data.tar.gz: 64158658398ebec5c815eed2303ecc0fceacb6f752ee0d17f8a4873de7e366eb08464af2c231e3cbfdfe1346dcd739a8efc34213fa442a9f59a3b44189019d0b
@@ -1,3 +1,3 @@
1
1
  module AdminModels
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.1'
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
 
@@ -8,36 +10,56 @@ class AdminModelGenerator < Rails::Generators::NamedBase
8
10
  end
9
11
 
10
12
  def crate_rails_admin_concern
11
- @class_name = class_name
13
+ @pascal_name = class_name.singularize
14
+ @snake_name = file_name.singularize
12
15
  @fields_list = ''
13
16
  @attributes.each do |attribute|
14
17
  @fields_list << "\n field :#{attribute.name}"
15
18
  end
16
- template 'admin_model.template', "app/models/concerns/rails_admin/#{file_name}.rb"
19
+ template 'admin_model.template', "app/models/concerns/rails_admin/#{@snake_name}.rb"
17
20
  end
18
21
 
19
22
  def include_rails_admin
20
- inject_into_class "app/models/#{file_name}.rb", class_name, " include RailsAdmin::#{class_name}\n"
23
+ inject_into_class "app/models/#{@snake_name}.rb", @pascal_name, " include RailsAdmin::#{@pascal_name}\n"
21
24
  end
22
25
 
23
- def create_translation_keys
24
- inject_into_file 'config/locales/pt-BR.yml', after: "\n models:\n" do
26
+ def get_translation_file
27
+ @ptbr_path = 'config/locales/pt-BR.yml'
28
+ ptbr = File.read(@ptbr_path)
29
+ @ptbr_hash = YAML.load(ptbr)
30
+ end
31
+ def inssert_model_translation_keys
32
+ ptbr = File.read(@ptbr_path)
33
+ inject_into_file @ptbr_path, after: ptbr[/pt-BR:\n(.*\n)* {2}activerecord:\n(.*\n)* {4}models:\n( {6}.+(\n( {8}.+\n)+))+/] do
25
34
  <<-YML
26
- #{name}:
35
+ #{@snake_name}:
27
36
  one: please fill me
28
37
  other: please fill me
29
38
  YML
30
39
  end
31
- model_attriutes = ''
32
- @attributes.each do |attribute|
33
- model_attriutes << "\n #{attribute.name}: please fill me"
40
+ end
41
+
42
+ def insert_attributes_translation_keys
43
+ model_attriutes = @attributes.reduce('') do |acc, attribute|
44
+ "#{acc}\n #{attribute.name}: please fill me"
34
45
  end
35
- inject_into_file 'config/locales/pt-BR.yml', after: "\n attributes:\n" do
46
+ ptbr = File.read(@ptbr_path)
47
+ inject_into_file @ptbr_path, after: ptbr[/pt-BR:\n(.*\n)* {2}activerecord:\n(.*\n)* {4}attributes:\n( {6}.+(\n( {8}.+\n)+))+/] do
36
48
  <<-YML
37
- #{name}:#{model_attriutes}
49
+ #{@snake_name}:#{model_attriutes}
38
50
  YML
39
51
  end
40
52
  end
41
53
 
42
-
54
+ def insert_attributes_errors_translation_keys
55
+ model_attriutes = @attributes.reduce('') do |acc, attribute|
56
+ "#{acc}\n #{attribute.name}:"
57
+ end
58
+ ptbr = File.read(@ptbr_path)
59
+ inject_into_file @ptbr_path, after: ptbr[/pt-BR:\n(.*\n)* {2}activerecord:\n(.*\n)* {4}errors:\n(.*\n)* {6}models:\n( {8}.+(\n( {10}.+\n)+))+/] do
60
+ <<-YML
61
+ #{@snake_name}:\n attributes:#{model_attriutes}
62
+ YML
63
+ end
64
+ end
43
65
  end
@@ -1,4 +1,4 @@
1
- module RailsAdmin::<%= @class_name %>
1
+ module RailsAdmin::<%= @pascal_name %>
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
@@ -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.2.1
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: 2022-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -59,7 +59,6 @@ files:
59
59
  - lib/admin_model/version.rb
60
60
  - lib/generators/admin_model/admin_model_generator.rb
61
61
  - lib/generators/admin_model/templates/admin_model.template
62
- - lib/tasks/admin_model_tasks.rake
63
62
  homepage: https://github.com/albertobazilio98/admin_model
64
63
  licenses:
65
64
  - MIT
@@ -79,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
78
  - !ruby/object:Gem::Version
80
79
  version: '0'
81
80
  requirements: []
82
- rubygems_version: 3.0.8
81
+ rubygems_version: 3.2.3
83
82
  signing_key:
84
83
  specification_version: 4
85
84
  summary: Quickly create rails admin stuff
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :admin_model do
3
- # # Task goes here
4
- # end