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

Alternatively accept _data.js for metadata instead of plain JSON? #103

Closed
sgoumaz opened this issue Oct 2, 2013 · 3 comments
Closed

Alternatively accept _data.js for metadata instead of plain JSON? #103

sgoumaz opened this issue Oct 2, 2013 · 3 comments
Assignees

Comments

@sgoumaz
Copy link

sgoumaz commented Oct 2, 2013

Our problem is, we need to make data in external JSON files (originating from elsewhere) available to Jade templates. (A reasonable use case I think.)

Right now it doesn't look possible within Harp (I would probably write a "pre-Harp" build step generating the ad-hoc _data.json files). The best way I see would be that we can optionally replace the _data.json with a _data.js, in which we'd load the external files with require() (and more generally do any simple preprocessing we need). Would that fit? If yes I'll be happy to submit the simple PR, if not alternative suggestions are welcome.

@ghost ghost assigned sintaxi Oct 2, 2013
@sintaxi
Copy link
Owner

sintaxi commented Oct 2, 2013

Our problem is, we need to make data in external JSON files (originating from elsewhere) available to Jade templates. (A reasonable use case I think.)

yep, makes sense. (and agreed)

Right now it doesn't look possible within Harp (I would probably write a "pre-Harp" build step generating the ad-hoc _data.json files). The best way I see would be that we can optionally replace the _data.json with a _data.js, in which we'd load the external files with require() (and more generally do any simple preprocessing we need). Would that fit? If yes I'll be happy to submit the simple PR, if not alternative suggestions are welcome.

I think what you are wanting to do is possible by using harp as a library IN you pre-compile script. LIke so...

note If you put your script in the base of your app I would suggest making sure you are running in "framework mode" meaning you have a harp.json and a public directory.

yourproject/compile.js

var harp = require('harp')

harp.compile(__dirname, function(err){
  if(err) console.log(err)

  console.log("All Done!")
})

Then you would build it by running node compile instead of harp compile.
If you are looking for a more integrated experience then I'm open to exploring some APIs to address this use case. I think the _data.js concept is a pretty interesting idea though I think a narrow API is what is appropriate to keep it really simple and leave the edge cases to using harp as a lib (like above).

We put our APIs through a lot of scrutiny so I wouldn't likely take a pull request that has an API that hasn't been put through its paces but we could start with a gist and go from there.

@sgoumaz
Copy link
Author

sgoumaz commented Oct 2, 2013

Thanks for the quick & detailed response. I've seen that JSON-or-JS config pattern used elsewhere too (no ref I remember now sorry) and it's definitely easier in this case than using harp as a lib, so we'll be very glad if you consider it. Issue added to terraform (with gist): sintaxi/terraform#8.

@barraq
Copy link

barraq commented Mar 10, 2016

👍

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

No branches or pull requests

4 participants