Helma Logo
main list history
previous version  overview  next version

Version 6 by tobi on 20. July 2006, 13:54

<pre><code>var var renderSnippet = function(name, param)
var cache;
if (!(cache = res.data["herpes:snippets"])) {
cache = res.data["herpes:snippets"] = new Object;
}
  if (cache[name]) {
  renderSkin(cache[name], param);
  return;
  }

  var NAME = "snippet";
  var DELIMITER = ":";
  var EXTENSION = "." + NAME + "s";
  var PREFIX = "<!" + NAME + DELIMITER;

  var dir = new File(app.dir, "Global");
  var file, snippetName;
  if (name.contains(DELIMITER)) {
      var parts = name.split(DELIMITER);
      file = new File(dir, parts[0] + EXTENSION);
      snippetName = parts[1];
  } else {
      file = new File(dir, name + EXTENSION);
  }

  if (file.exists()) {
      var content = file.readAll();
      var needle, offset, start;
      if (snippetName) {
        needle = PREFIX + snippetName;
        offset = content.indexOf(needle);
        start = offset + needle.length + 1;
      } else {
        offset = content.indexOf(PREFIX);
        start = offset + content.indexOf(">") + 1;
      }
      var end = content.indexOf(PREFIX, start);
      if (end < 0) {
      end = content.length;
      }
      var snippet = content.substring(start, end);
      if (snippet) {
      cache[name] = createSkin(snippet.trim());
        renderSkin(cache[name], param);
      }
  }
  return;
};</code></pre>

     removed
     added