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

Created command line tool #425

Merged
merged 1 commit into from
Feb 13, 2015
Merged

Created command line tool #425

merged 1 commit into from
Feb 13, 2015

Conversation

phillipj
Copy link
Collaborator

@phillipj phillipj commented Feb 9, 2015

Hey,

my first shot at a CLI used to render a mustache template with a data view and writes the template into stdout when successfull. Otherwise meaningfull errors into stderr.

The short story is it enables

$ mustache myTemplate.mustache dataView.json > output.html

Changes in the readme.md + tests pretty much sums it up.

Any thoughts?

@bobthecow
Copy link

I'd follow the ruby mustache argument order: mustache [data] [template]

(see mustache(1))

@bobthecow
Copy link

Also, we should allow users to specify - as the data or template argument, which would grab stdin.

cat data.json | mustache - myTemplate.mustache > out.html

@dasilvacontin
Copy link
Collaborator

Awesome! With @bobthecow's changes, I'd give 👍. Can't wait to have this, since I recently started toying with using package.json's scripts as my 'task-runner'.

@bobthecow
Copy link

While we're at it, how 'bout allowing an arbitrary number of datas? mustache <data> [<data> ...] <template>

@dasilvacontin
Copy link
Collaborator

@bobthecow, what would be the purpose of input? What's the expected output?

@bobthecow
Copy link

@dasilvacontin (Mustache.render(tpl, data) for data in datas).join("\n")

@dasilvacontin
Copy link
Collaborator

I see, interesting! Thumbs up incoming after the commits. :)

@phillipj
Copy link
Collaborator Author

Great feedback guys, thanks! I'll do some changes within the next couple of days :)

@phillipj phillipj force-pushed the feature/cli branch 2 times, most recently from eb92f0e to 028fe76 Compare February 11, 2015 08:43
CLI used to render a mustache template with a data view, writes the template into stdout when successfull. Otherwise meaningfull errors into stderr.

Fixes janl#424
@phillipj
Copy link
Collaborator Author

Has changed argument ordering and added support for stdin.

@phillipj
Copy link
Collaborator Author

@bobthecow multiple data views are interesting! Have you thought of scenarios where multiple data views would enable something one data view with an array as root could not?

E.g two views of:

{
    "message": "LeBron"
}
{
    "message": "r0x!"
}

compared to one view with:

[
    {
        "message": "LeBron"
    },
    {
        "message": "r0x!"
    }
]

@bobthecow
Copy link

I was thinking of a use case of a directory full of data files, and not having to preprocess them into a JSON array before using them. mustache messages/*.json message.mustache > messages.html

But I suppose you'd usually want to do more than newline delimited, so you're back to preprocessing.

@phillipj
Copy link
Collaborator Author

Played with that thought for a couple of minutes. Looks like it would be possible to push multiple single JSON objects into stdin reading them with the awesome JSONStream module.

$ cat messages/*.json | mustache - message.mustache > messages.html

Knowing its possible is good and all, but it doesnt really sound like you need it atm? If not lets do a PR on it later if/when someone actually needs it, I would happily contribute.

@bobthecow
Copy link

Don't hold anything up for my hypothetical feature. :shipit: :)

@bobthecow
Copy link

jsonstream is pretty cool. i've played with it a bit as well :)

phillipj added a commit that referenced this pull request Feb 13, 2015
@phillipj phillipj merged commit 05d7146 into janl:master Feb 13, 2015
@phillipj phillipj deleted the feature/cli branch February 13, 2015 17:25
@dasilvacontin
Copy link
Collaborator

Cool!

@bobthecow
Copy link

👍

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.

3 participants