Skip to content

Commit

Permalink
Merge pull request #119 from softmoth/json-newline
Browse files Browse the repository at this point in the history
Pretty print JSON files, and terminate with newline
  • Loading branch information
Danappelxx authored Mar 31, 2021
2 parents e349314 + 1d59723 commit 86fe766
Show file tree
Hide file tree
Showing 8 changed files with 1,463 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace :build do
File.open(json_file, 'w') do |file|
warning = {:__ATTN__ => note}
doc = YAML.load_file(filename)
file << warning.merge(doc).to_json()
file << JSON.pretty_generate(warning.merge(doc)) << "\n"
end
end
end
Expand Down
95 changes: 94 additions & 1 deletion specs/comments.json
Original file line number Diff line number Diff line change
@@ -1 +1,94 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Inline","desc":"Comment blocks should be removed from the template.","data":{},"template":"12345{{! Comment Block! }}67890","expected":"1234567890"},{"name":"Multiline","desc":"Multiline comments should be permitted.","data":{},"template":"12345{{!\n This is a\n multi-line comment...\n}}67890\n","expected":"1234567890\n"},{"name":"Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n{{! Comment Block! }}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n {{! Indented Comment Block! }}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Standalone Line Endings","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","data":{},"template":"|\r\n{{! Standalone Comment }}\r\n|","expected":"|\r\n|"},{"name":"Standalone Without Previous Line","desc":"Standalone tags should not require a newline to precede them.","data":{},"template":" {{! I'm Still Standalone }}\n!","expected":"!"},{"name":"Standalone Without Newline","desc":"Standalone tags should not require a newline to follow them.","data":{},"template":"!\n {{! I'm Still Standalone }}","expected":"!\n"},{"name":"Multiline Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Multiline Standalone","desc":"All standalone comment lines should be removed.","data":{},"template":"Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Inline","desc":"Inline comments should not strip whitespace","data":{},"template":" 12 {{! 34 }}\n","expected":" 12 \n"},{"name":"Surrounding Whitespace","desc":"Comment removal should preserve surrounding whitespace.","data":{},"template":"12345 {{! Comment Block! }} 67890","expected":"12345 67890"}]}
{
"__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
"overview": "Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n",
"tests": [
{
"name": "Inline",
"desc": "Comment blocks should be removed from the template.",
"data": {
},
"template": "12345{{! Comment Block! }}67890",
"expected": "1234567890"
},
{
"name": "Multiline",
"desc": "Multiline comments should be permitted.",
"data": {
},
"template": "12345{{!\n This is a\n multi-line comment...\n}}67890\n",
"expected": "1234567890\n"
},
{
"name": "Standalone",
"desc": "All standalone comment lines should be removed.",
"data": {
},
"template": "Begin.\n{{! Comment Block! }}\nEnd.\n",
"expected": "Begin.\nEnd.\n"
},
{
"name": "Indented Standalone",
"desc": "All standalone comment lines should be removed.",
"data": {
},
"template": "Begin.\n {{! Indented Comment Block! }}\nEnd.\n",
"expected": "Begin.\nEnd.\n"
},
{
"name": "Standalone Line Endings",
"desc": "\"\\r\\n\" should be considered a newline for standalone tags.",
"data": {
},
"template": "|\r\n{{! Standalone Comment }}\r\n|",
"expected": "|\r\n|"
},
{
"name": "Standalone Without Previous Line",
"desc": "Standalone tags should not require a newline to precede them.",
"data": {
},
"template": " {{! I'm Still Standalone }}\n!",
"expected": "!"
},
{
"name": "Standalone Without Newline",
"desc": "Standalone tags should not require a newline to follow them.",
"data": {
},
"template": "!\n {{! I'm Still Standalone }}",
"expected": "!\n"
},
{
"name": "Multiline Standalone",
"desc": "All standalone comment lines should be removed.",
"data": {
},
"template": "Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n",
"expected": "Begin.\nEnd.\n"
},
{
"name": "Indented Multiline Standalone",
"desc": "All standalone comment lines should be removed.",
"data": {
},
"template": "Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n",
"expected": "Begin.\nEnd.\n"
},
{
"name": "Indented Inline",
"desc": "Inline comments should not strip whitespace",
"data": {
},
"template": " 12 {{! 34 }}\n",
"expected": " 12 \n"
},
{
"name": "Surrounding Whitespace",
"desc": "Comment removal should preserve surrounding whitespace.",
"data": {
},
"template": "12345 {{! Comment Block! }} 67890",
"expected": "12345 67890"
}
]
}
133 changes: 132 additions & 1 deletion specs/delimiters.json
Original file line number Diff line number Diff line change
@@ -1 +1,132 @@
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Pair Behavior","desc":"The equals sign (used on both sides) should permit delimiter changes.","data":{"text":"Hey!"},"template":"{{=<% %>=}}(<%text%>)","expected":"(Hey!)"},{"name":"Special Characters","desc":"Characters with special meaning regexen should be valid delimiters.","data":{"text":"It worked!"},"template":"({{=[ ]=}}[text])","expected":"(It worked!)"},{"name":"Sections","desc":"Delimiters set outside sections should persist.","data":{"section":true,"data":"I got interpolated."},"template":"[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n","expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"},{"name":"Inverted Sections","desc":"Delimiters set outside inverted sections should persist.","data":{"section":false,"data":"I got interpolated."},"template":"[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n","expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"},{"name":"Partial Inheritence","desc":"Delimiters set in a parent template should not affect a partial.","data":{"value":"yes"},"partials":{"include":".{{value}}."},"template":"[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n","expected":"[ .yes. ]\n[ .yes. ]\n"},{"name":"Post-Partial Behavior","desc":"Delimiters set in a partial should not affect the parent template.","data":{"value":"yes"},"partials":{"include":".{{value}}. {{= | | =}} .|value|."},"template":"[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n","expected":"[ .yes. .yes. ]\n[ .yes. .|value|. ]\n"},{"name":"Surrounding Whitespace","desc":"Surrounding whitespace should be left untouched.","data":{},"template":"| {{=@ @=}} |","expected":"| |"},{"name":"Outlying Whitespace (Inline)","desc":"Whitespace should be left untouched.","data":{},"template":" | {{=@ @=}}\n","expected":" | \n"},{"name":"Standalone Tag","desc":"Standalone lines should be removed from the template.","data":{},"template":"Begin.\n{{=@ @=}}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Indented Standalone Tag","desc":"Indented standalone lines should be removed from the template.","data":{},"template":"Begin.\n {{=@ @=}}\nEnd.\n","expected":"Begin.\nEnd.\n"},{"name":"Standalone Line Endings","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","data":{},"template":"|\r\n{{= @ @ =}}\r\n|","expected":"|\r\n|"},{"name":"Standalone Without Previous Line","desc":"Standalone tags should not require a newline to precede them.","data":{},"template":" {{=@ @=}}\n=","expected":"="},{"name":"Standalone Without Newline","desc":"Standalone tags should not require a newline to follow them.","data":{},"template":"=\n {{=@ @=}}","expected":"=\n"},{"name":"Pair with Padding","desc":"Superfluous in-tag whitespace should be ignored.","data":{},"template":"|{{= @ @ =}}|","expected":"||"}]}
{
"__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
"overview": "Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n",
"tests": [
{
"name": "Pair Behavior",
"desc": "The equals sign (used on both sides) should permit delimiter changes.",
"data": {
"text": "Hey!"
},
"template": "{{=<% %>=}}(<%text%>)",
"expected": "(Hey!)"
},
{
"name": "Special Characters",
"desc": "Characters with special meaning regexen should be valid delimiters.",
"data": {
"text": "It worked!"
},
"template": "({{=[ ]=}}[text])",
"expected": "(It worked!)"
},
{
"name": "Sections",
"desc": "Delimiters set outside sections should persist.",
"data": {
"section": true,
"data": "I got interpolated."
},
"template": "[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n",
"expected": "[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"
},
{
"name": "Inverted Sections",
"desc": "Delimiters set outside inverted sections should persist.",
"data": {
"section": false,
"data": "I got interpolated."
},
"template": "[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n",
"expected": "[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"
},
{
"name": "Partial Inheritence",
"desc": "Delimiters set in a parent template should not affect a partial.",
"data": {
"value": "yes"
},
"partials": {
"include": ".{{value}}."
},
"template": "[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n",
"expected": "[ .yes. ]\n[ .yes. ]\n"
},
{
"name": "Post-Partial Behavior",
"desc": "Delimiters set in a partial should not affect the parent template.",
"data": {
"value": "yes"
},
"partials": {
"include": ".{{value}}. {{= | | =}} .|value|."
},
"template": "[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n",
"expected": "[ .yes. .yes. ]\n[ .yes. .|value|. ]\n"
},
{
"name": "Surrounding Whitespace",
"desc": "Surrounding whitespace should be left untouched.",
"data": {
},
"template": "| {{=@ @=}} |",
"expected": "| |"
},
{
"name": "Outlying Whitespace (Inline)",
"desc": "Whitespace should be left untouched.",
"data": {
},
"template": " | {{=@ @=}}\n",
"expected": " | \n"
},
{
"name": "Standalone Tag",
"desc": "Standalone lines should be removed from the template.",
"data": {
},
"template": "Begin.\n{{=@ @=}}\nEnd.\n",
"expected": "Begin.\nEnd.\n"
},
{
"name": "Indented Standalone Tag",
"desc": "Indented standalone lines should be removed from the template.",
"data": {
},
"template": "Begin.\n {{=@ @=}}\nEnd.\n",
"expected": "Begin.\nEnd.\n"
},
{
"name": "Standalone Line Endings",
"desc": "\"\\r\\n\" should be considered a newline for standalone tags.",
"data": {
},
"template": "|\r\n{{= @ @ =}}\r\n|",
"expected": "|\r\n|"
},
{
"name": "Standalone Without Previous Line",
"desc": "Standalone tags should not require a newline to precede them.",
"data": {
},
"template": " {{=@ @=}}\n=",
"expected": "="
},
{
"name": "Standalone Without Newline",
"desc": "Standalone tags should not require a newline to follow them.",
"data": {
},
"template": "=\n {{=@ @=}}",
"expected": "=\n"
},
{
"name": "Pair with Padding",
"desc": "Superfluous in-tag whitespace should be ignored.",
"data": {
},
"template": "|{{= @ @ =}}|",
"expected": "||"
}
]
}
Loading

0 comments on commit 86fe766

Please sign in to comment.