Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Marko v3: macros #170

Closed
patrick-steele-idem opened this Issue Dec 8, 2015 · 0 comments

Comments

Projects
None yet
1 participant
@patrick-steele-idem
Copy link
Contributor

patrick-steele-idem commented Dec 8, 2015

New syntax

Simple macro (no body)

<macro greeting(name, age)>
  Hello ${name}! You are ${age} years old.
</macro>

<greeting name="Frank" age=30/>
<greeting('Frank', 30)/>

Macro that allows nested body content

<macro section-heading(className)>
  <h1 class=className>
    <macro-body/>
  </h1>
</macro>

<section-heading className="foo">
  Hello World!
</section-heading>

<!-- Output: -->
<h1 class="foo">Hello World!</h1>

Alternate syntax for accessing the raw renderBody(out) function:

<macro section-heading(className, renderBody) body-param=renderBody>
  <h1 class=className>
    <invoke renderBody(out) if(renderBody)/>
  </h1>
</macro>

<section-heading className="foo">
  Hello World!
</section-heading>

<!-- Output: -->
<h1 class="foo">Hello World!</h1>

Old syntax

<def function="greeting(name, age)">
  Hello ${name}! You are ${age} years old.
</def>

<def function="greeting(name, count)">
    Hello ${name}! You have ${count} new messages.
</def>

<invoke function="greeting" name="John" count="${10}"/>
<invoke function="greeting('Frank', 20)"/>

Notes

  • Macros should be invoked with an implicit out argument.
  • Macros should not be allowed to used as JavaScript functions and should be given a unique name at compile time (e.g. greeting --> __greeting(out, name, age))

@patrick-steele-idem patrick-steele-idem modified the milestone: 3.0 Dec 22, 2015

@patrick-steele-idem patrick-steele-idem self-assigned this Jan 4, 2016

patrick-steele-idem added a commit that referenced this issue Jan 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.