diff options
| author | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 02:11:43 -0500 | 
|---|---|---|
| committer | pabs@pablotron.org <pabs@pablotron.org> | 2014-12-18 02:11:43 -0500 | 
| commit | 367c94caf6c719621da77a9b47e98b9945d34aa9 (patch) | |
| tree | e80a1d10c26e57ed1a3862087468faab9c5fd75e | |
| parent | d49ccd25b30efb777fcfc6007ee29785e8d843a2 (diff) | |
| download | luigi-template-367c94caf6c719621da77a9b47e98b9945d34aa9.tar.xz luigi-template-367c94caf6c719621da77a9b47e98b9945d34aa9.zip | |
use compiled action list and remove old code
| -rw-r--r-- | luigi-template.js | 58 | 
1 files changed, 7 insertions, 51 deletions
| diff --git a/luigi-template.js b/luigi-template.js index 0afa0d6..2f6e931 100644 --- a/luigi-template.js +++ b/luigi-template.js @@ -241,61 +241,17 @@ LuigiTemplate = (function() {      this.actions = parse_template(s);    }; -  function safe_trim(s) { -    return ((s !== undefined) ? s : '').replace(RES.trim, ''); -  } - -  // given a filter string, return a list of filters -  function make_filter_list(s) { -    var i, l, a, md, r = [], fs = s.split(/\s*\|\s*/); - -    if (s.length > 0 && fs.length > 0) { -      for (i = 1, l = fs.length; i < l; i++) { -        if (md = fs[i].match(RES.filter)) { -          r.push({ -            k: md[1], -            a: safe_trim(md[3]).split(/\s*,\s*/) -          }); -        } else { -          throw new Error("invalid filter string: " + fs[i]); -        } -      } -    } - -    return r; -  } - -  function get_filter(k) { -    var r = FILTERS[k]; -    if (!r) -      throw new Error("unknown filter: " + k); - -    return r; -  } -    function run(o) {      var i, l, f, fs, me = this; -    // TODO: add compiled support here - -    return this.s.replace(RES.run, function(m, k, filters) { -      var r = o[k]; - -      // build filter list -      fs = make_filter_list(filters); +    return map(this.actions, function(row) { +      if (!row.key in o) +        throw new Error('missing key: ' + row.key) -      // iterate over and apply each filter -      for (i = 0, l = fs.length; i < l; i++) { -        // get/check filter -        f = get_filter(fs[i].k, me); - -        // apply filter -        r = f(r, fs[i].a, o, this); -      } - -      // return result -      return r; -    }); +      return reduce(row.filters, function(r, f) { +        return FILTERS[f.name](r, f.args, o, this); +      }, o[row.key]); +    }).join('');    }    function get_inline_template(key) { | 
