8000 Run bbmustache from command line · Issue #46 · soranoba/bbmustache · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Run bbmustache from command line #46

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

Closed
rjcoelho opened this issue Apr 28, 2020 · 4 comments
Closed

Run bbmustache from command line #46

rjcoelho opened this issue Apr 28, 2020 · 4 comments

Comments

@rjcoelho
Copy link

I need to instantiate templates in files using erlang terms (also in other files).

I can open a PR with Main func on bbmustache and then we rebar3 escriptalise it (same as we do for other erlang tools like elvis or rebar3).

Does it make sense ?
Thanks

@soranoba
Copy link
Owner

ummm....
I couldn't imagine a scene where bbmustache became escript and would be useful, because I think erlang term is very difficult to pass from the command line.
The reason is the handling of single quotes and double quotes is different. 😓

bbmustache works like other mustache libraries, so mo is probably more convenient than bbmustache in this case.

Alternatively, it makes sense to create a thin escript on demand (I do this a lot).
For example, it looks like this.

$ cat <<EOF > make_cnf.escript
#!/usr/bin/env escript
%%! -pa _build/default/lib/bbmustache/ebin

main(_) ->
    Ret = bbmustache:render(<<"{{hoge}}">>, [{"hoge", 1}]),
    io:format("~p~n", [Ret]).

EOF
$ chmod +x make_cnf.escript 
$ ./make_cnf.escript 
<<"1">>

By the way, benchmark results are created by escript.
script: https://github.com/soranoba/bbmustache/blob/636815b64aecd34e3fd53e1b10d6769c6ee575d6/benchmarks/bench.escript
result: https://github.com/soranoba/bbmustache/tree/master/benchmarks

@rjcoelho
Copy link
Author
rjcoelho commented Apr 28, 2020

Both template and the erlang terms are in files. My case is I use overlay vargs I want to use to replace on template files. Eg:

#!/usr/bin/env escript
%%! -pa _build/default/lib/bbmustache/ebin

main(_) ->
    {ok, Data} = file:consult("vars.config"),
    {ok, Template}  = file:read_file("file.template)
    Ret = bbmustache:render(Template, Data),
    io:format("~p~n", [Ret]).

@soranoba
Copy link
Owner

oh, I see. it sounds good.
I welcome PR.

@soranoba
Copy link
Owner

Solved by #48

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

No branches or pull requests

2 participants
0