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

Implement 'tojson' filter #142

Closed
flexferrum opened this issue Sep 25, 2019 · 2 comments
Closed

Implement 'tojson' filter #142

flexferrum opened this issue Sep 25, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request hacktoberfest Issues for Hacktoberfest

Comments

@flexferrum
Copy link
Collaborator

flexferrum commented Sep 25, 2019

Implement 'tojson' filter according to the jinja2 specification:

Dumps a structure to JSON so that it’s safe to use in <script> tags. It accepts the same arguments and returns a JSON string. Note that this is available in templates through the |tojson filter which will also mark the result as safe. Due to how this function escapes certain characters this is safe even if used outside of <script> tags.

The following characters are escaped in strings:

  • <
  • >
  • &
  • '

This makes it safe to embed such strings in any place in HTML with the notable exception of double quoted attributes. In that case single quote your attributes or HTML escape it in addition.

The indent parameter can be used to enable pretty printing. Set it to the number of spaces that the structures should be indented with.

@flexferrum flexferrum added enhancement New feature or request hacktoberfest Issues for Hacktoberfest labels Sep 25, 2019
@vvish
Copy link

vvish commented Sep 26, 2019

Hi! Could you please assign the task on me?

@flexferrum
Copy link
Collaborator Author

Sure!

vvish pushed a commit to vvish/Jinja2Cpp that referenced this issue Oct 12, 2019
* Implemented serialization to json based or rapidjson framework.

* Added initial filter implementation + tests.
vvish pushed a commit to vvish/Jinja2Cpp that referenced this issue Oct 16, 2019
* Implemented serialization to json based or rapidjson framework.

* Added initial filter implementation + tests.

* Entry added to the list of supported filters in README.
vvish pushed a commit to vvish/Jinja2Cpp that referenced this issue Oct 16, 2019
* Implemented serialization to json based or rapidjson framework.

* Added initial filter implementation + tests.

* Entry added to the list of supported filters in README.
vvish pushed a commit to vvish/Jinja2Cpp that referenced this issue Oct 21, 2019
vvish pushed a commit to vvish/Jinja2Cpp that referenced this issue Oct 21, 2019
vvish pushed a commit to vvish/Jinja2Cpp that referenced this issue Oct 22, 2019
flexferrum pushed a commit that referenced this issue Oct 22, 2019
* Added initial implementation for tojson filter (#142)

* Implemented serialization to json based or rapidjson framework.

* Added initial filter implementation + tests.

* Entry added to the list of supported filters in README.

* Add rapidjson as a thirdparty library

* Encoding for Json serialization changed to UTF8 (#142)

* Unit-tests for 'tojson' filter fixed to be implementation/platform independant (#142)

* Fix integration with RapidJSON library

* Tests for rapidjson based serializer fixed to be platform independent (#142)

* Minor style corrections in the 'tojson' filter tests (#142)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest Issues for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

2 participants