]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Use for loops over attributes to generate scripts.dmp output
authordequis <redacted>
Thu, 7 Aug 2014 00:15:25 +0000 (21:15 -0300)
committerdequis <redacted>
Thu, 7 Aug 2014 05:06:41 +0000 (02:06 -0300)
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

index fc396fec1698e0607b65bbc6a0ab4b6c8fe138e5..d80b6b4953a21f6173c73d3366216fd718b5c031 100644 (file)
@@ -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 %}
 };
git clone https://git.99rst.org/PROJECT