From e8ccd4beeccdc54695648c8a88f0612de529d5e8 Mon Sep 17 00:00:00 2001 From: dequis Date: Wed, 6 Aug 2014 21:15:25 -0300 Subject: 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. --- scripts.dmp | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) 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 %} }; -- cgit v1.2.3