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

Macro support #381

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Macro support #381

wants to merge 4 commits into from

Conversation

mmarcon
Copy link

@mmarcon mmarcon commented Nov 13, 2014

This pull request introduces the concept of macro (maybe it can be named something more meaningful).

Applications built with harp can include a _macros folder in the project root and add node.js modules into this folder. Functions and objects exported by modules will be available in the global scope and accessible from templates as

<%- macros.someFunction() %>

This helps keeping code/logic out of templates and avoid code like http://harpjs.com/recipes/blog-sitemap.

It opens up harp to lots of freedom for more expert developers who want a more customized harp experience.

var loadMacros = function(projectPath) {
var macros = {}
var macroDir = path.join(projectPath, "_macros/")
if (!fs.existsSync(macroDir)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not look if it exists, you should just try to read it and then catch the error there, now your are essential reading the dir twice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to avoid try/catch based programming, but I understand your point about performance. I can change that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants