rails-angularjs_crud_generator 0.1.0 → 0.1.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
  SHA1:
3
- metadata.gz: 553a4111b1328847bcc44dd43ecf7a3972e56764
4
- data.tar.gz: 742302c6cb5badf5c788f319eef9a61f0b865534
3
+ metadata.gz: 3627f7efc09726749bfae27721f99e71a1bb50ea
4
+ data.tar.gz: 46e206c052c611e3257f5bbccb484bba3763bb86
5
5
  SHA512:
6
- metadata.gz: 4085954b07bcfa5d1867cb67f3e6da852da7b82c3563336114a9df3c2547ab135a62c0413c55ef1e6869b22b946963c8bc729a9f68b29e0e6dddb8b4f0c39c34
7
- data.tar.gz: becc2f7f9f619ff53a69711c16eae839d2f20eb946e91fd2b503c709bb9f59f1a35e2078a754c394837638e77eb8032cb4d2b6149d7a81c9a4e6a1cbd679b291
6
+ metadata.gz: b4aca20d759f567ff90db3251f21d1a42d3fc1bf57bb1055d77b2ed4a83d8022db2598de3a0c5d8292a5dac156a2cea1699bd43988a04f1861cb01325287d90c
7
+ data.tar.gz: 9829964f704c5d1cdad6208168342df58ea7cf97057b2336354a6105bd3d518c671eecaaea1dc9796099c3970114783bdb68707762620d60684b4aa75880b6c7
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ ## [WIP] Angularjs Crud Generator for Rails
2
+
3
+ Generates a fully working angularjs crud app for a model.
4
+
5
+ Note: The model should already exist.
6
+
7
+ **Installation**
8
+
9
+ Add below line to your `Gemfile` and run `bundle install`.
10
+
11
+ ```
12
+ gem 'rails-angularjs_crud_generator'
13
+ ```
14
+
15
+
16
+
17
+ **Usage**
18
+
19
+ 1. Initialize the generator.
20
+
21
+ ```
22
+ rails generate angularjs_crud:install
23
+ ```
24
+
25
+ 2. Generate your controller
26
+
27
+ ```
28
+ rails generate angularjs_crud <your-model-name>
29
+ ```
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates an angular app for doing basic crud operations.
3
+ Pass the model name, either CamelCased or under_scored. The angular app
4
+ name is retrieved as a pluralized version of the model name.
5
+
6
+ This generates an angular app in app/assets/javascripts/src/<app-name>/main.js
7
+
8
+ Example:
9
+ `rails generate angularjs_crud Article`
@@ -0,0 +1,3 @@
1
+ {
2
+ "directory": "public/assets/bower_components"
3
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "example-app",
3
+ "version": "0.0.0",
4
+ "authors": [],
5
+ "license": "Apache License, Version 2.0",
6
+ "ignore": [
7
+ "**/.*",
8
+ "node_modules",
9
+ "bower_components",
10
+ "test",
11
+ "tests"
12
+ ],
13
+ "dependencies": {
14
+ },
15
+ "devDependencies": {
16
+ }
17
+ }
@@ -0,0 +1,38 @@
1
+ module.exports = function(config) {
2
+ 'use strict';
3
+
4
+ config.set({
5
+ basePath: './public/assets/js/apps',
6
+
7
+ frameworks: ["mocha", "chai"],
8
+
9
+ preprocessors: {
10
+ '**/*.coffee': ['coffee'],
11
+ '**/*.html': ['ng-html2js'],
12
+ },
13
+
14
+ ngHtml2JsPreprocessor: {
15
+ // Use below line at the very top of your tests
16
+ // beforeEach(module('external-templates'))
17
+ moduleName: 'external-templates',
18
+ stripPrefix: 'templates/',
19
+ },
20
+
21
+ files: [
22
+ // bower
23
+ '../../bower_components/jquery/dist/jquery.js',
24
+ '../../bower_components/bootstrap/dist/js/bootstrap.js',
25
+ '../../bower_components/angular/angular.js',
26
+ '../../bower_components/angular-mocks/angular-mocks.js',
27
+ // endbower
28
+ //
29
+ // src
30
+ '*/main.js',
31
+ '*/templates/*.html',
32
+ // tests
33
+ '*/test/**/*.js',
34
+ ],
35
+
36
+ browsers: [ "Chrome" ],
37
+ });
38
+ };
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "example-app",
3
+ "version": "0.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "karma run"
8
+ },
9
+ "license": "Apache License, 2.0",
10
+ "devDependencies": {
11
+ "chai": "^3.0.0",
12
+ "karma": "^0.12.37",
13
+ "karma-chai": "^0.1.0",
14
+ "karma-chrome-launcher": "^0.2.0",
15
+ "karma-coffee-preprocessor": "^0.2.1",
16
+ "karma-mocha": "^0.2.0",
17
+ "karma-ng-html2js-preprocessor": "^0.1.2",
18
+ "mocha": "^2.2.5"
19
+ }
20
+ }
@@ -0,0 +1,36 @@
1
+ <div id="<%= file_name.pluralize %>_app" ng-app="<%= file_name.pluralize %>App" ng-controller="MainCtrl">
2
+ <div class="panel panel-default">
3
+ <div class="panel-body">
4
+ <div class="clearfix">
5
+ <h2 class="lead pull-left"><%= class_name.pluralize %></h2>
6
+ <button class="btn btn-primary btn-sm pull-right" ng-click="new()"><span class="glyphicon glyphicon-plus"></span> New</button>
7
+ </div>
8
+
9
+ <br><br>
10
+ <p ng-show="list.length == 0">No <%= file_name.pluralize %> yet.</p>
11
+ <table class="table table-condensed table-hover table-bordered table-striped" ng-show="list.length > 0">
12
+ <tr>
13
+ <th>Name</th>
14
+ <th>Date created</th>
15
+ <th>Actions</th>
16
+ </tr>
17
+ <tr ng-repeat="<%= file_name %> in list | orderBy: '-created_at'">
18
+ <td>{{<%= file_name %>.name}}</td>
19
+ <td>{{<%= file_name %>.created_at | date}}</td>
20
+ <td>
21
+ <a href="#" ng-click="show(<%= file_name %>)" class="btn btn-default btn-trans btn-link btn-xs"><span class="glyphicon glyphicon-eye-open"></span> Show</a>
22
+ <a href="#" ng-click="edit(<%= file_name %>)" class="btn btn-default btn-trans btn-link btn-xs"><span class="glyphicon glyphicon-pencil"></span> Edit</a>
23
+ <a href="#" ng-click="delete(<%= file_name %>)" class="btn btn-danger btn-trans btn-link btn-xs"><span class="glyphicon glyphicon-trash"></span> Delete</a>
24
+ </td>
25
+ </tr>
26
+ </table>
27
+
28
+ <!-- templates -->
29
+ <%%= angular_inline_template('<%= file_name.pluralize %>/templates/tmpl_form.html') %>
30
+ <%%= angular_inline_template('<%= file_name.pluralize %>/templates/tmpl_new.html') %>
31
+ <%%= angular_inline_template('<%= file_name.pluralize %>/templates/tmpl_edit.html') %>
32
+ <%%= angular_inline_template('<%= file_name.pluralize %>/templates/tmpl_show.html') %>
33
+ <%%= angular_inline_template('<%= file_name.pluralize %>/templates/tmpl_delete.html') %>
34
+ </div>
35
+ </div>
36
+ </div>
@@ -0,0 +1,175 @@
1
+ /* modules */
2
+ angular.module('<%= file_name.pluralize %>.controllers', []);
3
+ angular.module('<%= file_name.pluralize %>.services', []);
4
+ angular.module('<%= file_name.pluralize %>.directives', []);
5
+
6
+ /* app */
7
+ angular.module('<%= file_name.pluralize %>App', [
8
+ '<%= file_name.pluralize %>.controllers',
9
+ '<%= file_name.pluralize %>.services',
10
+ '<%= file_name.pluralize %>.directives',
11
+ 'ngResource',
12
+ 'ui.bootstrap',
13
+ ]);
14
+
15
+ /* controllers */
16
+ angular.module('<%= file_name.pluralize %>.controllers')
17
+ .controller('MainCtrl', function($scope, $log, <%= class_name %>, $modal) {
18
+ $log.debug('<%= file_name.pluralize %>App ready.');
19
+
20
+ var ModalInstanceCtrl, deleteModel, newModel, saveModel;
21
+
22
+ $scope.list = [];
23
+ $scope.addToList = function(newItem) {
24
+ $scope.list.push(newItem);
25
+ };
26
+
27
+ $scope.fetchList = function() {
28
+ <%= class_name %>.getAll().then(function(list) {
29
+ $log.debug('fetched list');
30
+ $log.debug(list);
31
+ $scope.list = list;
32
+ });
33
+ };
34
+
35
+ $scope.fetchList();
36
+
37
+ newModel = function() {
38
+ $log.debug('new model');
39
+
40
+ return new <%= class_name %>();
41
+ };
42
+
43
+ saveModel = function(unsavedModelObject) {
44
+ $log.debug('saving model');
45
+
46
+ if (unsavedModelObject.id > 0) {
47
+ unsavedModelObject.$update(function(savedObject) {
48
+ $log.debug('saved the edits');
49
+ $scope.fetchList();
50
+ });
51
+ } else {
52
+ unsavedModelObject.$save(function(savedObject) {
53
+ $log.debug('saved new model');
54
+ $scope.fetchList();
55
+ });
56
+ }
57
+ };
58
+
59
+ deleteModel = function(modelObjectToDelete) {
60
+ $log.debug('deleting model');
61
+
62
+ modelObjectToDelete.$delete(function() {
63
+ $log.debug('deleted model');
64
+ $scope.fetchList();
65
+ });
66
+ };
67
+
68
+ ModalInstanceCtrl = function($scope, $modalInstance, modelObject) {
69
+ $scope.<%= file_name %> = modelObject;
70
+
71
+ $scope.save = function(modelObject) {
72
+ saveModel(modelObject);
73
+ $modalInstance.dismiss('saved model');
74
+ };
75
+
76
+ $scope.delete = function() {
77
+ deleteModel(modelObject);
78
+ $modalInstance.dismiss('deleted model');
79
+ };
80
+
81
+ $scope.dismiss = function() {
82
+ $modalInstance.dismiss('dismissed');
83
+ };
84
+ };
85
+
86
+ $scope.new = function() {
87
+ $modal.open({
88
+ templateUrl: '<%= file_name.pluralize %>/templates/tmpl_new.html',
89
+ controller: ModalInstanceCtrl,
90
+ resolve: {
91
+ modelObject: function() {
92
+ return newModel();
93
+ }
94
+ }
95
+ });
96
+ };
97
+
98
+ $scope.edit = function(modelObject) {
99
+ $modal.open({
100
+ templateUrl: '<%= file_name.pluralize %>/templates/tmpl_edit.html',
101
+ controller: ModalInstanceCtrl,
102
+ resolve: {
103
+ modelObject: function() {
104
+ return angular.copy(modelObject);
105
+ }
106
+ }
107
+ });
108
+ };
109
+
110
+ $scope.show = function(modelObject) {
111
+ $modal.open({
112
+ templateUrl: '<%= file_name.pluralize %>/templates/tmpl_show.html',
113
+ controller: ModalInstanceCtrl,
114
+ resolve: {
115
+ modelObject: function() {
116
+ return angular.copy(modelObject);
117
+ }
118
+ }
119
+ });
120
+ };
121
+
122
+ $scope.delete = function(modelObject) {
123
+ $modal.open({
124
+ templateUrl: '<%= file_name.pluralize %>/templates/tmpl_delete.html',
125
+ controller: ModalInstanceCtrl,
126
+ resolve: {
127
+ modelObject: function() {
128
+ return modelObject;
129
+ }
130
+ }
131
+ });
132
+ };
133
+ });
134
+ /* end controllers */
135
+
136
+
137
+ /* services */
138
+ angular.module('<%= file_name.pluralize %>.services')
139
+ .factory('<%= class_name %>', function($resource) {
140
+ var <%= class_name %>, customMethods;
141
+
142
+ customMethods = {
143
+ update: {
144
+ method: 'PATCH'
145
+ }
146
+ };
147
+
148
+ <%= class_name %> = $resource('/api/<%= file_name.pluralize %>/:id', { id: "@id" }, customMethods);
149
+
150
+ <%= class_name %>.getAll = function(repertoire_piece_id) {
151
+ return <%= class_name %>.query({
152
+ repertoire_piece_id: repertoire_piece_id
153
+ }).$promise;
154
+ };
155
+
156
+ return <%= class_name %>;
157
+ });
158
+ /* end services */
159
+
160
+
161
+ /* directives */
162
+ angular.module('<%= file_name.pluralize %>.directives')
163
+ .directive('<%= file_name %>Form', function() {
164
+ return {
165
+ restrict: 'E',
166
+ scope: {
167
+ <%= file_name %>: '='
168
+ },
169
+ templateUrl: '<%= file_name.pluralize %>/templates/tmpl_form.html',
170
+ link: function(scope) {
171
+ return scope.test_msg = '<%= file_name %>FormTest';
172
+ }
173
+ };
174
+ });
175
+ /* end directives */
@@ -0,0 +1,12 @@
1
+ <div class="modal-header">
2
+ <strong>Are you sure you want to delete?</strong>
3
+ </div>
4
+
5
+ <div class="modal-body">
6
+ If you delete an item, it will be permanently lost.
7
+ </div>
8
+
9
+ <div class="modal-footer">
10
+ <button class="btn btn-default" ng-click="dismiss()">Cancel</button>
11
+ <button class="btn btn-danger" ng-click="delete()">Delete</button>
12
+ </div>
@@ -0,0 +1,12 @@
1
+ <div class="modal-header">
2
+ <h3 class="modal-title"><strong>Edit <%= file_name %> details</strong></h3>
3
+ </div>
4
+
5
+ <div class="modal-body">
6
+ <<%= file_name %>-form <%= file_name %>="<%= file_name %>"></<%= file_name %>-form>
7
+ </div>
8
+
9
+ <div class="modal-footer">
10
+ <button class="btn btn-primary" ng-click="save(<%= file_name %>)">Save</button>
11
+ <button class="btn btn-default" ng-click="dismiss()">Cancel</button>
12
+ </div>
@@ -0,0 +1,6 @@
1
+ <form name="<%= file_name %>_form" novalidate>
2
+ <div class="form-group">
3
+ <label>Name</label>
4
+ <input class="form-control" ng-model="<%= file_name %>.name" ng-required="true">
5
+ </div>
6
+ </form>
@@ -0,0 +1,12 @@
1
+ <div class="modal-header">
2
+ <h3 class="modal-title"><strong>New <%= file_name %></strong></h3>
3
+ </div>
4
+
5
+ <div class="modal-body">
6
+ <<%= file_name %>-form <%= file_name %>="<%= file_name %>"></<%= file_name %>-form>
7
+ </div>
8
+
9
+ <div class="modal-footer">
10
+ <button type="submit" class="btn btn-primary" ng-click="save(<%= file_name %>)">Save</button>
11
+ <button class="btn btn-default" ng-click="dismiss()">Cancel</button>
12
+ </div>
@@ -0,0 +1,20 @@
1
+ <div class="modal-header">
2
+ <h3 class="modal-title"><strong><%= class_name %> details</strong></h3>
3
+ </div>
4
+
5
+ <div class="modal-body">
6
+ <table class="table table-condensed table-hover table-striped">
7
+ <tr>
8
+ <td><strong>Name</strong></td>
9
+ <td>{{<%= file_name %>.name}}</td>
10
+ </tr>
11
+ <tr>
12
+ <td><strong>Date created</strong></td>
13
+ <td>{{<%= file_name %>.created_at | date}}</td>
14
+ </tr>
15
+ </table>
16
+ </div>
17
+
18
+ <div class="modal-footer">
19
+ <button class="btn btn-default" ng-click="dismiss()">OK</button>
20
+ </div>
@@ -0,0 +1,31 @@
1
+ describe('<%= file_name.pluralize %>.controllers MainCtrl', function() {
2
+ var $logMock, MainCtrl, <%= class_name %>Mock, scope;
3
+
4
+ scope = null;
5
+ MainCtrl = null;
6
+ $logMock = {
7
+ debug: function() {}
8
+ };
9
+ <%= class_name %>Mock = {
10
+ getAll: function() {
11
+ return {
12
+ then: function() {}
13
+ };
14
+ }
15
+ };
16
+
17
+ beforeEach(module('<%= file_name.pluralize %>.controllers'));
18
+ beforeEach(inject(function($controller, $rootScope) {
19
+ scope = $rootScope.$new();
20
+ MainCtrl = $controller('MainCtrl', {
21
+ $scope: scope,
22
+ $log: $logMock,
23
+ <%= class_name %>: <%= class_name %>Mock,
24
+ $modal: {}
25
+ });
26
+ }));
27
+
28
+ it('instantiates without errors', function() {
29
+ expect(MainCtrl).to.not.eql(null);
30
+ });
31
+ });
@@ -0,0 +1,24 @@
1
+ describe('<%= file_name.pluralize %>.directives <%= file_name %>Form', function() {
2
+ var $compile, element, scope;
3
+
4
+ $compile = null;
5
+ scope = null;
6
+ element = null;
7
+
8
+ beforeEach(module('external-templates'));
9
+ beforeEach(module('<%= file_name.pluralize %>.directives'));
10
+
11
+ beforeEach(inject(function(_$compile_, $rootScope) {
12
+ $compile = _$compile_;
13
+ scope = $rootScope.$new();
14
+
15
+ element = angular.element('<<%= file_name %>-form></<%= file_name %>-form>');
16
+ }));
17
+
18
+ it('instantiates without errors', function() {
19
+ $compile(element)(scope);
20
+ scope.$digest();
21
+
22
+ expect(element.isolateScope().test_msg).to.eql('<%= file_name %>FormTest');
23
+ });
24
+ });
@@ -0,0 +1,23 @@
1
+ describe('<%= file_name.pluralize %>.services <%= class_name %>', function() {
2
+ var <%= class_name %>Service, resourceMock;
3
+
4
+ <%= class_name %>Service = null;
5
+ resourceMock = function() {
6
+ return function() {};
7
+ };
8
+
9
+ beforeEach(module('<%= file_name.pluralize %>.services'));
10
+ beforeEach(function() {
11
+ module(function($provide) {
12
+ $provide.value('$resource', resourceMock);
13
+ });
14
+
15
+ inject(function($injector) {
16
+ <%= class_name %>Service = $injector.get('<%= class_name %>');
17
+ });
18
+ });
19
+
20
+ it('instantiates without errors', function() {
21
+ expect(<%= class_name %>Service).to.not.eql(null);
22
+ });
23
+ });
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.required_ruby_version = '>= 1.9.3'
4
+ s.name = 'rails-angularjs_crud_generator'
5
+ s.version = '0.1.1'
6
+ s.summary = 'Generates fully working angularjs apps'
7
+ s.description = 'Generates a fully working angularjs app for basic crud operations of a model.'
8
+ s.author = 'Chanaka Sandaruwan'
9
+ s.email = 'chanakasan@gmail.com'
10
+ s.files = Dir['**/*']
11
+ s.require_paths = ['lib']
12
+ s.homepage = 'https://github.com/chanakasan/rails-angularjs_crud_generator'
13
+ s.license = 'Apache License, Version 2.0'
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-angularjs_crud_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chanaka Sandaruwan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Generates a fully working angularjs app for basic crud operations of
14
14
  a model.
@@ -17,11 +17,29 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - README.md
21
+ - lib/generators/angularjs_crud/USAGE
20
22
  - lib/generators/angularjs_crud/angularjs_crud_generator.rb
21
23
  - lib/generators/angularjs_crud/helpers/bower_helper.rb
22
24
  - lib/generators/angularjs_crud/helpers/npm_helper.rb
23
25
  - lib/generators/angularjs_crud/install/install_generator.rb
26
+ - lib/generators/angularjs_crud/install/templates/_bowerrc
24
27
  - lib/generators/angularjs_crud/install/templates/angular_js_helper.rb
28
+ - lib/generators/angularjs_crud/install/templates/bower.json
29
+ - lib/generators/angularjs_crud/install/templates/karma.conf.js
30
+ - lib/generators/angularjs_crud/install/templates/package.json
31
+ - lib/generators/angularjs_crud/templates/_app_partial.html.erb
32
+ - lib/generators/angularjs_crud/templates/angular_app/main.js
33
+ - lib/generators/angularjs_crud/templates/angular_app/templates/tmpl_delete.html
34
+ - lib/generators/angularjs_crud/templates/angular_app/templates/tmpl_edit.html
35
+ - lib/generators/angularjs_crud/templates/angular_app/templates/tmpl_form.html
36
+ - lib/generators/angularjs_crud/templates/angular_app/templates/tmpl_new.html
37
+ - lib/generators/angularjs_crud/templates/angular_app/templates/tmpl_show.html
38
+ - lib/generators/angularjs_crud/templates/angular_app/test/controllers/main_ctrl_spec.js
39
+ - lib/generators/angularjs_crud/templates/angular_app/test/directives/form_spec.js
40
+ - lib/generators/angularjs_crud/templates/angular_app/test/services/model_spec.js
41
+ - rails-angularjs_crud_generator-0.1.0.gem
42
+ - rails-angularjs_crud_generator.gemspec
25
43
  homepage: https://github.com/chanakasan/rails-angularjs_crud_generator
26
44
  licenses:
27
45
  - Apache License, Version 2.0