def html_rewriter(self): embed_rules = {} link_rules = {} for rule in self.converter_rules: if isinstance(rule, EmbedTypeRule): embed_rules[rule.embed_type] = rule.handler.expand_db_attributes elif isinstance(rule, LinkTypeRule): link_rules[rule.link_type] = rule.handler.expand_db_attributes return MultiRuleRewriter([LinkRewriter(link_rules), EmbedRewriter(embed_rules)])
def expand_db_html(html): """ Expand database-representation HTML into proper HTML usable on front-end templates """ global FRONTEND_REWRITER if FRONTEND_REWRITER is None: embed_rules = features.get_embed_types() link_rules = features.get_link_types() FRONTEND_REWRITER = MultiRuleRewriter( [LinkRewriter(link_rules), EmbedRewriter(embed_rules)]) return FRONTEND_REWRITER(html)
def expand_db_html(html): """ Expand database-representation HTML into proper HTML usable on front-end templates """ global FRONTEND_REWRITER if FRONTEND_REWRITER is None: embed_rules = features.get_embed_types() link_rules = features.get_link_types() FRONTEND_REWRITER = MultiRuleRewriter([ LinkRewriter({ linktype: handler.expand_db_attributes for linktype, handler in link_rules.items() }), EmbedRewriter({ embedtype: handler.expand_db_attributes for embedtype, handler in embed_rules.items() }) ]) return FRONTEND_REWRITER(html)