Permalink
Browse files

Closes #259, Fix error where no properties at all would throw when co…

…mpiling templates. Now if no default is given it will use the ID property, and when looping will only add the items template if it has content in it's name field
  • Loading branch information...
1 parent a762c12 commit 7609a4945baedfbe6a467c56f4caec4de2e50639 @larzconwell larzconwell committed Nov 10, 2012
View
@@ -253,10 +253,12 @@ namespace('gen', function () {
};
var _formatModelProperties = function (properties) {
+ var obj = {default: {name: '', type: ''}};
if (!properties) {
- return {};
+ return obj;
}
- var obj = {default: {name: 'id', type: 'int'}};
+ obj['default'].name = 'id';
+ obj['default'].type = 'int';
Techwraith
Techwraith Nov 10, 2012 Contributor

Is there a reason we're using type "int" here?

larzconwell
larzconwell Nov 10, 2012 Contributor

That's what the default is for Model correct? This doesn't show up anywhere in the scaffold code, it's just so that when we compile the model below we check if we should add this.autoIncrementId = true;

Techwraith
Techwraith via email Nov 10, 2012 Contributor
mde
mde via email Nov 10, 2012 Contributor
larzconwell
larzconwell Nov 10, 2012 Contributor

Oh okay that makes a lot of sense. I'll change it to string, then cherry-pick it to the v0.6 branch.

mde
mde via email Nov 10, 2012 Contributor
larzconwell
larzconwell Nov 10, 2012 Contributor

I think I got it now, sorry it's taken me song long to get this shit down.

var itemsArr = properties.split('%')
, name
@@ -2,7 +2,7 @@ var <%= names.constructor.singular %> = function () {
this.defineProperties({
<% for (var i in properties) { -%>
-<% if (properties[i].name !== 'id') { -%>
+<% if (properties[i].name && properties[i].name !== 'id') { -%>
<% if (i === 'default') { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>', required: true},
<% } else { -%>
@@ -1,5 +1,5 @@
<% for(var i in properties) { -%>
-<% if(properties[i].name !== 'id') { -%>
+<% if(properties[i].name && properties[i].name !== 'id') { -%>
<div class="control-group">
<label for="<%= properties[i].name %>" class="control-label"><%= properties[i].name %></label>
<div class="controls">
@@ -8,7 +8,7 @@
<@ for (var i = 0, ii = <%= names.property.plural %>.length; i < ii; i++) { @>
<div class="row list-item" id="<%= names.property.singular %>-<@= <%= names.property.plural %>[i].id; @>">
<div class="span8">
- <h3><@- linkTo(<%= names.property.plural %>[i].<%= properties['default'].name %>, <%= names.property.singular %>Path(<%= names.property.plural %>[i].id)); @></h3>
+ <h3><@- linkTo(<%= names.property.plural %>[i].<%= properties['default'].name || "id" %>, <%= names.property.singular %>Path(<%= names.property.plural %>[i].id)); @></h3>
</div>
<div class="span4">
<h3><i class="icon-list-alt"></i><@= <%= names.property.plural %>[i].id; @></h3>
@@ -26,7 +26,7 @@ $(function () {
var template = [ ''
, '<div class="row list-item" id="<%= names.property.singular %>-' + <%= names.property.singular %>.id + '">'
, ' <div class="span8">'
- , ' <h3><a href="/<%= names.property.plural %>/' + <%= names.property.singular %>.id + '">' + <%= names.property.singular %>.<%= properties['default'].name %> + '</a></h3>'
+ , ' <h3><a href="/<%= names.property.plural %>/' + <%= names.property.singular %>.id + '">' + <%= names.property.singular %>.<%= properties['default'].name || "id" %> + '</a></h3>'
, ' </div>'
, ' <div class="span4">'
, ' <h3><i class="icon-list-alt"></i>' + <%= names.property.singular %>.id + '</h3>'
@@ -1,5 +1,5 @@
<div class="hero-unit">
- <h2 class="<%= properties['default'].name %>"><@= <%= names.property.singular %>.<%= properties['default'].name %> @></h2>
+ <h2 class="<%= properties['default'].name || "id" %>"><@= <%= names.property.singular %>.<%= properties['default'].name || "id" %> @></h2>
<@- linkTo('Edit this <%= names.property.singular %>', edit<%= names.constructor.singular %>Path(params.id), {class: 'btn pull-right'}); @>
</div>
@@ -1,5 +1,5 @@
<% for(var i in properties) { -%>
-<% if(properties[i].name !== 'id') { -%>
+<% if(properties[i].name && properties[i].name !== 'id') { -%>
.control-group
label(for="<%= properties[i].name %>", class="control-label") <%= properties[i].name %>
.controls
@@ -7,7 +7,7 @@ div#<%= names.property.plural %>-list
each <%= names.property.singular %> in <%= names.property.plural %>
.row.list-item(id="<%= names.property.singular %>-" + <%= names.property.singular %>.id)
.span8
- h3!= linkTo(<%= names.property.singular %>.<%= properties['default'].name %>, <%= names.property.singular %>Path(<%= names.property.singular %>.id))
+ h3!= linkTo(<%= names.property.singular %>.<%= properties['default'].name || "id" %>, <%= names.property.singular %>Path(<%= names.property.singular %>.id))
.span4
h3
i.icon-list-alt
@@ -21,7 +21,7 @@ script(type="text/javascript")
var template = [ ''
, '<div class="row list-item" id="<%= names.property.singular %>-' + <%= names.property.singular %>.id + '">'
, ' <div class="span8">'
- , ' <h3><a href="/<%= names.property.plural %>/' + <%= names.property.singular %>.id + '">' + <%= names.property.singular %>.<%= properties['default'].name %> + '</a></h3>'
+ , ' <h3><a href="/<%= names.property.plural %>/' + <%= names.property.singular %>.id + '">' + <%= names.property.singular %>.<%= properties['default'].name || "id" %> + '</a></h3>'
, ' </div>'
, ' <div class="span4">'
, ' <h3><i class="icon-list-alt"></i>' + <%= names.property.singular %>.id + '</h3>'
@@ -1,5 +1,5 @@
.hero-unit
- h2= <%= names.property.singular %>.<%= properties['default'].name %>
+ h2.<%= properties['default'].name || "id" %>= <%= names.property.singular %>.<%= properties['default'].name || "id" %>
!= linkTo('Edit this <%= names.property.singular %>', edit<%= names.constructor.singular %>Path(params.id), {class: 'btn pull-right'})
h2 <%= names.constructor.singular %> Properties
@@ -1,5 +1,5 @@
<% for(var i in properties) { -%>
-<% if(properties[i].name !== 'id') { -%>
+<% if(properties[i].name && properties[i].name !== 'id') { -%>
<div class="control-group">
<label for="<%= properties[i].name %>" class="control-label"><%= properties[i].name %></label>
<div class="controls">
@@ -8,7 +8,7 @@
<@ for (var i = 0, ii = <%= names.property.plural %>.length; i < ii; i++) { @>
<div class="row list-item" id="<%= names.property.singular %>-<@= <%= names.property.plural %>[i].id; @>">
<div class="span8">
- <h3><@- linkTo(<%= names.property.plural %>[i].<%= properties['default'].name %>, <%= names.property.singular %>Path(<%= names.property.plural %>[i].id)); @></h3>
+ <h3><@- linkTo(<%= names.property.plural %>[i].<%= properties['default'].name || "id" %>, <%= names.property.singular %>Path(<%= names.property.plural %>[i].id)); @></h3>
</div>
<div class="span4">
<h3><i class="icon-list-alt"></i><@= <%= names.property.plural %>[i].id; @></h3>
@@ -1,5 +1,5 @@
<div class="hero-unit">
- <h2 class="<%= properties['default'].name %>"><@= <%= names.property.singular %>.<%= properties['default'].name %> @></h2>
+ <h2 class="<%= properties['default'].name || "id" %>"><@= <%= names.property.singular %>.<%= properties['default'].name || "id" %> @></h2>
<@- linkTo('Edit this <%= names.property.singular %>', edit<%= names.constructor.singular %>Path(params.id), {class: 'btn pull-right'}); @>
</div>
@@ -1,5 +1,5 @@
<% for(var i in properties) { -%>
-<% if(properties[i].name !== 'id') { -%>
+<% if(properties[i].name && properties[i].name !== 'id') { -%>
.control-group
label(for="<%= properties[i].name %>", class="control-label") <%= properties[i].name %>
.controls
@@ -7,7 +7,7 @@ div#<%= names.property.plural %>-list
each <%= names.property.singular %> in <%= names.property.plural %>
.row.list-item(id="<%= names.property.singular %>-" + <%= names.property.singular %>.id)
.span8
- h3!= linkTo(<%= names.property.singular %>.<%= properties['default'].name %>, <%= names.property.singular %>Path(<%= names.property.singular %>.id))
+ h3!= linkTo(<%= names.property.singular %>.<%= properties['default'].name || "id" %>, <%= names.property.singular %>Path(<%= names.property.singular %>.id))
.span4
h3
i.icon-list-alt
@@ -1,5 +1,5 @@
.hero-unit
- h2= <%= names.property.singular %>.<%= properties['default'].name %>
+ h2.<%= properties['default'].name || "id" %>= <%= names.property.singular %>.<%= properties['default'].name || "id" %>
!= linkTo('Edit this <%= names.property.singular %>', edit<%= names.constructor.singular %>Path(params.id), {class: 'btn pull-right'})
h2 <%= names.constructor.singular %> Properties

0 comments on commit 7609a49

Please sign in to comment.