express-view-helpers
Advanced tools
Comparing version 0.0.0 to 0.0.1
var helpers = { | ||
linkTo: function(text, url) { | ||
return "<a href='" + url + "'>" + text + "</a>" | ||
linkTo: function(text, url, options) { | ||
options = options || {} | ||
options.href = url | ||
return "<a " + hashToAttributes(options) + ">" + text + "</a>" | ||
}, | ||
cssTag: function(path) { | ||
return "<link rel='stylesheet' href='" + path + "' type='text/css' charset='utf-8'>" | ||
cssTag: function(path, options) { | ||
options = options || {} | ||
options.rel = 'stylesheet' | ||
options.href = path | ||
options.type = 'text/css' | ||
options.charset = 'utf-8' | ||
return "<link " + hashToAttributes(options) + ">" | ||
}, | ||
jsTag: function(path) { | ||
return "<script type='text/javascript' src='" + path + "' charset='utf-8'></script>" | ||
jsTag: function(path, options) { | ||
options = options || {} | ||
options.type = 'text/javascript' | ||
options.src = path | ||
options.charset = 'utf-8' | ||
return "<script " + hashToAttributes(options) + "></script>" | ||
}, | ||
label: function(name, text) { | ||
return "<label for='" + name + "'>" + text + "</label>" | ||
label: function(name, text, options) { | ||
options = options || {} | ||
options.for = name | ||
return "<label " + hashToAttributes(options) + ">" + text + "</label>" | ||
}, | ||
submitTag: function(text) { | ||
return "<input type='submit' value='" + text + "'>" | ||
submitTag: function(text, options) { | ||
options = options || {} | ||
options.type = 'submit' | ||
options.value = text | ||
return "<input " + hashToAttributes(options) + ">" | ||
}, | ||
imageTag: function(src, alt) { | ||
return "<img src='" + src + "' alt='" + alt + "' />" | ||
imageTag: function(src, options) { | ||
options = options || {} | ||
options.src = src | ||
return "<img " + hashToAttributes(options) + " />" | ||
}, | ||
@@ -23,18 +47,25 @@ require: require | ||
var injectInputHelper = function(helperName, type) { | ||
helpers[helperName] = function(name, value, options) { | ||
options = options || {} | ||
var result = "<input type='" + type + "' name='" + name + "'" | ||
if(options.id) | ||
result += " id='" + options.id + "'" | ||
return result + ">" | ||
var hashToAttributes = function(hash) { | ||
var result = [] | ||
for(var key in hash) { | ||
var value = hash[key] | ||
if((value != null) && (typeof value != 'undefined')) { | ||
result.push(key + "='" + value + "'") | ||
} | ||
} | ||
return result.join(" ") | ||
} | ||
var types = ['text', 'password'] | ||
types.forEach(function(type) { injectInputHelper(type + 'Field', type) }) | ||
types.forEach(function(type) { | ||
helpers[type + 'Field'] = function(name, value, options) { | ||
options = options || {} | ||
options.type = type | ||
options.name = name | ||
options.value = value | ||
return "<input " + hashToAttributes(options) + ">" | ||
} | ||
}) | ||
module.exports = helpers |
{ | ||
"name": "express-view-helpers", | ||
"description": "Some view helpers for expressjs.", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"repository": { | ||
@@ -15,3 +15,6 @@ "type": "git", | ||
"node": "*" | ||
} | ||
}, | ||
"files": [ | ||
"" | ||
] | ||
} |
2944
6
75