From: dequis Date: Thu, 7 Aug 2014 00:15:25 +0000 (-0300) Subject: Use for loops over attributes to generate scripts.dmp output X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=e8ccd4beeccdc54695648c8a88f0612de529d5e8;p=irssi-scripts.irssi.org.git Use for loops over attributes to generate scripts.dmp output It's shorter and also reduces redundant whitespace in output. This liquid templating engine is dumb. Writing it this way is the only way to avoid whitespace between tags. --- diff --git a/scripts.dmp b/scripts.dmp index fc396fe..d80b6b4 100644 --- a/scripts.dmp +++ b/scripts.dmp @@ -2,33 +2,16 @@ layout: nil --- +{% assign required_attributes = "filename modified version authors contact name description license" | split: ' ' %} +{% assign optional_attributes = "url changed commands note modules" | split: ' ' %} + $scripts = { {% for script in site.data.scripts %} '{{ script.filename }}' => { - 'filename' => '{{ script.filename }}', - 'last_modified' => '{{ script.modified }}', - 'version' => '{{ script.version }}', - 'authors' => '{{ script.authors }}', - 'contact' => '{{ script.contact }}', - 'name' => '{{ script.name }}', - 'description' => '{{ script.description }}', - 'license' => '{{ script.license }}', -{% if script.url %} - 'url' => '{{ script.url }}', -{% endif %} -{% if script.changed %} - 'changed' => '{{ script.changed }}', -{% endif %} -{% if script.commands %} - 'commands' => '{{ script.commands }}', -{% endif %} -{% if script.note %} - 'note' => '{{ script.note }}', -{% endif %} -{% if script.modules %} - 'modules' => '{{ script.modules }}', -{% endif %} - +{% for attr in required_attributes %} + '{{ attr }}' => '{{ script[attr] }}',{% endfor %} +{% for attr in optional_attributes %}{% if script contains attr %} + '{{ attr }}' => '{{ script[attr] }}',{% endif %}{% endfor %} }, {% endfor %} };