Permalink
Browse files

[enhance] Templates: big re-factoring.

Removing code-duplication & reducing size of the huge recursive
type that was not very DB-friendly, i.e. slow to process.
  • Loading branch information...
1 parent acb09a5 commit 9669fac3b608c85a89c300ab4199188c7937a85b @akoprow akoprow committed Nov 9, 2011
Showing with 204 additions and 247 deletions.
  1. +3 −38 stdlib/web/template/template.opa
  2. +193 −173 stdlib/web/template/template_base_engine.opa
  3. +8 −36 stdlib/web/template/template_type.opa
@@ -235,67 +235,32 @@ Template =
default_conf = { strict = false ; fallback_to_text_node = true}
@private map_content(translation:('a -> 'b), content:Template.content('a)) : Template.content('b) =
-
match content with
+ | { ~standard_tag; ~content; ~standard_attribute } -> { ~standard_tag; content=map_content(translation, content); ~standard_attribute}
| { anchor; ~anchor_attribute; ~content } -> {anchor; ~anchor_attribute; content=map_content(translation, content) }
- | { div; ~content; ~standard_attribute } -> { div; content=map_content(translation, content); ~standard_attribute}
| { blockquote; ~content; ~quote_attribute } -> { blockquote; content=map_content(translation, content); ~quote_attribute}
| { quote; ~content; ~quote_attribute } -> { quote; content=map_content(translation, content); ~quote_attribute}
- | { address; ~content; ~standard_attribute } -> { address; content=map_content(translation, content); ~standard_attribute}
- | { acronym; ~content; ~standard_attribute } -> { acronym; content=map_content(translation, content); ~standard_attribute}
- | { span; ~content; ~standard_attribute } -> { span; content= map_content(translation, content); ~standard_attribute }
| { ~fragment } -> { fragment = List.map(el -> map_content(translation, el), fragment) }
| { ~text } -> { ~text }
| { ~checked_text } -> { ~checked_text }
| { ~extension } -> { extension = translation(extension) }
| { br ; ~standard_attribute } -> { br ; ~standard_attribute }
- | { fieldset ; ~content ; ~standard_attribute } -> { fieldset ; content=map_content(translation, content) ; ~standard_attribute }
| { form ; ~content ; ~form_attribute } -> { form ; content=map_content(translation, content) ; ~form_attribute }
- | { h1 ; ~content ; ~standard_attribute } -> { h1 ; content=map_content(translation, content) ; ~standard_attribute }
- | { h2 ; ~content ; ~standard_attribute } -> { h2 ; content=map_content(translation, content) ; ~standard_attribute }
- | { h3 ; ~content ; ~standard_attribute } -> { h3 ; content=map_content(translation, content) ; ~standard_attribute }
- | { h4 ; ~content ; ~standard_attribute } -> { h4 ; content=map_content(translation, content) ; ~standard_attribute }
- | { h5 ; ~content ; ~standard_attribute } -> { h5 ; content=map_content(translation, content) ; ~standard_attribute }
- | { h6 ; ~content ; ~standard_attribute } -> { h6 ; content=map_content(translation, content) ; ~standard_attribute }
- | { del ; ~content ; ~standard_attribute } -> { del ; content=map_content(translation, content) ; ~standard_attribute }
- | { ins ; ~content ; ~standard_attribute } -> { ins ; content=map_content(translation, content) ; ~standard_attribute }
- | { abbr ; ~content ; ~standard_attribute } -> { abbr ; content=map_content(translation, content) ; ~standard_attribute }
- | { dd ; ~content ; ~standard_attribute } -> { dd ; content=map_content(translation, content) ; ~standard_attribute }
- | { dt ; ~content ; ~standard_attribute } -> { dt ; content=map_content(translation, content) ; ~standard_attribute }
- | { dl ; ~content ; ~standard_attribute } -> { dl ; content=map_content(translation, content) ; ~standard_attribute }
| { hr ; ~standard_attribute } -> { hr ; ~standard_attribute }
| { img ; ~img_attribute } -> { img ; ~img_attribute }
| { input ; ~input_attribute } -> { input ; ~input_attribute }
| { label ; ~content ; ~label_attribute } -> { label ; content=map_content(translation, content) ; ~label_attribute }
- | { legend ; ~content ; ~standard_attribute } -> { legend ; content=map_content(translation, content) ; ~standard_attribute }
- | { li ; ~content ; ~standard_attribute } -> { li ; content=map_content(translation, content) ; ~standard_attribute }
- | { ol ; ~content ; ~standard_attribute } -> { ol ; content=map_content(translation, content) ; ~standard_attribute }
| { optgroup ; ~content ; ~optgroup_attribute } -> { optgroup ; content=map_content(translation, content) ; ~optgroup_attribute }
| { option ; ~content ; ~option_attribute } -> { option ; content=map_content(translation, content) ; ~option_attribute }
- | { paragraph ; ~content ; ~standard_attribute } -> { paragraph ; content=map_content(translation, content) ; ~standard_attribute }
- | { pre ; ~content ; ~standard_attribute } -> { pre ; content=map_content(translation, content) ; ~standard_attribute }
| { select ; ~content ; ~select_attribute } -> { select ; content=map_content(translation, content) ; ~select_attribute }
- | { sub ; ~content ; ~standard_attribute } -> { sub ; content=map_content(translation, content) ; ~standard_attribute }
- | { sup ; ~content ; ~standard_attribute } -> { sup ; content=map_content(translation, content) ; ~standard_attribute }
- | { table ; ~content ; ~standard_attribute } -> { table ; content=map_content(translation, content) ; ~standard_attribute }
- | { caption; ~content ; ~standard_attribute } -> { caption ; content=map_content(translation, content) ; ~standard_attribute }
- | { tbody ; ~content ; ~standard_attribute } -> { tbody ; content=map_content(translation, content) ; ~standard_attribute }
| { td ; ~content ; ~td_attribute } -> { td ; content=map_content(translation, content) ; ~td_attribute }
| { textarea ; ~content ; ~textarea_attribute } -> { textarea ; content=map_content(translation, content) ; ~textarea_attribute }
- | { tfoot ; ~content ; ~standard_attribute } -> { tfoot ; content=map_content(translation, content) ; ~standard_attribute }
| { th ; ~content ; ~th_attribute } -> { th ; content=map_content(translation, content) ; ~th_attribute }
- | { thead ; ~content ; ~standard_attribute } -> { thead ; content=map_content(translation, content) ; ~standard_attribute }
- | { tr ; ~content ; ~standard_attribute } -> { tr ; content=map_content(translation, content) ; ~standard_attribute }
- | { ul ; ~content ; ~standard_attribute } -> { ul ; content=map_content(translation, content) ; ~standard_attribute }
- | { menu ; ~content ; ~standard_attribute } -> { menu ; content=map_content(translation, content) ; ~standard_attribute }
- | { open ; ~content; ~standard_attribute } -> { open ; content=map_content(translation, content); ~standard_attribute }
| { link ; ~link_attribute } -> { link; ~link_attribute }
| { head ; ~content } -> { head ; content=map_content(translation, content) }
| { ~title } -> { ~title }
| { meta; ~meta_attribute } -> { meta; ~meta_attribute }
| { base; ~base_attribute } -> { base; ~base_attribute }
- | { header; ~content; ~standard_attribute } -> { span; content=map_content(translation, content); ~standard_attribute }
- | { footer; ~content; ~standard_attribute } -> { span; content=map_content(translation, content); ~standard_attribute }
abstract_map_xmlns_parser(fun:(xmlns -> outcome(Template.content('a), Template.failure)), mapper:(Template.content('a) -> Template.content('b) )):(xmlns -> outcome(Template.content('b), Template.failure)) =
xmlns -> match fun(xmlns) with
@@ -366,9 +331,9 @@ Template =
*/
try_parse_with_conf(conf:Template.conf, engine:Template.engine('a, 'b), input:string) : outcome(Template.content(either('a, 'b)), Template.failure ) =
(
- remove_span(content:Template.content(either('a, 'b) ) ) =
+ remove_span(content:Template.content(either('a, 'b))) =
match content with
- | { span; ~content ... } -> content
+ | { standard_tag={span}; ~content ... } -> content
| _ -> @fail
match Xmlm.try_parse(input) with
Oops, something went wrong.

0 comments on commit 9669fac

Please sign in to comment.