-
Notifications
You must be signed in to change notification settings - Fork 427
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
Passing JSON object to ReLaXed: wiki needs to be updated! #175
Comments
Hey thanks for this, can you add this to the wiki? (not sure if you need us to give you some kind of write access or not) |
Yeah I think I need permission to do this. Might be restricted to collaborators only. Otherwise you can simply edit it. |
Thank you for sharing! Should add to wiki. |
Anyone can edit the wiki so please feel free to add the missing information. |
Hi @DanielRuf I don't believe anybody can edit the wiki. As @LanguageAgnostic notes, it is restricted to collaborators only. Let me know if this is a mistake and I would be happy to correct the wiki! :) |
There is a problem with passing variables to ReLaXed with the shown example. I propose a small change on the wiki. We could also discuss better solutions. 😄
Note: Passing a JSON file works fine.
Steps
Tested on Windows and Linux.
relaxed mydoc.pug --build-once --locals {"name": "Marc"}
2 Problems:
1st problem
We would get an error like this:
Because of it, no data is passed to our file.
2nd problem
A file named
Marc}
is created instead ofmydoc.pdf
. This is a simple syntax fix, see below.Fixes
First, simply add quotes around the JSON object to get the right output file name. Now the reason behind the JSON parsing error is how the data is given through Commander.js.
With our example, it looks like this:
{name:Marc}
The latter is not a valid JSON object (missing quotes on keys) and would be of wrong type if the value was a string, which is the case here. The input style is also the case for other CLI tools like Caporal.js and Yargs.js since they are also subject to the Strong Quoting's principle.
The solution proposed is to simply to escape quotes. This is how the JSON object has to be passed:
So on the wiki, the command should be:
Trick
A neat trick to obtain the result is to stringify twice the JSON object before passing it as a parameter to ReLaXed:
The text was updated successfully, but these errors were encountered: