Ejemplo n.º 1
0
        
        @shpaml.syntax(r'{% > *((\w+).*)')
        def SELF_CLOSING_TEMPLATE_STATEMENT(m):
            tag = m.group(1).strip()
            return '{%% %s{%% end%s %%}' % (m.group(1), m.group(2))
        
        shpaml.LINE_METHODS.insert(0, SELF_CLOSING_TEMPLATE_STATEMENT)
        
        TEMPLATE_STATEMENT = re.compile(r'{% (\w+)')
        
        def html_block_tag_with_template_statement(html_block_tag_without_template_statement, output, block, recurse):
            append = output.append
            prefix, tag = block[0]
            if shpaml.RAW_HTML.regex.match(tag):
                match = TEMPLATE_STATEMENT.match(tag)
                if match:
                    append(prefix + whitespace_removal.TextWithoutWhitespace(tag))
                    recurse(block[1:])
                    append(prefix + whitespace_removal.TextWithoutWhitespace('{% end' + match.group(1) + ' %}'))
                    return
            html_block_tag_without_template_statement(output, block, recurse)
        
        runtime.hook_module_function(shpaml, 'html_block_tag', html_block_tag_with_template_statement)

aml.configure(JinjaShortcuts)
convert_text = aml.convert_text

if __name__ == "__main__":
    import filter
    filter.perform_conversion(convert_text)
Ejemplo n.º 2
0
            tag = m.group(1).strip()
            return "<%% %s<%% end %%>" % (m.group(1))

        shpaml.LINE_METHODS.insert(0, SELF_CLOSING_TEMPLATE_STATEMENT)

        TEMPLATE_STATEMENT = re.compile(r"<%(!?) (\w+)")

        def html_block_tag_with_template_statement(html_block_tag_without_template_statement, output, block, recurse):
            append = output.append
            prefix, tag = block[0]
            if shpaml.RAW_HTML.regex.match(tag):
                match = TEMPLATE_STATEMENT.match(tag)
                if match:
                    append(prefix + whitespace_removal.TextWithoutWhitespace(tag))
                    recurse(block[1:])
                    finalizer = "<%%%s end %%>" % match.group(1)
                    append(prefix + whitespace_removal.TextWithoutWhitespace(finalizer))
                    return
            html_block_tag_without_template_statement(output, block, recurse)

        runtime.hook_module_function(shpaml, "html_block_tag", html_block_tag_with_template_statement)


aml.configure(ErbShortcuts)
convert_text = aml.convert_text

if __name__ == "__main__":
    import filter

    filter.perform_conversion(convert_text)