On Sat, Jul 07, 2012 at 10:55:26AM -0300, Angel Java Lopez wrote:

> var st = require('simpletags');
> 
> st.html(st.head(st.title('...')), st.body(st.h1(....))
> 
> instead
> 
> html(head(title('....')), body(h1('...'))
> 
> in a controlled way (only in its own module). I want to give him/her an
> option. Ruby has it (as an option, too). It's the first time I found I
> needed it in Node.js. Usually, I assert "Ruby ceremony > Javascript/Node.js
> ceremony", but now, I was trapped by this issue.
> 
> My best solutions:
> 
> a)
> var st = require(...); // and use with st.h1, st.h2...
> 
> b)
> require('simpletags').exportsTo(global); // maybe in browser I could export
> to windows directly in the module
> 
> c)
> var simpletags = require('simpletags');
> eval(simpletags.exportLocalCode()); // where .exportLocalCode returns a
> String with "var h1 = simpletags.h1; ... "
> c2)
> var st = require('simpletags');
> eval(st.exportLocalCode('st')); // the local variable name 'st' should be
> informed to be used in var ...= .... string result

You can also do this:

    require('simpletags')(function (html, head, title, body, h1) {
      html(head(title('....')), body(h1('...'))
    });

I'm using function argument names to both request data from the context and
assign it to variables at once in a control flow library I'm building.

https://github.com/bigeasy/cadence

Using the function argument names for key names, I maintain state for a control
flow in a hash table. If one of the functions needs a value, they name it in
their argument declaration list.

Notice on line 12. `stat` is the return value of call to `fs.stat` while `file`,
and `shift` are pulled from the context for use in that particular step of the
control flow.

https://github.com/bigeasy/cadence/blob/master/deltree.js#L1-L18

It's a nice pattern. Works well.

It removes one level of annoyance. You don't need to assign each member of the
`simpletags` hash to a variable, but it isn't the full magic you're looking for,
where all of the variables magically appear.

--
Alan Gutierrez - http://github.com/bigeasy - http://twitter.com/bigeasy

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply via email to