BuildSugar 0.1a1 Demo

Provides a bizarrely clean & simple syntax sugar for building HTML/XML strings http://gist.github.com/27801

by Thomas Aylott

CSS

/* Blueprint CSS */

html,body,div,span,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,code,del,dfn,em,img,q,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;font-weight:inherit;font-style:inherit;font-size:100%;font-family:inherit;vertical-align:baseline;}body{line-height:1.5;}table{border-collapse:separate;border-spacing:0;}caption,th,td{text-align:left;font-weight:normal;}table,td,th{vertical-align:middle;}blockquote:before,blockquote:after,q:before,q:after{content:"";}blockquote,q{quotes:"" "";}a img{border:none;}body{font-size:75%;color:#222;background:#fff;font-family:"Helvetica Neue",Arial,Helvetica,sans-serif;}h1,h2,h3,h4,h5,h6{font-weight:normal;color:#111;}h1{font-size:3em;line-height:1;margin-bottom:.5em;}h2{font-size:2em;margin-bottom:.75em;}h3{font-size:1.5em;line-height:1;margin-bottom:1em;}h4{font-size:1.2em;line-height:1.25;margin-bottom:1.25em;}h5{font-size:1em;font-weight:bold;margin-bottom:1.5em;}h6{font-size:1em;font-weight:bold;}h1 img,h2 img,h3 img,h4 img,h5 img,h6 img{margin:0;}p{margin:0 0 1.5em;}img.left{float:left;margin:1.5em 1.5em 1.5em 0;padding:0;}img.right{float:right;margin:1.5em 0 1.5em 1.5em;}a:focus,a:hover{color:#000;}a{color:#009;text-decoration:underline;}blockquote{margin:1.5em;color:#666;font-style:italic;}strong{font-weight:bold;}em,dfn{font-style:italic;}dfn{font-weight:bold;}sup,sub{line-height:0;}abbr,acronym{border-bottom:1px dotted #666;}address{margin:0 0 1.5em;font-style:italic;}del{color:#666;}pre{margin:1.5em 0;white-space:pre;}pre,code,tt{font:1em 'andale mono','lucida console',monospace;line-height:1.5;}li ul,li ol{margin:0 1.5em;}ul,ol{margin:0 1.5em 1.5em 1.5em;}ul{list-style-type:disc;}ol{list-style-type:decimal;}dl{margin:0 0 1.5em 0;}dl dt{font-weight:bold;}dd{margin-left:1.5em;}table{margin-bottom:1.4em;width:100%;}th{font-weight:bold;}thead th{background:#c3d9ff;}th,td,caption{padding:4px 10px 4px 5px;}tr.even...

JavaScript

/*
---
provides  : BuildSugar
version   : 0.1alpha1
source    : http://gist.github.com/278016
copyright : 2010 Thomas Aylott
license   : MIT
...
*/
var BS=function(c){function f(a,b){c.push([])
return d(a,b)}function d(a,b){b=""+(b||"")
a&&e("<",a,">")
b&&e(b)
a&&e("</",a.split(" ")[0],">")
return d}d.toString=function(){return c.pop().join("")}
function e(){c[c.length-1].push([].join.call(arguments,""))}return f}([])
/* */


document
.write
(BS
    
    
    ('H1' ,"Battlestar Galactica DVDs")
    
    ('P' ,"Best.  Show.  Evar. ")
    
    ('A href=#' ,BS ('IMG src="http://bit.ly/WinAylott"') ('BR')
        ('' ,"View larger image") )
    
    ('FORM method=GET' ,BS
        
        ('LABEL for=quantity' ,"Quantity")
        ('INPUT name=quantity value=1')
        
        ('INPUT type=submit value="Add to Cart"')
    )
    
)