ngcrud 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 993fd28fa6e71b33932e02c343e67bdc3543205e2d979852e2eb4c6d89aa4128
4
+ data.tar.gz: be5511a3a24bcd469fab177c52f007aa5ddd83d0ec73594183895d1453de07bd
5
+ SHA512:
6
+ metadata.gz: 619532fc99edcc21e0e5ae42e25b8aec1a2e134a7d84a9cb0e5a787efdbc473660c4c1d98c670b848cd063b7d2f49397c4e802a51ea96f599fd8f6dca84ae47b
7
+ data.tar.gz: f9ee7e43b60370948a1144eada4088971cddf9f3600023607312ba5db95103ddbe82ba2bc328eb2c8c08a089cc7bea8138801519fb5c8a2c2543fb4d6bd76ff6
data/LICENSE ADDED
@@ -0,0 +1,172 @@
1
+ Open Software License ("OSL") v. 3.0
2
+
3
+ This Open Software License (the "License") applies to any original work of
4
+ authorship (the "Original Work") whose owner (the "Licensor") has placed the
5
+ following licensing notice adjacent to the copyright notice for the Original
6
+ Work:
7
+
8
+ Licensed under the Open Software License version 3.0
9
+
10
+ 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free,
11
+ non-exclusive, sublicensable license, for the duration of the copyright, to do
12
+ the following:
13
+
14
+ a) to reproduce the Original Work in copies, either alone or as part of a
15
+ collective work;
16
+
17
+ b) to translate, adapt, alter, transform, modify, or arrange the Original
18
+ Work, thereby creating derivative works ("Derivative Works") based upon the
19
+ Original Work;
20
+
21
+ c) to distribute or communicate copies of the Original Work and Derivative
22
+ Works to the public, with the proviso that copies of Original Work or
23
+ Derivative Works that You distribute or communicate shall be licensed under
24
+ this Open Software License;
25
+
26
+ d) to perform the Original Work publicly; and
27
+
28
+ e) to display the Original Work publicly.
29
+
30
+ 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free,
31
+ non-exclusive, sublicensable license, under patent claims owned or controlled
32
+ by the Licensor that are embodied in the Original Work as furnished by the
33
+ Licensor, for the duration of the patents, to make, use, sell, offer for sale,
34
+ have made, and import the Original Work and Derivative Works.
35
+
36
+ 3. Grant of Source Code License. The term "Source Code" means the preferred
37
+ form of the Original Work for making modifications to it and all available
38
+ documentation describing how to modify the Original Work. Licensor agrees to
39
+ provide a machine-readable copy of the Source Code of the Original Work along
40
+ with each copy of the Original Work that Licensor distributes. Licensor
41
+ reserves the right to satisfy this obligation by placing a machine-readable
42
+ copy of the Source Code in an information repository reasonably calculated to
43
+ permit inexpensive and convenient access by You for as long as Licensor
44
+ continues to distribute the Original Work.
45
+
46
+ 4. Exclusions From License Grant. Neither the names of Licensor, nor the names
47
+ of any contributors to the Original Work, nor any of their trademarks or
48
+ service marks, may be used to endorse or promote products derived from this
49
+ Original Work without express prior permission of the Licensor. Except as
50
+ expressly stated herein, nothing in this License grants any license to
51
+ Licensor's trademarks, copyrights, patents, trade secrets or any other
52
+ intellectual property. No patent license is granted to make, use, sell, offer
53
+ for sale, have made, or import embodiments of any patent claims other than the
54
+ licensed claims defined in Section 2. No license is granted to the trademarks
55
+ of Licensor even if such marks are included in the Original Work. Nothing in
56
+ this License shall be interpreted to prohibit Licensor from licensing under
57
+ terms different from this License any Original Work that Licensor otherwise
58
+ would have a right to license.
59
+
60
+ 5. External Deployment. The term "External Deployment" means the use,
61
+ distribution, or communication of the Original Work or Derivative Works in any
62
+ way such that the Original Work or Derivative Works may be used by anyone
63
+ other than You, whether those works are distributed or communicated to those
64
+ persons or made available as an application intended for use over a network.
65
+ As an express condition for the grants of license hereunder, You must treat
66
+ any External Deployment by You of the Original Work or a Derivative Work as a
67
+ distribution under section 1(c).
68
+
69
+ 6. Attribution Rights. You must retain, in the Source Code of any Derivative
70
+ Works that You create, all copyright, patent, or trademark notices from the
71
+ Source Code of the Original Work, as well as any notices of licensing and any
72
+ descriptive text identified therein as an "Attribution Notice." You must cause
73
+ the Source Code for any Derivative Works that You create to carry a prominent
74
+ Attribution Notice reasonably calculated to inform recipients that You have
75
+ modified the Original Work.
76
+
77
+ 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that
78
+ the copyright in and to the Original Work and the patent rights granted herein
79
+ by Licensor are owned by the Licensor or are sublicensed to You under the
80
+ terms of this License with the permission of the contributor(s) of those
81
+ copyrights and patent rights. Except as expressly stated in the immediately
82
+ preceding sentence, the Original Work is provided under this License on an "AS
83
+ IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without
84
+ limitation, the warranties of non-infringement, merchantability or fitness for
85
+ a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK
86
+ IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this
87
+ License. No license to the Original Work is granted by this License except
88
+ under this disclaimer.
89
+
90
+ 8. Limitation of Liability. Under no circumstances and under no legal theory,
91
+ whether in tort (including negligence), contract, or otherwise, shall the
92
+ Licensor be liable to anyone for any indirect, special, incidental, or
93
+ consequential damages of any character arising as a result of this License or
94
+ the use of the Original Work including, without limitation, damages for loss
95
+ of goodwill, work stoppage, computer failure or malfunction, or any and all
96
+ other commercial damages or losses. This limitation of liability shall not
97
+ apply to the extent applicable law prohibits such limitation.
98
+
99
+ 9. Acceptance and Termination. If, at any time, You expressly assented to this
100
+ License, that assent indicates your clear and irrevocable acceptance of this
101
+ License and all of its terms and conditions. If You distribute or communicate
102
+ copies of the Original Work or a Derivative Work, You must make a reasonable
103
+ effort under the circumstances to obtain the express assent of recipients to
104
+ the terms of this License. This License conditions your rights to undertake
105
+ the activities listed in Section 1, including your right to create Derivative
106
+ Works based upon the Original Work, and doing so without honoring these terms
107
+ and conditions is prohibited by copyright law and international treaty.
108
+ Nothing in this License is intended to affect copyright exceptions and
109
+ limitations (including "fair use" or "fair dealing"). This License shall
110
+ terminate immediately and You may no longer exercise any of the rights granted
111
+ to You by this License upon your failure to honor the conditions in Section
112
+ 1(c).
113
+
114
+ 10. Termination for Patent Action. This License shall terminate automatically
115
+ and You may no longer exercise any of the rights granted to You by this
116
+ License as of the date You commence an action, including a cross-claim or
117
+ counterclaim, against Licensor or any licensee alleging that the Original Work
118
+ infringes a patent. This termination provision shall not apply for an action
119
+ alleging patent infringement by combinations of the Original Work with other
120
+ software or hardware.
121
+
122
+ 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this
123
+ License may be brought only in the courts of a jurisdiction wherein the
124
+ Licensor resides or in which Licensor conducts its primary business, and under
125
+ the laws of that jurisdiction excluding its conflict-of-law provisions. The
126
+ application of the United Nations Convention on Contracts for the
127
+ International Sale of Goods is expressly excluded. Any use of the Original
128
+ Work outside the scope of this License or after its termination shall be
129
+ subject to the requirements and penalties of copyright or patent law in the
130
+ appropriate jurisdiction. This section shall survive the termination of this
131
+ License.
132
+
133
+ 12. Attorneys' Fees. In any action to enforce the terms of this License or
134
+ seeking damages relating thereto, the prevailing party shall be entitled to
135
+ recover its costs and expenses, including, without limitation, reasonable
136
+ attorneys' fees and costs incurred in connection with such action, including
137
+ any appeal of such action. This section shall survive the termination of this
138
+ License.
139
+
140
+ 13. Miscellaneous. If any provision of this License is held to be
141
+ unenforceable, such provision shall be reformed only to the extent necessary
142
+ to make it enforceable.
143
+
144
+ 14. Definition of "You" in This License. "You" throughout this License,
145
+ whether in upper or lower case, means an individual or a legal entity
146
+ exercising rights under, and complying with all of the terms of, this License.
147
+ For legal entities, "You" includes any entity that controls, is controlled by,
148
+ or is under common control with you. For purposes of this definition,
149
+ "control" means (i) the power, direct or indirect, to cause the direction or
150
+ management of such entity, whether by contract or otherwise, or (ii) ownership
151
+ of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial
152
+ ownership of such entity.
153
+
154
+ 15. Right to Use. You may use the Original Work in all ways not otherwise
155
+ restricted or conditioned by this License or by law, and Licensor promises not
156
+ to interfere with or be responsible for such uses by You.
157
+
158
+ 16. Modification of This License. This License is Copyright © 2005 Lawrence
159
+ Rosen. Permission is granted to copy, distribute, or communicate this License
160
+ without modification. Nothing in this License permits You to modify this
161
+ License as applied to the Original Work or to Derivative Works. However, You
162
+ may modify the text of this License and copy, distribute or communicate your
163
+ modified version (the "Modified License") and apply it to other original works
164
+ of authorship subject to the following conditions: (i) You may not indicate in
165
+ any way that your Modified License is the "Open Software License" or "OSL" and
166
+ you may not use those names in the name of your Modified License; (ii) You
167
+ must replace the notice specified in the first paragraph above with the notice
168
+ "Licensed under <insert your license name here>" or with a notice of your own
169
+ that is not confusingly similar to the notice in this License; and (iii) You
170
+ may not claim that your original works are open source software unless your
171
+ Modified License has been approved by Open Source Initiative (OSI) and You
172
+ comply with its license review and certification process.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # NGCRUD Ruby Gem
2
+
3
+ ## Description
4
+
5
+ NGCRUD is a Ruby gem designed to simplify Angular code generation in the command-line interface (CLI), similar to the functionality provided by Rails for Ruby on Rails applications. With NGCRUD, you can effortlessly scaffold Angular components based on your defined models, streamlining the development of Angular applications.
6
+
7
+ This gem is currently in its early stage of development. While I have made efforts to ensure its functionality, it may contain bugs, limitations, or incomplete features. I'm actively working to improve and enhance its performance and functionality.
8
+
9
+ ## Requirements
10
+
11
+ The code generated by this gem requires an installation of Angular, ngx-toastr and the following Angular Firestore modules:
12
+
13
+ - AngularFirestore
14
+ - AngularFirestoreCollection
15
+ - AngularFirestoreDocument
16
+
17
+ ## Installation
18
+
19
+ To install NGCRUD, use RubyGems:
20
+
21
+ ```sh
22
+ gem install ngcrud
23
+ ```
24
+
25
+ ## Use
26
+
27
+ Suppose you want to generate Angular code for a "Contacts" model with the following attributes:
28
+
29
+ - name (string)
30
+ - telephone (string)
31
+ - birth_date (date)
32
+ - active (boolean)
33
+
34
+ ```sh
35
+ ngcrud Contacts name:string telephone:string birth_date:date active:boolean email_marketing:boolean
36
+ ```
37
+
38
+ This will generate inside src/app/features/contacts the following files and code:
39
+
40
+ - contact.ts - Resource interface typescript
41
+ - contacts.service.ts - The service
42
+ - /contacts-create/contacts-create.component.html
43
+ - /contacts-create/contacts-create.component.ts
44
+ - /contacts-list/contacts-list.component.html
45
+ - /contacts-list/contacts-list.component.ts
46
+
47
+ ## License
48
+
49
+ NGCRUD is released under the [MIT License](https://mit-license.org).
50
+
51
+ ## Contact
52
+
53
+ If you have any questions or feedback, feel free to contact me mdorozcog@gmail.com
54
+
55
+ Happy coding!
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ end
6
+
7
+ desc "Run tests"
8
+ task default: :test
data/bin/ngcrud ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'erb'
4
+ require_relative '../lib/resource_crud'
5
+
6
+ if ARGV.count < 2
7
+ p "You need to provide at least 2 params: ResourceName field:type"
8
+ end
9
+
10
+ props = ARGV.each_with_index.map do |param, idx|
11
+ unless idx.zero?
12
+ field = param.split(":")
13
+ [field[0].to_sym, field[1]]
14
+ end
15
+ end.compact.to_h
16
+
17
+ crud = ResourceCrud.new(ARGV[0], **props)
18
+ crud.generator
data/lib/ng_crud.rb ADDED
@@ -0,0 +1,3 @@
1
+ module NgCrud
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,54 @@
1
+ require 'fileutils'
2
+
3
+ class ResourceCrud
4
+ def initialize(name, **props)
5
+ @name = name
6
+ @props = props
7
+ @generator_hash = {}
8
+ end
9
+
10
+ def generator
11
+ gem_path = Gem::Specification.find_by_name("ngcrud").gem_dir
12
+ dirname = File.dirname("src/app/features/#{@name.downcase}")
13
+ unless File.directory?(dirname)
14
+ FileUtils::mkdir_p("src/app/features/#{@name.downcase}/#{@name.downcase}-create")
15
+ FileUtils::mkdir_p("src/app/features/#{@name.downcase}/#{@name.downcase}-list")
16
+ end
17
+
18
+ p "Generating interface..."
19
+ interface = ERB.new(File.open("#{gem_path}/lib/templates/resource_interface.erb").read)
20
+ interface_file = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}.ts", "w")
21
+ interface_file.write(interface.result(get_binding))
22
+ interface_file.close
23
+ p "Generating service..."
24
+ service = ERB.new(File.open("#{gem_path}/lib/templates/resource_service.erb").read)
25
+ service_file = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}.service.ts", "w")
26
+ service_file.write(service.result(get_binding))
27
+ service_file.close
28
+
29
+ p "Generating components..."
30
+ create_html = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_create_html.erb").read)
31
+ file_html = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-create/#{@name.downcase}-create.component.html", "w")
32
+ file_html.write(create_html.result(get_binding))
33
+ file_html.close
34
+ create_ts = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_create_ts.erb").read)
35
+ file_ts = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-create/#{@name.downcase}-create.component.ts", "w")
36
+ file_ts.write(create_ts.result(get_binding))
37
+ file_ts.close
38
+
39
+ list_html = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_list_html.erb").read)
40
+ file_html = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-list/#{@name.downcase}-list.component.html", "w")
41
+ file_html.write(list_html.result(get_binding))
42
+ file_html.close
43
+ list_ts = ERB.new(File.open("#{gem_path}/lib/templates/components/resource_list_ts.erb").read)
44
+ file_ts = File.new("./src/app/features/#{@name.downcase}/#{@name.downcase}-list/#{@name.downcase}-list.component.ts", "w")
45
+ file_ts.write(list_ts.result(get_binding))
46
+ file_ts.close
47
+
48
+ end
49
+
50
+ private
51
+ def get_binding
52
+ binding
53
+ end
54
+ end
@@ -0,0 +1,17 @@
1
+ <form [formGroup]="<%= @name.downcase %>FormGroup" (ngSubmit)="onSubmit()" novalidate>
2
+ <% @props.each do |k, v| %>
3
+ <div class="mb-3">
4
+ <label><%= k.to_s.capitalize %></label>
5
+ <input type="text" formControlName="<%= k %>" class="form-control" required>
6
+ </div>
7
+ <% end %>
8
+ <div class="mb-3">
9
+ <button
10
+ type="submit"
11
+ class="btn btn-primary"
12
+ [disabled]="!<%= @name.downcase %>FormGroup.valid"
13
+ >
14
+ Create
15
+ </button>
16
+ </div>
17
+ </form>
@@ -0,0 +1,67 @@
1
+ import { Component, OnInit } from '@angular/core';
2
+ import { <%= @name %>Service } from '../../shared/services/<%= @name.downcase %>.service';
3
+ import { FormBuilder, FormGroup, Validators } from '@angular/forms';
4
+ import { ToastrService } from 'ngx-toastr';
5
+ import { Router } from '@angular/router';
6
+
7
+ @Component({
8
+ selector: 'app-<%= @name.downcase %>-create',
9
+ templateUrl: './<%= @name.downcase %>-create.component.html',
10
+ styleUrls: ['./<%= @name.downcase %>-create.component.scss']
11
+ })
12
+ export class <%= @name %>CreateComponent implements OnInit {
13
+ public <%= @name.downcase %>FormGroup: FormGroup;
14
+ constructor(
15
+ public crudApi: <%= @name %>Service,
16
+ public fb: FormBuilder,
17
+ public toastr: ToastrService,
18
+ public router: Router
19
+ ) {}
20
+
21
+ ngOnInit(): void {
22
+ this.crudApi.Get<%= @name %>sList();
23
+ this.<%= @name.downcase %>FormGroup = this.fb.group({
24
+ <% @props.each do |k, v| %>
25
+ <%= k %>: [
26
+ '',
27
+ [
28
+ Validators.required,
29
+ Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$'),
30
+ ],
31
+ ],
32
+ <% end %>
33
+ });
34
+ }
35
+
36
+ <%= @name.downcase %>Form(): any {
37
+ this.<%= @name.downcase %>FormGroup = this.fb.group({
38
+ <% @props.each do |k, v| %>
39
+ <%= k %>: [
40
+ '',
41
+ [
42
+ Validators.required,
43
+ Validators.pattern('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$'),
44
+ ],
45
+ ],
46
+ <% end %>
47
+ });
48
+ }
49
+
50
+ <% @props.each do |k, v| %>
51
+ get <%= k %>() {
52
+ return this.<%= @name.downcase %>FormGroup.get('<%= k %>');
53
+ }
54
+ <% end %>
55
+
56
+ ResetForm() {
57
+ this.<%= @name.downcase %>FormGroup.reset();
58
+ }
59
+
60
+ onSubmit(): void {
61
+ this.crudApi.add<%= @name %>(this.<%= @name.downcase %>FormGroup.value);
62
+ this.toastr.success(
63
+ this.<%= @name.downcase %>FormGroup.controls['email'].value + ' successfully added!'
64
+ );
65
+ setTimeout(()=>this.router.navigate(['<%= @name.downcase %>-list']), 2000);
66
+ }
67
+ }
@@ -0,0 +1,62 @@
1
+ <div
2
+ class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom"
3
+ >
4
+ <h2 class="h2"><%= @name %>s List</h2>
5
+ <a
6
+ routerLink="/<%= @name.downcase %>-create"
7
+ class="btn btn-success"
8
+ *ngIf="hideWhenNo<%= @name %>"
9
+ >
10
+ Add Student
11
+ </a>
12
+ </div>
13
+ <div class="pricing-header mx-auto">
14
+ <div class="no-data text-center" *ngIf="preLoader">
15
+ <img src="assets/preloader.gif" class="preloader-icon" alt="No student" />
16
+ </div>
17
+ <div class="no-data text-center" *ngIf="noData">
18
+ <img src="assets/no-<%= @name.downcase %>.svg" class="nodata-msg" alt="No student" />
19
+ <p class="nodata-msg">No <%= @name.downcase %> added yet!</p>
20
+ <a routerLink="/<%= @name.downcase %>-create" class="btn btn-success"> Add <%= @name.downcase %> </a>
21
+ </div>
22
+ <div class="table-responsive" *ngIf="hideWhenNo<%= @name %>">
23
+ <table
24
+ class="table table-bordered table-responsive-sm table-responsive-md table-responsive-lg"
25
+ >
26
+ <thead>
27
+ <tr>
28
+ <% @props.each do |k, v| %>
29
+ <th scope="col"><%= k.capitalize %></th>
30
+ <% end %>
31
+ <th class="text-center" scope="col">Edit</th>
32
+ </tr>
33
+ </thead>
34
+ <tbody>
35
+ <tr
36
+ *ngFor="
37
+ let <%= @name.downcase %> of <%= @name.downcase %>s
38
+ | paginate: { itemsPerPage: 8, currentPage: p };
39
+ let i = index
40
+ "
41
+ >
42
+ <% @props.each do |k, v| %>
43
+ <td>{{ <%= @name.downcase %>.<%= k %> }}</td>
44
+ <% end %>
45
+ <td class="text-center action-block">
46
+ <span
47
+ class="mr-2 btn btn-outline-primary btn-sm"
48
+ routerLink="/<%= @name.downcase %>-edit/{{ <%= @name.downcase %>.id }}"
49
+ >Edit</span
50
+ >
51
+ <span
52
+ class="btn btn-outline-danger btn-sm"
53
+ (click)="delete<%= @name %>(<%= @name.downcase %>)"
54
+ >Delete</span
55
+ >
56
+ </td>
57
+ </tr>
58
+ </tbody>
59
+ </table>
60
+ </div>
61
+ <pagination-controls (pageChange)="p = $event"></pagination-controls>
62
+ </div>
@@ -0,0 +1,58 @@
1
+ import { Component, OnInit } from '@angular/core';
2
+ import { <%= @name %>Service } from '../../shared/services/<%= @name.downcase %>.service';
3
+ import { <%= @name %> } from '../../shared/services/<%= @name.downcase %>';
4
+ import { ToastrService } from 'ngx-toastr';
5
+
6
+ @Component({
7
+ selector: 'app-<%= @name.downcase %>-list',
8
+ templateUrl: './<%= @name.downcase %>-list.component.html',
9
+ styleUrls: ['./<%= @name.downcase %>-list.component.scss']
10
+ })
11
+ export class <%= @name %>ListComponent implements OnInit {
12
+
13
+ p: number = 1;
14
+ <%= @name.downcase %>s: <%= @name %>[];
15
+ hideWhenNo<%= @name %>: boolean = false;
16
+ noData: boolean = false;
17
+ preLoader: boolean = true;
18
+
19
+ constructor(
20
+ public crudApi: <%= @name %>Service,
21
+ public toastr: ToastrService
22
+ ){ }
23
+
24
+ ngOnInit(): void {
25
+ this.dataState();
26
+ let s = this.crudApi.Get<%= @name %>sList();
27
+ s.snapshotChanges().subscribe(data => {
28
+ this.<%= @name.downcase %>s = [];
29
+ data.forEach(item => {
30
+ let a = item.payload.doc.data();
31
+ if (a != null){
32
+ a["id"] = item.payload.doc.id;
33
+ this.<%= @name.downcase %>s.push(a as <%= @name %>);
34
+ }
35
+
36
+ });
37
+ })
38
+ }
39
+ dataState() {
40
+ this.crudApi.Get<%= @name %>sList().valueChanges().subscribe(data => {
41
+ this.preLoader = false;
42
+ if(data.length <= 0){
43
+ this.hideWhenNo<%= @name %> = false;
44
+ this.noData = true;
45
+ } else {
46
+ this.hideWhenNo<%= @name %> = true;
47
+ this.noData = false;
48
+ }
49
+ })
50
+ }
51
+ delete<%= @name %>(<%= @name.downcase %>: <%= @name %>) {
52
+ if (window.confirm('Are sure you want to delete this <%= @name.downcase %> ?')) {
53
+ this.crudApi.Delete<%= @name %>(<%= @name.downcase %>.id)
54
+ this.toastr.success(<%= @name.downcase %>.email + ' successfully deleted!');
55
+ }
56
+ }
57
+
58
+ }
@@ -0,0 +1,5 @@
1
+ export interface <%= @name %> {
2
+ <% @props.each do |k, v| %>
3
+ <%= k %>: <%= v %>;
4
+ <% end %>
5
+ }
@@ -0,0 +1,53 @@
1
+ import { Injectable } from '@angular/core';
2
+ import { <%= @name %> } from './<%= @name.downcase %>';
3
+ import {
4
+ AngularFirestore,
5
+ AngularFirestoreCollection,
6
+ AngularFirestoreDocument
7
+ } from '@angular/fire/compat/firestore';
8
+
9
+ @Injectable({
10
+ providedIn: 'root',
11
+ })
12
+ export class <%= @name %>Service {
13
+ <%= @name.downcase %>Ref: AngularFirestoreDocument;
14
+ <%= @name.downcase %>sRef: AngularFirestoreCollection;
15
+
16
+ constructor(private db: AngularFirestore) {
17
+ this.<%= @name.downcase %>sRef = db.collection('<%= @name.downcase %>s');
18
+ }
19
+ // Create <%= @name %>
20
+ add<%= @name %>(<%= @name.downcase %>: <%= @name %>) {
21
+ let <%= @name.downcase %>Obj =
22
+ {
23
+ <% @props.each do |k, v| %>
24
+ <%= k %>: <%= @name.downcase %>.<%= k %>,
25
+ <% end %>
26
+ };
27
+ // CHANGE THIS PART TO NAME THE DOCUMENT
28
+ this.<%= @name.downcase %>sRef.doc(<%= @name.downcase %>Obj.CHANGE_ME).set(<%= @name.downcase %>Obj);
29
+ }
30
+ // Fetch Single <%= @name %> Object
31
+ get<%= @name %>(id: string) {
32
+ this.<%= @name.downcase %>Ref = this.db.doc('<%= @name.downcase %>s/' + id);
33
+ return this.permissionRef;
34
+ }
35
+ // Fetch <%= @name %>s List
36
+ get<%= @name %>sList() {
37
+ this.<%= @name.downcase %>sRef = this.db.collection('<%= @name.downcase %>s');
38
+ return this.<%= @name.downcase %>sRef;
39
+ }
40
+ // Update <%= @name %> Object
41
+ update<%= @name %>(<%= @name.downcase %>: <%= @name %>) {
42
+ this.<%= @name.downcase %>Ref.update({
43
+ <% @props.each do |k| %>
44
+ <%= k %>: <%= @name.downcase %>.<%= k %>,
45
+ <% end %>
46
+ });
47
+ }
48
+ // Delete <%= @name %> Object
49
+ Delete<%= @name %>(id: string) {
50
+ this.<%= @name.downcase %>Ref = this.db.doc('<%= @name.downcase %>s/' + id);
51
+ this.<%= @name.downcase %>Ref.delete();
52
+ }
53
+ }
@@ -0,0 +1,10 @@
1
+ require "minitest/autorun"
2
+ require "resource_crud"
3
+
4
+ class ResourceCrudTest < Minitest::Test
5
+ def test_types
6
+ res = ResourceCrud.new("Resource", name: "string", age: "number")
7
+ assert_equal "String",
8
+ res.class
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ngcrud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Diego Orozco
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.2
27
+ description: A rails-like Angular CRUD Generator
28
+ email: mdorozcog@gmail.com
29
+ executables:
30
+ - ngcrud
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - bin/ngcrud
38
+ - lib/ng_crud.rb
39
+ - lib/resource_crud.rb
40
+ - lib/templates/components/resource_create_html.erb
41
+ - lib/templates/components/resource_create_ts.erb
42
+ - lib/templates/components/resource_list_html.erb
43
+ - lib/templates/components/resource_list_ts.erb
44
+ - lib/templates/resource_interface.erb
45
+ - lib/templates/resource_service.erb
46
+ - test/test_resource_crud.rb
47
+ homepage: https://github.com/mdorozcog/ngcrud
48
+ licenses:
49
+ - MIT
50
+ metadata: {}
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 3.1.2
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.4.20
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Angular CRUD Generator
70
+ test_files: []