cleanup, docs
This commit is contained in:
@@ -45,6 +45,57 @@ void render_doc_params(StringList param_lines)
|
||||
?></div></>
|
||||
}
|
||||
|
||||
String doc_example_path(String page, u64 idx)
|
||||
{
|
||||
return("examples/_gen/" + page + "_" + std::to_string(idx + 1) + ".uce");
|
||||
}
|
||||
|
||||
String doc_example_unit_source(String body)
|
||||
{
|
||||
return("RENDER(Request& context)\n{\n" + body + "\n}\n");
|
||||
}
|
||||
|
||||
bool doc_write_if_changed(String path, String content)
|
||||
{
|
||||
if(file_exists(path) && file_get_contents(path) == content)
|
||||
return(true);
|
||||
return(file_put_contents(path, content));
|
||||
}
|
||||
|
||||
String doc_render_example_output(String page, u64 idx, String body)
|
||||
{
|
||||
String path = doc_example_path(page, idx);
|
||||
String unit_source = doc_example_unit_source(body);
|
||||
if(!doc_write_if_changed(path, unit_source))
|
||||
return("DOC EXAMPLE ERROR: could not write " + path);
|
||||
if(!unit_compile(path))
|
||||
return("DOC EXAMPLE ERROR: unit_compile failed for " + path);
|
||||
|
||||
ob_start();
|
||||
unit_render(path);
|
||||
String out = ob_get_close();
|
||||
if(out == "")
|
||||
return("DOC EXAMPLE ERROR: example produced no output");
|
||||
return(out);
|
||||
}
|
||||
|
||||
void render_doc_examples(String page, StringList example_blocks)
|
||||
{
|
||||
for(u64 idx = 0; idx < example_blocks.size(); idx++)
|
||||
{
|
||||
String body = example_blocks[idx];
|
||||
String output = doc_render_example_output(page, idx, body);
|
||||
?><div class="doc-section example">
|
||||
<h3>Example</h3>
|
||||
<pre class="example-source"><?= body ?></pre>
|
||||
<div class="example-output">
|
||||
<div class="example-output-label">Output</div>
|
||||
<pre><?= output ?></pre>
|
||||
</div>
|
||||
</div><?
|
||||
}
|
||||
}
|
||||
|
||||
void render_see_section(String name)
|
||||
{
|
||||
StringList lines = split(file_get_contents("areas/" + name + ".txt"), "\n");
|
||||
@@ -225,6 +276,8 @@ RENDER(Request& context)
|
||||
?><div class="doc-section content"><?: markdown_to_html(doc_page.content) ?></div><?
|
||||
}
|
||||
|
||||
render_doc_examples(page, doc_page.example_blocks);
|
||||
|
||||
?></article><?
|
||||
|
||||
if(doc_page.see_lines.size() > 0)
|
||||
|
||||
Reference in New Issue
Block a user