ng_on_rails 0.0.3.4 → 0.0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/generators/ng_on_rails/templates/app_controller_template.js.coffee +8 -5
- data/lib/generators/ng_on_rails/templates/controller_template.js.erb +128 -125
- data/lib/generators/ng_on_rails/views_generator.rb +2 -2
- data/lib/ng_on_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4dbd24da05c3703028c56e9e886bbad00d9bbfb
|
4
|
+
data.tar.gz: dae75d2a092dfdb1476aa085b706ebaeb8e93adf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e45f74e69948b5a4898ce60f597ba32210e24e9d18d2c10d2acb45830b9c2193fe457c8175de7b41657333693cc1c9a53f0ef069a4693d108753066fdfa84de6
|
7
|
+
data.tar.gz: 52de3d3c9eee0a6e52be64f4b12e3fe52d89fc81bcdb80b51448ef4c65927edbd26b258ac7ee7dc032eb42e8e30df3bf83b8ecaaf1144cd810a4e2885654cfe8
|
data/README.md
CHANGED
@@ -202,8 +202,8 @@ $ bundle exec rails g ng_on_rails:views Page --properties id:number{skip_form+li
|
|
202
202
|
```
|
203
203
|
or even better, in two lines with the scaffolding short hand:
|
204
204
|
```
|
205
|
-
$ bundle exec rails g ng_on_rails:
|
206
|
-
$ bundle exec rails g ng_on_rails:
|
205
|
+
$ bundle exec rails g ng_on_rails:scaffold Doc --properties id:number{skip_form+link} name{required} description:textarea{skip_index} --relationships pages --rails-views
|
206
|
+
$ bundle exec rails g ng_on_rails:scaffold Page --properties id:number{skip_form+link} order_index:number subject{required} body:textarea{skip_index} --belongs_to Doc --rails-views
|
207
207
|
```
|
208
208
|
|
209
209
|
-----------------------------------------------------------
|
@@ -1,131 +1,134 @@
|
|
1
|
-
NgOnRailsApp.controller '<%="#{class_name.pluralize}"%>Controller',
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
working_<%="#{resource_name}"
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
working_<%="#{resource_name}"
|
1
|
+
NgOnRailsApp.controller '<%="#{class_name.pluralize}"%>Controller', [
|
2
|
+
'$scope','<%="#{class_name}"%>','Rails',
|
3
|
+
($scope,<%="#{class_name}"%>,Rails) ->
|
4
|
+
#
|
5
|
+
# CONTROLLER SETUP
|
6
|
+
#
|
7
|
+
ctrl = this
|
8
|
+
ctrl.rails = Rails
|
9
|
+
ctrl.data = {}
|
10
|
+
|
11
|
+
|
12
|
+
#
|
13
|
+
# INITIALIZERS
|
14
|
+
#
|
15
|
+
ctrl.set<%="#{class_name}"%> = (<%="#{resource_name}"%>)->
|
16
|
+
ctrl.data.<%="#{resource_name}"%> = <%="#{resource_name}"%>
|
17
|
+
ctrl.set<%="#{class_name.pluralize}"%> = (<%="#{plural_name}"%>)->
|
18
|
+
ctrl.data.<%="#{plural_name}"%> = <%="#{plural_name}"%>
|
19
|
+
|
20
|
+
|
21
|
+
#
|
22
|
+
# REST METHODS
|
23
|
+
#
|
24
|
+
ctrl.rest =
|
25
|
+
index: ->
|
26
|
+
params = {}
|
27
|
+
<%="#{class_name}"%>.query(params).$promise.then (<%="#{plural_name}"%>) ->
|
28
|
+
ctrl.data.<%="#{plural_name}"%> = <%="#{plural_name}"%>
|
29
|
+
|
30
|
+
show: (<%="#{resource_name}"%>_id)->
|
31
|
+
<%="#{class_name}"%>.get({id: <%="#{resource_name}"%>_id}).$promise.then (<%="#{resource_name}"%>) ->
|
32
|
+
ctrl.data.<%="#{resource_name}"%> = <%="#{resource_name}"%>
|
33
|
+
|
34
|
+
new: (<%=belongs_to_parameters%>)->
|
35
|
+
ctrl.clear()
|
36
|
+
ctrl.data.active<%="#{class_name}"%> = {}
|
37
|
+
ctrl.data.creating_new_<%="#{resource_name}"%> = true
|
38
|
+
<%
|
39
|
+
belongs_to_parameter_array.each do |relationship|
|
40
|
+
%>ctrl.data.active<%="#{class_name}"%>.<%= relationship%> = <%= relationship %>
|
41
|
+
<%
|
42
|
+
end
|
43
|
+
%>
|
44
|
+
|
45
|
+
create: ->
|
46
|
+
if !(ctrl.locked || ctrl.<%="#{resource_name}"%>_form.$error.required)
|
47
|
+
ctrl.locked = true
|
48
|
+
working_<%="#{resource_name}"%> = angular.copy(ctrl.data.active<%="#{class_name}"%>)
|
49
|
+
<%="#{class_name}"%>.save(
|
50
|
+
working_<%="#{resource_name}"%>,
|
51
|
+
(<%="#{resource_name}"%>)->
|
52
|
+
ctrl.data.<%="#{plural_name}"%> ||= []
|
53
|
+
ctrl.data.<%="#{plural_name}"%>.push(<%="#{resource_name}"%>)
|
54
|
+
ctrl.clear()
|
55
|
+
ctrl.locked = false
|
56
|
+
,
|
57
|
+
(error)->
|
58
|
+
console.log("create_error:",error)
|
59
|
+
ctrl.clear()
|
60
|
+
ctrl.locked = false
|
61
|
+
)
|
62
|
+
|
63
|
+
edit: (<%="#{resource_name}"%><%=belongs_to_comma%><%=belongs_to_parameters%>) ->
|
64
|
+
ctrl.clear()
|
65
|
+
ctrl.data.active<%="#{class_name}"%> = <%="#{resource_name}"%>
|
66
|
+
ctrl.data.editing_<%="#{resource_name}"%> = true
|
67
|
+
<%="#{resource_name}"%>.is_displayed = false
|
68
|
+
<%
|
69
|
+
belongs_to_array.each do |relationship|
|
70
|
+
%>ctrl.data.active<%="#{class_name}"%>.<%= relationship%> = <%= relationship %>
|
71
|
+
<%
|
72
|
+
end
|
73
|
+
%>
|
74
|
+
|
75
|
+
update: (<%="#{resource_name}"%>)->
|
76
|
+
if !(ctrl.locked || ctrl.<%="#{resource_name}"%>_form.$error.required)
|
77
|
+
ctrl.locked = true
|
78
|
+
<%="#{resource_name}"%> = ctrl.data.active<%="#{class_name}"%> unless !!<%="#{resource_name}"%>
|
79
|
+
working_<%="#{resource_name}"%> = angular.extend(angular.copy(<%="#{resource_name}"%>),ctrl.data.active<%="#{class_name}"%>)
|
80
|
+
<%="#{class_name}"%>.update(
|
81
|
+
working_<%="#{resource_name}"%>,
|
82
|
+
(<%="#{resource_name}"%>)->
|
83
|
+
# success handler
|
84
|
+
ctrl.locked = false
|
85
|
+
,
|
86
|
+
(error)->
|
87
|
+
console.log("update_error:",error)
|
88
|
+
ctrl.locked = false
|
89
|
+
)
|
90
|
+
ctrl.clear()
|
91
|
+
|
92
|
+
delete: (index,<%="#{resource_name}"%>,<%="#{plural_name}"%>)->
|
93
|
+
<%="#{class_name}"%>.delete(
|
94
|
+
<%="#{resource_name}"%>,
|
80
95
|
(<%="#{resource_name}"%>)->
|
81
|
-
#
|
82
|
-
|
96
|
+
<%="#{plural_name}"%> ||= ctrl.data.<%="#{plural_name}"%>
|
97
|
+
if !!<%="#{plural_name}"%>
|
98
|
+
<%="#{plural_name}"%>.splice(index,1)
|
99
|
+
else
|
100
|
+
window.location.href = "<%= path_to_index_page %>"
|
83
101
|
,
|
84
102
|
(error)->
|
85
|
-
console.log("
|
86
|
-
ctrl.locked = false
|
103
|
+
console.log("delete_error:",error)
|
87
104
|
)
|
88
105
|
ctrl.clear()
|
89
106
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
ctrl.toggleDisplay = (<%="#{resource_name}"%>)->
|
119
|
-
<%="#{resource_name}"%>.is_displayed = !<%="#{resource_name}"%>.is_displayed
|
120
|
-
|
121
|
-
#
|
122
|
-
# PRIVATE METHODS
|
123
|
-
#
|
124
|
-
# => add methods here, not attached to the ctrl object to be used internally
|
125
|
-
#
|
126
|
-
|
127
|
-
|
128
|
-
#
|
129
|
-
# END
|
130
|
-
#
|
131
|
-
return
|
107
|
+
|
108
|
+
#
|
109
|
+
# SCOPE METHODS
|
110
|
+
#
|
111
|
+
ctrl.clear = (doc)->
|
112
|
+
ctrl.data.active<%="#{class_name}"%> = null
|
113
|
+
ctrl.data.creating_new_<%="#{resource_name}"%> = false
|
114
|
+
ctrl.data.editing_<%="#{resource_name}"%> = false
|
115
|
+
|
116
|
+
ctrl.is_editing = (<%="#{resource_name}"%>)->
|
117
|
+
(ctrl.data.editing_<%="#{resource_name}"%> && !!<%="#{resource_name}"%> && <%="#{resource_name}"%>.id == ctrl.data.active<%="#{class_name}"%>.id) ||
|
118
|
+
(ctrl.data.creating_new_<%="#{resource_name}"%> && !<%="#{resource_name}"%>)
|
119
|
+
|
120
|
+
ctrl.toggleDisplay = (<%="#{resource_name}"%>)->
|
121
|
+
<%="#{resource_name}"%>.is_displayed = !<%="#{resource_name}"%>.is_displayed
|
122
|
+
|
123
|
+
#
|
124
|
+
# PRIVATE METHODS
|
125
|
+
#
|
126
|
+
# => add methods here, not attached to the ctrl object to be used internally
|
127
|
+
#
|
128
|
+
|
129
|
+
|
130
|
+
#
|
131
|
+
# END
|
132
|
+
#
|
133
|
+
return
|
134
|
+
]
|
@@ -152,8 +152,8 @@ module NgOnRails
|
|
152
152
|
def jbuilder_attributes
|
153
153
|
(
|
154
154
|
options[:properties].map{ |prop| "#{prop.split("{")[0].split(":")[0]}" } |
|
155
|
-
options[:belongs_to].map{ |model| "#{model}_id" } |
|
156
|
-
options[:relationships]
|
155
|
+
options[:belongs_to].map{ |model| "#{model.underscore}_id" } |
|
156
|
+
options[:relationships].map{ |relationship| relationship.underscore }
|
157
157
|
).join(" ")
|
158
158
|
end
|
159
159
|
|
data/lib/ng_on_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ng_on_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3.
|
4
|
+
version: 0.0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brookie Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: angularjs-rails
|