module

Hwaro::Core::Build::SummaryReaders

Can a template set print a page's automatic excerpt?

The excerpt is a second markdown render of every page, so ParseContent only builds it when something can print it (auto_summary_read?). A template prints it by naming summary (page.summary, p.summary, page_summary, summary_truncated) — or by printing a whole page object, whose summary key then comes along unnamed: {{ p }}, {{ p | tojson }}, {{ section.pages }}, {% for k, v in page %}, p[field], or a page handed to a macro that does any of that.

This is a static, text-level over-approximation, like TemplateVarFeatures: anything it cannot classify counts as a reader. A false "reader" only costs the excerpt render; a false "no reader" would blank summary in the output, so every rule below errs toward reading.

Constants

ASSIGN_RE = /\{%-?\s*(?:set|with)\s+(\w+)\s*=\s*(.+?)-?%\}/m
CALL_REF_RE = /(?<![\w.])(?:#{PAGE_CALLS.join('|')})\s*\([^()]*\)((?:\s*\.\s*\w+)*)/
FOR_RE = /\{%-?\s*for\s+([\w\s,]+?)\s+in\s+(.+?)-?%\}/m
GENERIC_READ_RE = /tojson|jsonify|pprint|inspect|dictsort|xmlattr|\|\s*string\b|\battr\s*\(|\battribute\s*=\s*[^"'\s]|[\w)\]]\[\s*[A-Za-z_]|\bfor\s+\w+\s*,\s*\w+\s+in\b/

Serialization, dict iteration and field names held in variables print fields nobody named.

HARMLESS_NEXT_RE = /\A\s*(?:\.|\[\s*["']|\|\s*(?:length|count)\b|is\b|==|!=|and\b|or\b|else\b|in\b)/

What may follow a page value without printing it: a field access, a literal-key subscript, a count, a test or a boolean/comparison operator. The end of the expression is NOT harmless: {{ p }} prints the page.

PAGE_CALLS = ["get_page", "get_section", "get_taxonomy", "get_taxonomy_term"] of ::String

Functions returning page-carrying objects.

PAGE_CALLS_RE = /\b(?:#{PAGE_CALLS.join('|')})\s*\(/
PAGE_NAMES = ["page", "section", "pages", "site", "paginator", "pagination_obj", "page_translations", "__all_pages__", "__all_sections__", "__pages_by_path__", "__sections_by_key__", "__sections_by_key_by_lang__", "__taxonomies__"] of ::String

Top-level template variables that are, or contain, page objects (the HTML strings pagination / section_list and the term name taxonomy_term are not).

PAGE_VALUED_ATTRS = ["page", "pages", "items", "sections", "subsections", "lower", "higher", "parent", "ancestors", "translations", "series", "series_pages", "related_posts", "backlinks", "terms", "taxonomies", "authors", "children"] of ::String

Attributes whose value is a page, a section, a term, an author or a list of them.

PRINT_RE = /\{\{-?(.*?)-?\}\}/m
REFERENCE_RE = /(?<![\w.])(\w+)((?:\s*\.\s*\w+)*)/
STRING_RE = /"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/
TAG_RE = /\{%-?(.*?)-?%\}/m

Instance methods

read?(templates : Hash(String, String)) : Bool
Source