Skip to content

Commit 8603d3a

Browse files
committed
Merge pull request #82 from hhvm/add-example-output
Add example output after the code examples
2 parents f73da60 + fc9ece6 commit 8603d3a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

md-render/HHVM/UserDocumentation/IncludeExamplesFilter.rb

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,49 @@ def call
5151
File.read(full_path),
5252
language: 'Hack',
5353
);
54-
node.replace(code)
54+
code_node = node.replace(code)
55+
# If the example has HHVM output associated with it, then print it
56+
# after the code example. However, if both a .example.hhvm.out and
57+
# .hhvm.expect exist, that is an error
58+
output_header = doc.document.create_element(
59+
'em',
60+
"Output",
61+
);
62+
if (File.exists? (full_path + ".hhvm.expect")) ^ (File.exists? (full_path + ".example.hhvm.out"))
63+
if File.exists? (full_path + ".hhvm.expect")
64+
output_path = full_path + ".hhvm.expect"
65+
else
66+
output_path = full_path + ".example.hhvm.out"
67+
end
68+
output = doc.document.create_element(
69+
'pre',
70+
File.read(output_path),
71+
language: 'Text',
72+
);
73+
code_node.after(output).after(output_header)
74+
elsif (File.exists? (full_path + ".hhvm.expect")) && (File.exists? (full_path + ".example.hhvm.out"))
75+
text = "Both .hhvm.expect and .example.hhvm.out exist. Remove one: #{full_path}"
76+
STDERR.write(
77+
text.red.bold + "\n"
78+
)
79+
warning = doc.document.create_element(
80+
'h1',
81+
text,
82+
style: 'color: red',
83+
)
84+
code_node.after(warning).after(output_header)
85+
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
86+
text = "Neither .hhvm.expect or .example.hhvm.out exist. Add one: #{full_path}"
87+
STDERR.write(
88+
text.red.bold + "\n"
89+
)
90+
warning = doc.document.create_element(
91+
'h1',
92+
text,
93+
style: 'color: red',
94+
)
95+
code_node.after(warning).after(output_header)
96+
end
5597
end
5698
doc
5799
end

0 commit comments

Comments
 (0)