Helma Logo
main list history
previous version  overview  next version

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

<pre><code>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>

<pre><code><!snippet:link>
<a href="<% param.href %>"><% param.text %></a>
<!snippet:image>
<img src="<% param.src %>"
    <% param.width prefix='width="' suffix='"' %>
    <% param.height prefix='height="' suffix='"' %>
    border="0" />
<!snippet:table>
<table border="0" cellspacing="0" cellpadding="0">
<% param.rows %>
</table>
<!snippet:tablerow>
<tr>
<% param.cells %>
</tr>
<!snippet:tablecell>
<td><% param.data %></td></code></pre>

     removed
     added