cmake: Add a --DOC_NO_DASH option to the doc examples framework

This way it can be used in documentation pages.
This commit is contained in:
Emmanuel Lepage Vallee 2017-02-11 15:35:08 -05:00 committed by Yauhen Kirylau
parent 6d00d34b41
commit f448a604b7
1 changed files with 20 additions and 13 deletions

View File

@ -83,7 +83,7 @@ function(escape_string variable content escaped_content line_prefix)
set(tmp_output ${content}) set(tmp_output ${content})
foreach (LINE ${var_lines}) foreach (LINE ${var_lines})
if(NOT LINE MATCHES "^.*--DOC_[A-Z]+") if(NOT LINE MATCHES "^.*--DOC_[A-Z]+")
set(tmp_output ${tmp_output}\n--${line_prefix}${LINE}) set(tmp_output ${tmp_output}\n${DOC_LINE_PREFIX}${line_prefix}${LINE})
endif() endif()
endforeach() endforeach()
@ -117,8 +117,8 @@ function(extract_header variable pre_output post_output)
endif() endif()
endforeach() endforeach()
set(${post_output} "${tmp_post_output}\n--" PARENT_SCOPE) set(${post_output} "${tmp_post_output}\n${DOC_LINE_PREFIX}" PARENT_SCOPE)
set(${pre_output} "${tmp_pre_output}\n--" PARENT_SCOPE) set(${pre_output} "${tmp_pre_output}\n${DOC_LINE_PREFIX}" PARENT_SCOPE)
endfunction() endfunction()
# Read a code file and convert it to ldoc usage example. # Read a code file and convert it to ldoc usage example.
@ -169,6 +169,19 @@ endfunction()
function(run_test test_path namespace escaped_content) function(run_test test_path namespace escaped_content)
find_template(template "${test_path}") find_template(template "${test_path}")
file(READ ${test_path} tmp_content)
# Add "--" in front of each line. This is required for method doc, but not
# for documentation pages
if(NOT tmp_content MATCHES "--DOC_NO_DASH")
set(DOC_LINE_PREFIX "--")
endif()
# Do not use the @usage tag, but 4 spaces.
if(NOT tmp_content MATCHES "--DOC_NO_USAGE")
set(DOC_BLOCK_PREFIX "@usage")
endif()
# Get the file name without the extension. # Get the file name without the extension.
get_filename_component(${test_path} TEST_FILE_NAME NAME) get_filename_component(${test_path} TEST_FILE_NAME NAME)
set(IMAGE_PATH "${IMAGE_DIR}/AUTOGEN${namespace}_${TEST_FILE_NAME}") set(IMAGE_PATH "${IMAGE_DIR}/AUTOGEN${namespace}_${TEST_FILE_NAME}")
@ -218,7 +231,7 @@ function(run_test test_path namespace escaped_content)
# documentation under the image. # documentation under the image.
if(NOT ${TEST_OUTPUT} STREQUAL "") if(NOT ${TEST_OUTPUT} STREQUAL "")
set(TEST_DOC_CONTENT set(TEST_DOC_CONTENT
"${TEST_DOC_CONTENT}\n--\n--**Usage example output**:\n--" "${TEST_DOC_CONTENT}\n${DOC_LINE_PREFIX}\n${DOC_LINE_PREFIX}**Usage example output**:\n${DOC_LINE_PREFIX}"
) )
# Markdown requires an empty line before and after, and 4 spaces. # Markdown requires an empty line before and after, and 4 spaces.
@ -226,22 +239,16 @@ function(run_test test_path namespace escaped_content)
"\n${TEST_OUTPUT}" "\n${TEST_OUTPUT}"
"${TEST_DOC_CONTENT}" TEST_DOC_CONTENT " " "${TEST_DOC_CONTENT}" TEST_DOC_CONTENT " "
) )
set(TEST_DOC_CONTENT "${TEST_DOC_CONTENT}\n--") set(TEST_DOC_CONTENT "${TEST_DOC_CONTENT}\n${DOC_LINE_PREFIX}")
endif() endif()
# If there is some @* content, append it. # If there is some @* content, append it.
set(TEST_DOC_CONTENT "${TEST_DOC_CONTENT}${TEST_POST_HEADER}") set(TEST_DOC_CONTENT "${TEST_DOC_CONTENT}${TEST_POST_HEADER}")
# Only add it if there is something to display. # Only add it if there is something to display.
if(NOT ${TEST_CODE} STREQUAL "\n--") if(NOT ${TEST_CODE} STREQUAL "\n${DOC_LINE_PREFIX}")
# Do not use the @usage tag, but 4 spaces.
file(READ ${test_path} tmp_content)
if(NOT tmp_content MATCHES "--DOC_NO_USAGE")
set(DOC_PREFIX "@usage")
endif()
escape_string( escape_string(
" ${DOC_PREFIX}" " ${DOC_BLOCK_PREFIX}"
"${TEST_DOC_CONTENT}" TEST_DOC_CONTENT "" "${TEST_DOC_CONTENT}" TEST_DOC_CONTENT ""
) )