paiq / blackcoffee

CoffeeScript + hygienic macros
MIT License
105 stars 9 forks source link

macros - simple replace the macro with the code specified #18

Closed cooolbasha closed 9 years ago

cooolbasha commented 10 years ago

I am trying to write simple macros where you defined some lines of code that is in across different module as a macro. so that the coffeescript will just paste the exact code (nice to have arguments,dynamic)..I would expect that to be simple ..but the documentation looks complex..atleast for the ones without argument it should be simple...am i missing something...

macro mymacro  = """
req.session.data = 'success'
req.session.name = 'test'
"""

so that I can use the macro mymacro somewhere else..with the code just getting replaced...for eg specifying the following code would just replace...

macro mymacro
vanviegen commented 9 years ago

Here's two ways to do it: (I'd prefer the second one)

macro test -> macro.csToNode """ 
    req.session.data = 'success'
    req.session.name = 'test'
    """
test()

macro test2 -> macro.codeToNode ->
    req.session.data = 'success'
    req.session.name = 'test'
test2()