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

tpl/transform: Add template func for TOML/JSON/YAML docs examples conversion #4395

Merged
merged 1 commit into from
Feb 10, 2018

Conversation

bep
Copy link
Member

@bep bep commented Feb 9, 2018

Usage:

{{ "title = \"Hello World\"" | transform.Remarshal "json" | safeHTML }}

Fixes #4389

/cc @regisphilibert

@bep bep changed the title tpl/transform: Add template for TOML/JSON/YAML docs examples conversion tpl/transform: Add template func for TOML/JSON/YAML docs examples conversion Feb 9, 2018
@moorereason
Copy link
Contributor

Serlify? Where did you come up with that? 😆

@bep
Copy link
Member Author

bep commented Feb 9, 2018

Serlify? Where did you come up with that?

Here.

@bep
Copy link
Member Author

bep commented Feb 9, 2018

Seriously, I welcome better suggestions (however I suspect this will be a classic. So TOML, JSON etc. are data serialization formats ... serlify). But this func is kind of a special purpose "Hugo docs func", but I guess others will pick up on it ...


// Serlify is used in the Hugo documentation to convert configuration
// examples from YAML to JSON, TOML (and possibly the other way around).
// The is primary a helper for the Hugo docs site which is why it got this stupid name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is primarily"

// Serlify is used in the Hugo documentation to convert configuration
// examples from YAML to JSON, TOML (and possibly the other way around).
// The is primary a helper for the Hugo docs site which is why it got this stupid name.
// It is not general purpose YAML to TOML converter etc., and may
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"not a"

@bep
Copy link
Member Author

bep commented Feb 9, 2018

@regisphilibert I will merge this into master some time during this weekend. It should work, but I want to test it a little. There may be some date issues that could be improved. Not sure.

@regisphilibert
Copy link
Member

regisphilibert commented Feb 9, 2018

@bep Sure I'll try it once it's on master and will go back to the hugoDocs repo to add the toggling config shortcode issue where we'll talk more about front end.

Thanks a ton! You were super fast with this.

@bep
Copy link
Member Author

bep commented Feb 9, 2018

Thanks a ton! You were super fast with this.

Yes, I have been annoyed by the "example situation" for a long time -- and if someone wants to do something about it, I will try to keep that momentum going ...

@kaushalmodi
Copy link
Contributor

How about serialize, or remarshal (there's even a GitHub repo named that, that does exactly this - TOML/YAML/JSON conversion)?

@bep
Copy link
Member Author

bep commented Feb 10, 2018

How about serialize, or remarshal

"remarshal" I kind of like, but ...

@regisphilibert
Copy link
Member

regisphilibert commented Feb 10, 2018

I like that it ends with ...fy. Reminds of jsonify which everybody knows.

@kaushalmodi
Copy link
Contributor

My take is that in jsonify, removing "ify", the "json" part makes sense, and similarly "markdown" + "ify" = markdownify. The same logic doesn't work here.. "serl" doesn't mean anything. If sticking to "-ify" is the aim, then may be.. serialify.

But then the question is.. is this process technically serialization/marshalling?

JSON, or TOML, or YAML, each of those is already marshalled, or converted from raw data into some sort of format, a spec, an object.

If we are converting among these formats, something like remarshall, reformat, transform (though, the library is also called the same) sounds more correct.

@vassudanagunta
Copy link
Contributor

Add template func for TOML/JSON/YAML docs examples conversion

that does exactly this - TOML/YAML/JSON conversion)?

If we are converting

hint hint

@vassudanagunta
Copy link
Contributor

vassudanagunta commented Feb 10, 2018

Or if the package name will always be present:

{`{{ "title = \"Hello World\"" | transform.to "json" | safeHTML }}`, "{\n   \"title\": \"Hello World\"\n}\n"},

Or even:

{`{{ "title = \"Hello World\"" | transform.toJSON | safeHTML }}`, "{\n   \"title\": \"Hello World\"\n}\n"},

{`{{ "title = \"Hello World\"" | transform.toYAML | safeHTML }}`, "{\n   \"title\": \"Hello World\"\n}\n"},

{`{{ "title = \"Hello World\"" | transform.toTOML | safeHTML }}`, "{\n   \"title\": \"Hello World\"\n}\n"},

The latter works even if the package name is optional:

{`{{ "title = \"Hello World\"" | toJSON | safeHTML }}`, "{\n   \"title\": \"Hello World\"\n}\n"},

@bep
Copy link
Member Author

bep commented Feb 10, 2018

@vassudanagunta thanks, but it needs to be one method so it can be (easy to) dynamically invoked.

@bep
Copy link
Member Author

bep commented Feb 10, 2018

And the winner is @kaushalmodi

{{ "title = \"Hello World\"" | transform.Remarshal "json" | safeHTML }}

…version

Usage:

```html
{{ "title = \"Hello World\"" | transform.Remarshal "json" | safeHTML }}
```

Fixes gohugoio#4389
@bep bep merged commit d382502 into gohugoio:master Feb 10, 2018
@github-actions
Copy link

github-actions bot commented Feb 7, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a function to convert toTOML/toYAML/toJSON
5 participants