Code Monkey home page Code Monkey logo

coffeecup's People

Contributors

aeosynth avatar anodynos avatar asalant avatar awwx avatar benekastah avatar bobzoller avatar brandonbloom avatar colinta avatar dvv avatar esamattis avatar flosse avatar gradus avatar hurrymaplelad avatar ilogico avatar jfhbrook avatar lancejpollard avatar mauricemach avatar mikesmullin avatar miladaghamohamadnia avatar mwl avatar rachel-carvalho avatar randypuro avatar shimaore avatar srackham avatar wmertens avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coffeecup's Issues

Misc visibility issues

  • The easydoc refers to the coffeekup_ Google group which doesn't exist. Should it be coffeekup?
  • Your coffeekup fork could point to coffeecup in its readme so people can find it more easily. It took me a while to find coffeecup.
  • Your easydoc could embed an example like http://coffeekup.org does.

SVG text elements do not work due to clash with text helper function

I'm using CoffeeCup to create SVG content. This works great except for one issue. SVG has a <text> element. But in CoffeeCup, the obvious way of creating such elements doesn't work. I want to generate <text x="42" y="13">Hello</text>.

text {x: 42, y:13}, 'Hello'

This only produces [Object], as it invokes the text helper function instead of a tag function. A workaround I found is to define my own helper function that can create arbitrary elements:

helpers = element: (tagname, args...) -> __cc.tag(tagname, args)
coffeecup.render myTemplate, myData, hardcode: helpers

I use it like this in the template to produce the desired result:

element 'text', {x: 42, y:13}, 'Hello'

Maybe a similar function could be added to the CoffeeCup DSL, to deal with this situation, as well as any other potential future situation where an element name may clash with a helper or reserved word?

node 0.10 warning

with node 0.10 and npm 1.2.14, coffeecup gives the following warning

npm WARN engine [email protected]: wanted: {"node":"0.4.x || 0.6.x || 0.8.x"} (current: {"node":"v0.10.0","npm":"1.2.14"})

If it already works in 0.10 without anything, would be just a matter of changing it in the package.json file

Element ID shorthand breaks in IE

mauricemach/coffeekup#96
from @hankmander

the coffekup code:
div "#my_id", ->
gives:

instead of giving the element an id it gives the element a class that starts with a '#'. However, it works if you do this instead: div id: "register_interest", ->

giving elements classes ( div ".my_id", -> ) works as expected though.

NOTE. This only occurs when client side rendering a template in Internet explorer 7. Might apply to other versions of IE as well.

Edit: version 0.3.1 of coffeekup and 1.1.2 of coffeescript used

Optimized template test fails

$ coffee ./test_optimized.coffee
The "sys" module is now called "util". It should have a similar interface.
[Failed] Literal text
[Passed] Default DOCTYPE
[Passed] DOCTYPE
[Passed] Custom tag
[Passed] Custom tag with attributes
[Passed] Custom tag with attributes and inner content
[Passed] Self-closing tags
[Passed] Common tag
[Passed] Attributes
[Passed] HereDocs
[Passed] CoffeeScript helper (function)
[Passed] CoffeeScript helper (string)
[Passed] Context vars
[Passed] Local vars, hardcoded
[Passed] Local vars, hard-coded (functions)
[Passed] Local vars, hard-coded ("helpers")
[Passed] Local vars
[Passed] Comments
[Passed] Escaping
[Passed] Autoescaping
[Passed] ID/class shortcut (combo)
[Passed] ID/class shortcut (ID only)
[Passed] ID/class shortcut (one class only)
[Passed] ID/class shortcut (multiple classes)
[Passed] ID/class shortcut (no string contents)
[Passed] Attribute values
[Passed] IE conditionals
[Passed] yield

28 tests, 27 passed, 1 failed, 0 errors

FAILED:

- Literal text:
text 'Just text'
{"optimize":true,"cache":true}
Just text
<text>Just text</text>

coffeecup and express3

Hi all,
saw that Coffeecup was updated for express 3 in #39. But, I can't seem to find the right syntax to bind a view engine in express 3 to Coffeecup. Could you update the README or the example/express plz
José

Optimize using function inlining

Putting this here for future reference:

There currently is an issue with the optimizer, it doesn't do exactly the same tag parsing as the regular code because it replaces the regular calls with equivalent code. The correct solution is to replace calls with the end result if the call is static, using function inlining.

I had a look at doing that but it's a bit too much to take on for me right now. UglifyJS doesn't seem to have something like that out of the box and it should really be done by it and not the coffeecup optimizer.

Closure can do it: https://developers.google.com/closure/compiler/docs/api-tutorial3#enable
Haven't tested that though.

coffeecup and form validation

Hi all,
this is not really an issue, but a quick two questions related to coffeecup.
(1) which module(s) do you guys recommend for form validation? I am using express 3
(2) is it still possible to use the layout.coffee file for the layout of my views? It doesn't display when I use twitter bootstrap. Any advice?
Thanks,
José

How To Refactor Right?

Hi

I am trying to refactor my code from

div  ->
  h2 'Heading'
    div ->
      MoreStuff

to

example = (headerText, stuff) ->
  div  ->
    h2 headerText
      div ->
        stuff

but

example 'Header', text 'ExampleText'

renderes to

ExampleText<div>
  <h2>RefactoredCode</h2>
  <div>
  </div>
</div>

though I expected it to be

<div>
  <h2>RefactoredCode</h2>
  <div>
    ExampleText
  </div>
</div>

Could somebody please tell me how to do it right? I could not find an answer to that in the docs. Or is refactoring this way not possible? Then it may be a real issue^^
Help is greatly appreciated.

Regards
Andreas Worm

Watch directories like Jitter

Jitter has an interesting feature:

https://github.com/TrevorBurnham/Jitter

jitter src/coffee/ web-app/js/

This will watch all CoffeeScript files in src/coffee/.coffee recursively and reproduce the same structure inside web-app/js/.js.

It would be great to be able to do the same with coffeecup, watching for changes recursively in *.cc and generating *.js when passed the --js option.

How about adding this feature to the coffeecup command?

precompilation options

I tried coffeecup because coffeekup cli wasn't working.
I was interested in precompiling the templates so I explored the options.

I wanted to be able to compile templates into a single file so I wrote a very simple patch, but I don't know how to commit it.
I'll read the git docs, but I would like to know if it's OK, or generally just get feedback from someone.

Switches --bare and --core seem to be ignored completely by the cli and I'm not sure how they should work. Currently, all the templates are added to the chosen namespace, each one declaring either the entire renderer or just the functions they need if the -z is used. It would be nice if we could reduce the output size as much as we could, but I feel I have to touch the compiler itself to achive that.

In general, I think the cli is a bit messy and inflexible, but I would just like to have some feedback before getting my hands too dirty.

Asynchronous document support

Importing: mauricemach/coffeekup#101

A feature CoffeeKup is definitely in need of is asynchronous rendering, this should look like:

div (done) ->
    setTimeout(
        ->
            text 'waited 5 seconds'
            done()
        5000
    )

It would enable far more powerful templating abilities especially when combined with CMSs such as DocPad

Add support for stdin

I didn't do a pull request. You have a few waiting anyway.

I suggest something like, to stay in line with the rest of the code and conventions, to modify cli.coffee and append a switch e.g. -i for processing stdin.

 ['-i', '--stdin', 'accept input over standard input interface stdin']

Then add

codeIn = ""
stdin = process.openStdin()

# and under run...

if options.stdin
    # Buffer streams of data and concat to string until finished
    stdin.on 'data', (buffer) -> codeIn += buffer.toString() if buffer
    stdin.on 'end', -> log coffeecup.render codeIn

This will allow for something like

$ coffee -p -b myfile.litcoffee | js2coffee | coffeecup -i

As a little round-trip since coffeescript cli tool doesn't really allow a unmangle of the .litcoffee files yet.

Support client-side script interpolation

This has been unresolved in a satisfactory manner since June 2012 someone first popped the question I believe.

Could there at least be some discussion on what would be a desirable approach to cleanly implement such a feature, if even desired, into coffeecup? I'd like to here what the lot of you think...

Cannot find module 'uglify-js'

unless uglify-js is installed globally following error occurs when running 'cake test'

Error: Cannot find module 'uglify-js'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (/Users/klop/node/coffeecup/src/compiler.coffee:7:10)
at Object. (/Users/klop/node/coffeecup/src/compiler.coffee:286:4)
at Module._compile (module.js:441:26)
at Object..coffee (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:21:21)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)

Syntax Error when minifying with connect-assets

only fails when using minifyBuilds: true with connect-assets. any idea what could be causing it? code below

(function(){var a,b,c,d,e,f,g,h,i,j=[].slice,k=[].indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(b in this&&this[b]===a)return b;return-1},l={}.hasOwnProperty,m=function(a,b){function d(){this.constructor=a}for(var c in b)l.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};typeof window!="undefined"&&window!==null?(c=window.coffeecup={},b=typeof CoffeeScript!="undefined"&&CoffeeScript!==null?CoffeeScript:null):(c=exports,b=require("coffee-script"),e=require(__dirname+"/compiler"),e.setup(c),g=require("fs")),c.version="0.3.16",c.doctypes={"default":"<!DOCTYPE html>",5:"<!DOCTYPE html>",xml:'<?xml version="1.0" encoding="utf-8" ?>',transitional:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',strict:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',frameset:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',1.1:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',basic:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',mobile:'<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">',ce:'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ce-html-1.0-transitional.dtd">'},d="var __slice = Array.prototype.slice;\nvar __hasProp = Object.prototype.hasOwnProperty;\nvar __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };\nvar __extends = function(child, parent) {\n for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }\n function ctor() { this.constructor = child; }\n ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype;\n return child; };\nvar __indexOf = Array.prototype.indexOf || function(item) {\n for (var i = 0, l = this.length; i < l; i++) {\n if (this[i] === item) return i;\n } return -1; };".replace(/\n/g,""),f={regular:"a abbr address article aside audio b bdi bdo blockquote body button canvas caption cite code colgroup datalist dd del details dfn div dl dt em fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup html i iframe ins kbd label legend li map mark menu meter nav noscript object ol optgroup option output p pre progress q rp rt ruby s samp script section select small span strong style sub summary sup table tbody td textarea tfoot th thead time title tr u ul video",svg:"a altGlyph altGlyphDef altGlyphItem animate animateColor animateMotion animateTransform circle clipPath color-profile cursor defs desc ellipse feBlend feColorMatrix feComponentTransfer feComposite feConvolveMatrix feDiffuseLighting feDisplacementMap feDistantLight feFlood feFuncA feFuncB feFuncG feFuncR feGaussianBlur feImage feMerge feMergeNode feMorphology feOffset fePointLight feSpecularLighting feSpotLight feTile feTurbulence filter font font-face font-face-format font-face-name font-face-src font-face-uri foreignObject g glyph glyphRef hkern image line linearGradient marker mask metadata missing-glyph mpath path pattern polygon polyline radialGradient rect script set stop style svg symbol text textPath title tref tspan use view vkern","void":"area base br col command embed hr img input keygen link meta param source track wbr",obsolete:"applet acronym bgsound dir frameset noframes isindex listing nextid noembed plaintext rb strike xmp big blink center font marquee multicol nobr spacer tt",obsolete_void:"basefont frame"},h=function(){var a,b,c,d,e,g,h,i,l;b=1<=arguments.length?j.call(arguments,0):[],d=[];for(e=0,h=b.length;e<h;e++){a=b[e],l=f[a].split(" ");for(g=0,i=l.length;g<i;g++)c=l[g],k.call(d,c)<0&&d.push(c)}return d},c.tags=h("regular","obsolete","void","obsolete_void","svg"),c.self_closing=h("void","obsolete_void"),i=function(a){var b,c,d,e,f,g,h,i,l,m,n,o;return a==null&&(a={}),(n=a.format)==null&&(a.format=!1),(o=a.autoescape)==null&&(a.autoescape=!1),m={buffer:[],esc:function(b){return a.autoescape?f(b):b.toString()},tabs:0,repeat:function(a,b){return Array(b+1).join(a)},indent:function(){if(a.format)return l(this.repeat(" ",this.tabs))},tag:function(b,c){var d,e,f,g;d=[b];for(f=0,g=c.length;f<g;f++)e=c[f],d.push(e);return i.apply(a,d)},render_idclass:function(a){var b,c,d,e,f,g,h,i,j,k;c=[],k=a.split(".");for(f=g=0,i=k.length;g<i;f=++g)d=k[f],d!==""&&(f===0&&d.indexOf("#")===0?e=d.slice(1):c.push(d));e&&l(' id="'+e+'"');if(c.length>0){l(' class="');for(h=0,j=c.length;h<j;h++)b=c[h],b!==c[0]&&l(" "),l(b);return l('"')}},render_attrs:function(a,b){var c,d,e;b==null&&(b=""),e=[];for(c in a)d=a[c],typeof d=="boolean"&&d&&(d=c),typeof d=="function"&&(d="("+d+").call(this);"),typeof d!="object"||d instanceof Array?d||d===0?e.push(l(" "+(b+c)+'="'+this.esc(d)+'"')):e.push(void 0):e.push(this.render_attrs(d,b+c+"-"));return e},render_contents:function(b,c){var d;c==null&&(c=!1);switch(typeof b){case"string":case"number":case"boolean":return l(c?b:this.esc(b));case"function":return a.format&&l("\n"),this.tabs++,d=b.call(a),typeof d=="string"&&(this.indent(),l(c?d:this.esc(d)),a.format&&l("\n")),this.tabs--,this.indent()}},render_tag:function(b,c,d,e,f){return this.indent(),l("<"+b),c&&this.render_idclass(c),d&&this.render_attrs(d),e&&l(" "+e),k.call(this.self_closing,b)>=0?(l(" />"),a.format&&l("\n")):(l(">"),this.render_contents(f),l("</"+b+">"),a.format&&l("\n")),null}},i=function(){var a,b,c,d,e,f,g,h,i,k;h=arguments[0],b=2<=arguments.length?j.call(arguments,1):[];for(i=0,k=b.length;i<k;i++){a=b[i];switch(typeof a){case"function":d=a;break;case"object":c=a;break;case"number":case"boolean":d=a;break;case"string":b.length===1?d=a:a===b[0]?(e=a.charAt(0),e==="#"||e==="."?(f=a.substr(0,a.indexOf(" ")),g=a.substr(a.indexOf(" ")+1),f===""&&(f=g,g=void 0)):(g=a,g===""&&(g=void 0))):d=a}}return m.render_tag(h,f,c,g,d)},b=function(a){var b,c;return c=[],b=m.buffer,m.buffer=c,a(),m.buffer=b,c.join("")},f=function(a){return a.toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")},e=function(b){b==null&&(b="default"),l(m.doctypes[b]);if(a.format)return l("\n")},l=function(a){return m.buffer.push(a.toString()),null},d=function(b){l("<!--"+b+"-->");if(a.format)return l("\n")},c=function(a){switch(typeof a){case"function":return script(""+m.coffeescript_helpers+"("+a+").call(this);");case"string":return script({type:"text/coffeescript"},function(){return a});case"object":return a.type="text/coffeescript",script(a)}},h=function(b){if(a.stylus==null)throw new TemplateError("stylus is not available");l("<style>"),a.format&&l("\n"),a.stylus.render(b,{compress:!a.format},function(a,b){if(a)throw a;return l(b)}),l("</style>");if(a.format)return l("\n")},g=function(b,c){m.indent(),l("<!--[if "+b+"]>"),m.render_contents(c),l("<![endif]-->");if(a.format)return l("\n")},null},i=i.toString().replace(/function\s*\(.*\)\s*\{/,"").replace(/return null;\s*\}$/,""),i=d+i,c.compile=function(a,f){var g,h,j,k,l,m,n,o,p,q,r,s,t;f==null&&(f={}),typeof a=="function"?a=a.toString():typeof a=="string"&&b!=null&&(a=b.compile(a,{bare:!0}),a="function(){"+a+"}"),h="";if(f.hardcode){s=f.hardcode;for(j in s)n=s[j],typeof n=="function"?h+="var "+j+" = function(){return ("+n+").apply(data, arguments);};":h+="var "+j+" = "+JSON.stringify(n)+";"}if(f.optimize&&e!=null)return e.compile(a,h,f);l="",m=[],t=c.tags;for(o=0,q=t.length;o<q;o++)k=t[o],(a.indexOf(k)>-1||h.indexOf(k)>-1)&&m.push(k);l+="var "+m.join(",")+";";for(p=0,r=m.length;p<r;p++)k=m[p],l+=""+k+" = function(){return __cc.tag('"+k+"', arguments);};";return g=l+h+i,g+="__cc.doctypes = "+JSON.stringify(c.doctypes)+";",g+="__cc.coffeescript_helpers = "+JSON.stringify(d)+";",g+="__cc.self_closing = "+JSON.stringify(c.self_closing)+";",f.locals&&(g+="with(data.locals){"),g+="("+a+").call(data);",f.locals&&(g+="}"),g+="return __cc.buffer.join('');",new Function("data",g)},a={},c.render=function(b,d,e){var f,g,h,i;d==null&&(d={}),e==null&&(e={});for(f in e)h=e[f],d[f]=h;(i=d.cache)==null&&(d.cache=!1);if(typeof window=="undefined"||window===null)d.stylus=require("stylus");return d.optimize&&!d.cache&&(d.optimize=!1),d.cache&&a[b]!=null?g=a[b]:d.cache?g=a[b]=c.compile(b,d):g=c.compile(b,d),g(d)};if(typeof window=="undefined"||window===null)c.__express=function(b,d,e){var f;return d==null&&(d={}),d.stylus=require("stylus"),d.optimize&&!d.cache&&(d.optimize=!1),d.cache&&a[b]!=null?(f=a[b],e(null,f(d))):g.readFile(b,"utf8",function(g,h){return g?e(g):(f=c.compile(h,d),d.cache&&(a[b]=f),e(null,f(d)))})},c.adapters={simple:c.render,meryl:c.render,express:{TemplateError:function(a){function b(a){this.message=a,Error.call(this,this.message),Error.captureStackTrace(this,arguments.callee)}return m(b,a),b.prototype.name="TemplateError",b}(Error),compile:function(a,b){var d,e,f;(f=b.hardcode)==null&&(b.hardcode={}),b.hardcode.partial=function(){return text(this.partial.apply(this,arguments))},d=this.TemplateError;try{e=c.compile(a,b)}catch(g){throw new d("Error compiling "+b.filename+": "+g.message)}return function(){try{return e.apply(null,arguments)}catch(a){throw new d("Error rendering "+b.filename+": "+a.message)}}}}}}).call(this),function(){}.call(this)

Haml ▸ HTML ▸ Coffeecup ▸ Javascript ▸ CoffeeScript Converter!

none of the links found under your README.md for tools > html 2 coffeecup converters were working for me.

what i really wanted was an online tool i could bookmark and run in my browser. something that would translate haml to coffeecup (moving from rails to node).

so i made this:

http://haml-html-coffeecup-javascript-coffeescript-converter.smullindesign.com/

or, if above doesn't work:

http://mikesmullin.github.com/haml-html-coffeecup-javascript-coffeescript-converter/

since it is hosted by github it shouldn't go down and its easy to fork mirrors.

you may wish to update your readme.md with this all-in-one tool.

Attribute content should auto-escape

I could be wrong about this, but I can't think of any situation where a person would not want to escape what goes into an HTML attribute.

Doing, for instance, span 'data-equation': 'x<22', "x is less than 22" leads to HTML of dubious validity (but it will probably still render properly).

Trying span 'data-outcome': 'She said "yes"', "He asked if she wanted to" will render as <span data-outcome="She said "yes"">He asked if she wanted to</span>, which is definitely invalid. So when there is arbitrary data going into an attribute I have to add the h() helper around the value every time, which is not so neat.

I'd say this should go for attribute names and the ID and class values too, even though the characters which would be escaped are likely not ever valid in attribute, ID and class names. Better to throw warnings or end up with invalid ID/class names than to end up with invalid HTML.

Even if you don't agree that they should always be escaped (I suppose if you happen to have the strings in already-escaped format you might not want to), it should at least be an option.

Express 3.1: TypeError: Cannot read property '0' of undefined

node 0.8.20
express 3.1.0
coffeecup 0.3.19
All install from npm.

cd node_modules/coffeecup/examples/express/
coffee app.coffee

When trying to open http://localhost:3000/ error appears:

TypeError: Cannot read property '0' of undefined
at new View (/home/neos/node_modules/express/lib/view.js:41:65)
at Function.app.render (/home/neos/node_modules/express/lib/application.js:486:12)
at ServerResponse.res.render (/home/neos/node_modules/express/lib/response.js:753:7)
at app.get.res.render.foo (/home/neos/node_modules/coffeecup/examples/express/app.coffee:11:16)
at callbacks (/home/neos/node_modules/express/lib/router/index.js:161:37)
at param (/home/neos/node_modules/express/lib/router/index.js:135:11)
at pass (/home/neos/node_modules/express/lib/router/index.js:142:5)
at Router._dispatch (/home/neos/node_modules/express/lib/router/index.js:170:5)
at Object.router (/home/neos/node_modules/express/lib/router/index.js:33:10)
at next (/home/neos/node_modules/express/node_modules/connect/lib/proto.js:199:15)

update to coffeescript 1.3.1

currently locked to coffeescript v1.2.0 in package.json
b/c 1.3.1 breaks the build
We need to be able to upgrade to 1.3.1

Jade-like block inheritance?

I really like the idea of block-style inheritance.

https://github.com/visionmedia/jade#a6-7

Given that Express v3 is doing away with layouts, these block styles could really work well in a lot of cases. Especially when you're doing a blog... you could append to a posts block, and the permalink container could pick its own layout.

Is this something you'd want to see in Coffeecup? Does it feel "pure"? If so, I might give a crack at putting something together.

Any equivalence to Dust's @sep-arator concept?

Dust.js (at least LinkedIn's version) has a useful {@sep} capability to denote what "separator" should be used when generating list entries. It's akin to the "join" operator for an array.

Dust:  {#links}<a href='/nodes/{href}'>{name}</a>{@sep}, {/sep}{/links}

I can't quite figure out the best way to do this in coffeecup. It's easy to generate a list of links:

a href:link.href, link.name for link in links

but producing them as a comma-separated list is more problematic.

Since coffeecup is "generating" results to a special buffer rather than "returning" results to coffeescript, I can't use a normal "join" operator.

I'm hoping there's a nifty mechanism to do this without resorting to index counting and emitting a text ', ' for all-but-the-last list item.

Any solutions to this? Can I encapsulate this sort of functionality in a helper somehow? Am I overlooking something trivial?

Testing

I would like to switch the tests to mocha and a bit better test coverage.

Express 3.1: ReferenceError: partial is not defined

node 0.8.20
express 3.1.0 (from npm)
coffeecup 0.3.19 (from github)

cd node_modules/coffeecup/examples/express/
coffee app.coffee

When trying to open http://localhost:3000/ error appears:

ReferenceError: partial is not defined
at Object.eval (eval at (/home/neos/node_modules/coffeecup/lib/coffeecup.js:410:10))
at eval (eval at (/home/neos/node_modules/coffeecup/lib/coffeecup.js:410:10))
at coffeecup.__express.render (/home/neos/node_modules/coffeecup/lib/coffeecup.js:458:25)
at coffeecup.__express (/home/neos/node_modules/coffeecup/lib/coffeecup.js:479:16)
at fs.readFile (fs.js:176:14)
at Object.oncomplete (fs.js:297:15)

Examples "/login" and "/inline" work fine.

Method of compiling template that references Javascript library to HTML?

If this is my template:

Foo =
 bar: 'Hi'
text Foo.bar

compiling to HTML works fine:

me$ coffeecup test.coffee
me$ cat test.html
Hi

But if I reference a Javascript library:

class Foo extends Backbone.Model
  @bar: 'Hi'
text Foo.bar

I get:

undefined:283
})(Backbone.Model);
   ^
ReferenceError: Backbone is not defined

Is there a way of doing this already that I am not aware of? Thanks!

Error compiling switch statement

I get the following error when compiling the example template, looks like the 'switch' reserved word being declared as variable. Here's a snipped from the example:

$ cat t2.coffee
switch @user.role
  when 'owner', 'admin'
    li -> a href: '/admin', -> 'Secret Stuff'

$ ./bin/coffeecup t2.coffee

undefined:2
var a,i,li,ol,s,th,u,hr,switch,use;a = function(){return __cc.tag('a', argumen
                        ^^^^^^
SyntaxError: Unexpected token switch
    at Object.Function (unknown source)
    at Object.compile (/home/srackham/projects/coffeecup.git/lib/coffeecup.js:333:10)
    at Object.render (/home/srackham/projects/coffeecup.git/lib/coffeecup.js:354:21)
    at /home/srackham/projects/coffeecup.git/lib/cli.js:28:26
    at [object Object].<anonymous> (fs.js:123:5)
    at [object Object].emit (events.js:64:17)
    at Object.oncomplete (fs.js:1181:12)

$

Express 3.x support

Express 3 expects a member called __express with a profile (path, options, callback) where the callback has a profile of (err,str) (reference).

This could be for example (modeled after coffeecup.render and consolidate.js):

coffeecup.__express = (path, options = {}, fn) ->
  if not window?
    options.stylus = require 'stylus'

  if options.cache and cache[path]?
    tpl = cache[path]
    fn null, tpl(options)
  else
    fs.readFile path, 'utf8', (err, str) ->
      if err then return fn err
      tpl = coffeecup.compile(str,options);
      if options.cache then cache[path] = tpl
      fn null, tpl(options)

This would be helpful in zappajs where we use coffeecup as the default engine.

Some related questions (feel free to move to separate issue): I'm not sure what to do wrt coffeecup.adapter.express, which is also use by zappa (zappa might be the only user for that feature?). Since not everyone is using Express 3.x yet it makes sense to keep it for now. However I'm curious whether there's a special reason partial is only available there (and not in generic CoffeeCup). Finally the TemplateError bits could be added to the __express function and use the err parameter of the callback, in Express 3.x.

explicit require of coffee-script

In order to use the new coffeecup module in flatiron, I had to first require 'coffee-script'

require 'coffee-script'
ccup = require 'coffeecup'

The old coffeekup would implicitly require coffee-script

ccup = require 'coffeekup'

Markdown support

So Coffee[KC]up is amazing, the one thing I miss from Jade is Markdown support.

I tried just including it as a helper function but haven't had much luck. Any thoughts on how to make that work?

option value: '' throws out value

this was an issue with the old coffeekup, does it still apply?

Doing

option value: '', 'title'

creates

<option>title</option>

instead of

<option value="">title</option>

is there a way to set a blank string as a value?

Options clobber Data? ( should be separate )

coffeecup.render = (template, data = {}, options = {}) ->
data[k] = v for k, v of options
data.cache ?= off
data.stylus = require 'stylus'

These first 3 lines of "render" start brutally clobbering the "data" object by injecting the options right into the data!
This means you can never use data attributes named any of the following:
"hardcode"
"optimize"
"locals"
"cache"
"stylus"

Options should be kept separate from Data, so that there are no secret "forbidden" attribute names!

Text is not escaped

Using coffeekup the following is outputted in escaped format:

h1 "<foo>" # Correctly outputs as <h1>&lt;foo&gt;</h1>

not so with coffeecup.

Underlined space follows a link in formatted mode

To reproduce:

$ cat test.coffee
a href: '', -> 'link'
text 'after'
$ coffeecup -f test.coffee && cat test.html
<a href="">
  link
</a>
after
$ open test.html

Perhaps there should be a formatting exception for text within <a> so that it gives:

<a href="">link</a>
after

However, this still leaves the problem that it adds a space between link and after. I don't think using the -f option should change how the page looks - just how the HTML looks.

Cannot find module 'optparse'

Need to make the coffeecup bin work without the following error unless optparse is installed globally.

$ coffeecup -h

Error: Cannot find module 'optparse'
at Function._resolveFilename (module.js:332:11)
at Function._load (module.js:279:25)
at Module.require (module.js:354:17)
at require (module.js:370:17)
at Object. (/usr/local/lib/node_modules/coffeecup/bin/coffeecup:12:18)
at Object. (/usr/local/lib/node_modules/coffeecup/bin/coffeecup:110:4)
at Module._compile (module.js:441:26)
at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script/coffee-script.js:68:25)
at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:135:29
at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/command.js:110:18

Falsy values for attributes are skipped

This template

select ->
  for i in [0..2]
    option value: i

compiles to

<select>
  <option></option>
  <option value="1"></option>
  <option value="2"></option>
</select>

Notice missing value="0".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.