Skip to content

Add example output after the code examples #82

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

Merged
merged 2 commits into from
Nov 18, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion md-render/HHVM/UserDocumentation/IncludeExamplesFilter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,49 @@ def call
File.read(full_path),
language: 'Hack',
);
node.replace(code)
code_node = node.replace(code)
# If the example has HHVM output associated with it, then print it
# after the code example. However, if both a .example.hhvm.out and
# .hhvm.expect exist, that is an error
output_header = doc.document.create_element(
'em',
"Output",
);
if (File.exists? (full_path + ".hhvm.expect")) ^ (File.exists? (full_path + ".example.hhvm.out"))
if File.exists? (full_path + ".hhvm.expect")
output_path = full_path + ".hhvm.expect"
else
output_path = full_path + ".example.hhvm.out"
end
output = doc.document.create_element(
'pre',
File.read(output_path),
language: 'Text',
);
code_node.after(output).after(output_header)
elsif (File.exists? (full_path + ".hhvm.expect")) && (File.exists? (full_path + ".example.hhvm.out"))
text = "Both .hhvm.expect and .example.hhvm.out exist. Remove one: #{full_path}"
STDERR.write(
text.red.bold + "\n"
)
warning = doc.document.create_element(
'h1',
text,
style: 'color: red',
)
code_node.after(warning).after(output_header)
elsif File.exists? (full_path + ".hhconfig") # We have some include .php files that we don't want output for. Files that are test run have a .hhconfig
text = "Neither .hhvm.expect or .example.hhvm.out exist. Add one: #{full_path}"
STDERR.write(
text.red.bold + "\n"
)
warning = doc.document.create_element(
'h1',
text,
style: 'color: red',
)
code_node.after(warning).after(output_header)
end
end
doc
end
Expand Down