Skip to content

Commit

Permalink
minor improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
nrn committed Jan 19, 2013
1 parent 330106d commit 5a1967a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@ Flates is simple functional templating in javascript.

[![browser support](http://ci.testling.com/nrn/flates.png)](http://ci.testling.com/nrn/flates)

## f.<tagName>([attributes, ]innerHTML...)
## f(tag[, attributes, innerHTML...]) || f.tag([attributes, innerhtml])

Each function takes an optional attribute object which is just the
{ key: 'value' } representation of key="value" pairs you want
Expand Down
10 changes: 3 additions & 7 deletions flates.js
Expand Up @@ -2,9 +2,8 @@
function Flates () {

function f (tag, attr) {
var con = arrayify(arguments)
con.shift()
var attributes = ''
var con = Array.prototype.slice.call(arguments, 1)
, attributes = ''
if (!stringNumArray(attr)) {
con.shift()
attributes = attrStr(attr)
Expand All @@ -20,7 +19,7 @@ function Flates () {
}

function attrStr (attrObj) {
if (typeof attrObj !== 'object') return ''
if (typeof attrObj !== 'object' || !attrObj) return ''
return ' ' + Object.keys(attrObj).map(function (key) {
return key + '="' + attrObj[key] + '"'
}).join(' ')
Expand All @@ -32,9 +31,6 @@ function Flates () {
if (Array.isArray(item)) return true
return false
}
function arrayify (arr) {
return Array.prototype.slice.apply(arr)
}

function flatten (arr) {
if (Array.isArray(arr)) return arr.map(flatten).join('')
Expand Down
17 changes: 7 additions & 10 deletions package.json
@@ -1,5 +1,5 @@
{ "name": "flates"
, "version": "0.0.4"
, "version": "0.0.5"
, "author": "Nick Niemeir <nick.niemeir@gmail.com> (http://nrn.io)"
, "description": "Simple functions to build html strings."
, "keywords": [ "HTML", "template", "templates", "functional" ]
Expand All @@ -10,15 +10,12 @@
, "testling":
{ "files": [ "t/*.js" ]
, "browsers":
[ "chrome/latest"
, "chrome/canary"
, "firefox/latest"
, "firefox/nightly"
, "opera/latest"
, "opera/next"
, "safari/latest"
, "ie/latest"
]
{ "chrome": [ "23", "canary" ]
, "firefox": [ "17", "nightly" ]
, "safari": [ "5.1" ]
, "ie": [ "10" ]
, "opera": [ "12", "next" ]
}
}
, "repository":
{ "type": "git"
Expand Down
5 changes: 2 additions & 3 deletions t/strings.js
Expand Up @@ -2,10 +2,9 @@ var test = require('tape')
, f = require('../flates')

function build (obj) {
if (typeof obj === 'undefined') return obj
if (Array.isArray(obj)) return f.ul(obj.map(build).map(first(f.li)))
else if (typeof obj === 'object') {
return f.dl(Object.keys(obj).map( function(key) {
else if (typeof obj === 'object' && obj) {
return f.dl(Object.keys(obj).map(function(key) {
return f.dt(key) + f.dd(build(obj[key]))
}))
} else return obj
Expand Down

0 comments on commit 5a1967a

Please sign in to comment.