Browse files

Closes #227, added select tag support for contentTag, if the tag is s…

…elect and the content is an Array then it will use the array items as options for the select statement.

Also fixed some error dealing with i18n, where `lib/model/*` was requiring a non existant file/dir.
  • Loading branch information...
1 parent 62886dd commit c2df52f84e00670e683b715c391a58b93e48f124 @larzconwell larzconwell committed Oct 13, 2012
View
3 docs/5-templates.md
@@ -324,6 +324,9 @@ contentTag('a', 'hey there', {href: 'http://google.com', data: { goTo: 'http://g
contentTag('a', 'hey there', {href: 'http://google.com', data_go_to: 'http://google.com'})
// => '<a data-go-to="http://google.com" href="http://google.com">hey there</a>'
+
+contentTag('select', ['geddy', 'alex', 'neil'])
+// => '<select><option value="geddy">geddy</option><option value="alex">alex</option><option value="neil">neil</option></select>'
```
* * *
View
3 lib/model/datatypes.js
@@ -16,7 +16,8 @@
*
*/
-var i18n = require('../i18n');
+
+var i18n = require('utilities').i18n;
/*
* Datatype verification -- may modify the value by casting
View
2 lib/model/index.js
@@ -43,7 +43,7 @@ User = geddy.model.register('User', User);
var model = {}
, utils = require('utilities')
- , i18n = require('../i18n');
+ , i18n = utils.i18n;
model.datatypes = require('./datatypes.js');
model.validators = require('./validators.js');
View
2 lib/model/validators.js
@@ -16,7 +16,7 @@
*
*/
-var i18n = require('../i18n');
+var i18n = require('utilities').i18n;
/*
* Basic validators -- name is the field name, params is the entire params
View
10 lib/template/helpers/utils.js
@@ -62,6 +62,16 @@ exports.tags = {
if (tag === 'img') {
htmlOptions.alt = htmlOptions.alt === '' ? htmlOptions.alt : htmlOptions.alt || content;
}
+ if (tag === 'select' && typeof content !== 'string') {
+ var tags = '';
+
+ for (var i = 0; i < content.length; i++) {
+ tags += this.contentTagString('option', content[i], {value: content[i]});
+ }
+
+ content = tags;
+ }
+
tagOptions = this.tagOptions(htmlOptions);
content = this.preContentStrings[tag] ?
View
10 test/templates/helpers/helpers.js
@@ -96,6 +96,16 @@ tests = {
assert.equal(string, '<a data-go-to="http://google.com" href="http://google.com">http://google.com</a>');
}
+, 'test select tag for contentTag': function () {
+ var string = helpers.contentTag('select', ['geddy', 'alex', 'neil']);
+ assert.equal(string, '<select><option value="geddy">geddy</option><option value="alex">alex</option><option value="neil">neil</option></select>');
+ }
+
+, 'test select tag with a string for contentTag': function () {
+ var string = helpers.contentTag('select', 'some incorrect content');
+ assert.equal(string, '<select>some incorrect content</select>');
+ }
+
, 'test single tags in truncateHTML': function () {
var string = helpers.truncateHTML('<p>Once upon a time in a world</p>', { length: 10 });
assert.equal(string, '<p>Once up...</p>');

0 comments on commit c2df52f

Please sign in to comment.