Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Closes 210, Generators will use `name` and `title` properties as the …

…default if they exist, falling back to ID or the explicitly set default.
  • Loading branch information...
commit d9489a2a2481c5877768f94c3a5ef6c66188c043 1 parent 376ae14
@larzconwell larzconwell authored
View
42 templates/Jakefile
@@ -219,6 +219,9 @@ namespace('gen', function () {
if (!type) {
type = 'string';
}
+ if (args === 'def') {
+ args = 'default';
+ }
switch (type) {
case 'text':
@@ -237,26 +240,33 @@ namespace('gen', function () {
break;
}
- if (args === 'def') {
- args = 'default';
+ // Manage properties that deal with changing the default property
+ if (args === 'default') {
+ // Reset old default to it's own property
+ obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
+
+ // Add new default property
+ obj['default'] = {name: name, type: type};
+ continue;
}
- // Set property as default if given the `default` argument
- if (args === 'default') {
+ // If ID property is given and it matches the default
+ // then rewrite the default with the new ID property
+ if (name === 'id' && obj['default'].name === 'id') {
obj['default'] = {name: name, type: type};
- // Add the original ID property
- obj['id'] = obj['id'] || {name: 'id', type: 'int'};
+ continue;
}
- else {
- // If ID property is given and it matches the default
- // then rewrite the default with the new ID property
- if (name === 'id' && obj['default'].name === 'id') {
- obj['default'] = {name: name, type: type};
- }
- else {
- // Add the property normally
- obj[name] = {name: name, type: type};
- }
+
+ // If the name is name or title then set them to default, otherwise add
+ // the property normally
+ if (name === 'name' || name === 'title') {
+ // Reset old default to it's own property
+ obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
+
+ // Add new default property
+ obj['default'] = {name: name, type: type};
+ } else {
+ obj[name] = {name: name, type: type};
}
}
View
7 templates/resource/model.ejs
@@ -1,13 +1,12 @@
var <%= names.constructor.singular %> = function () {
this.defineProperties({
-<% for(var i in properties) { -%>
-<% if(i === 'default') { -%>
-<% if(properties[i].name !== 'id') { -%>
+<% for (var i in properties) { -%>
+<% if (i === 'default') { -%>
+<% if (properties[i].name !== 'id') { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>', required: true},
<% } -%>
<% } else { -%>
-<% if(i !== 'id') -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>'},
<% } -%>
<% } -%>
View
7 templates/scaffold/model.ejs
@@ -1,13 +1,12 @@
var <%= names.constructor.singular %> = function () {
this.defineProperties({
-<% for(var i in properties) { -%>
-<% if(i === 'default') { -%>
-<% if(properties[i].name !== 'id') { -%>
+<% for (var i in properties) { -%>
+<% if (i === 'default') { -%>
+<% if (properties[i].name !== 'id') { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>', required: true},
<% } -%>
<% } else { -%>
-<% if(i !== 'id') -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>'},
<% } -%>
<% } -%>
Please sign in to comment.
Something went wrong with that request. Please try again.