Skip to content

Commit 08361b0

Browse files
committed
Clean-up in-line documentation.
1 parent d8c9a34 commit 08361b0

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

color_multi_tool.jinja

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@
100100
REMEMBER:
101101
Everything returned from a macro template is a string.
102102
#}
103+
{#- First a test to make sure input is valid #}
103104
{%- if chkNAME(color_name) | bool %}
104105
{%- set R = _nameMap['_rgb'] | selectattr('color', 'eq', color_name) | map(attribute='r') | first | default([]) %}
105106
{%- set G = _nameMap['_rgb'] | selectattr('color', 'eq', color_name) | map(attribute='g') | first | default([]) %}
106107
{%- set B = _nameMap['_rgb'] | selectattr('color', 'eq', color_name) | map(attribute='b') | first | default([]) %}
107108
{%- else %}
109+
{#- Set defaults #}
108110
{%- set R = 0 %}
109111
{%- set G = 0 %}
110112
{%- set B = 0 %}
@@ -132,18 +134,23 @@
132134
REMEMBER:
133135
Everything returned from a macro template is a string.
134136
#}
137+
{#- First a test to make sure input is valid #}
135138
{%- if chkRGB(rgbl) | default(false) | bool %}
139+
{#- Set defaults #}
136140
{%- set out = ["black"] | list %}
141+
{#- Pull in the data #}
137142
{%- set _rnge = _range | default(0) | round(0,0) %}
138143
{%- set iR = rgbl[0] | default(0) | int(0) %}
139144
{%- set iG = rgbl[1] | default(0) | int(0) %}
140145
{%- set iB = rgbl[2] | default(0) | int(0) %}
146+
{#- Define Ranges for each color #}
141147
{%- set _Rl = rgbl[0] + _rnge %}
142148
{%- set _Gl = rgbl[1] + _rnge %}
143149
{%- set _Bl = rgbl[2] + _rnge %}
144150
{%- set _Rg = rgbl[0] - _rnge %}
145151
{%- set _Gg = rgbl[1] - _rnge %}
146152
{%- set _Bg = rgbl[2] - _rnge %}
153+
{#- Grab matching colors out of the list. #}
147154
{%- set out = _nameMap['_rgb'] |
148155
selectattr('r', 'ge', _Rg) |
149156
selectattr('r', 'le', _Rl) |
@@ -154,7 +161,7 @@
154161
map(attribute='color') | list | default(['black']) %}
155162
{{- out -}}
156163
{%- else %}
157-
{#- Input was not valid #}
164+
{#- Input was not valid #}
158165
{{-['black'] | list -}}
159166
{%- endif %}
160167
{% endmacro %}
@@ -177,7 +184,9 @@
177184
REMEMBER:
178185
Everything returned from a macro template is a string.
179186
#}
187+
{#- First a test to make sure input is valid #}
180188
{%- if chkRGB(rgbl) | bool %}
189+
{#- Set defaults #}
181190
{%- set iR = rgbl[0] | int(0) %}
182191
{%- set iG = rgbl[1] | int(0) %}
183192
{%- set iB = rgbl[2] | int(0) %}
@@ -214,12 +223,12 @@
214223
{%- set X = x | float(0) | round(3) %}
215224
{%- set Y = y | float(0) | round(3) %}
216225
{%- else %}
217-
{#- Color started as black #}
226+
{#- Color started as black #}
218227
{%- set X = 0.0 %}
219228
{%- set Y = 0.0 %}
220229
{%- endif %}
221230
{%- else %}
222-
{#- Input was not valid #}
231+
{#- Input was not valid #}
223232
{%- set X = 0.0 %}
224233
{%- set Y = 0.0 %}
225234
{%- endif %}
@@ -244,7 +253,7 @@
244253
REMEMBER:
245254
Everything returned from a macro template is a string.
246255
#}
247-
{#- First a test to make sure this is a list #}
256+
{#- First a test to make sure input is valid #}
248257
{%- if chkXY(xyl) | bool %}
249258
{%- set vX = xyl[0] | float(0) %}
250259
{%- set vY = xyl[1] | float(0.00000000001) %}
@@ -289,7 +298,7 @@
289298
{%- set G = (g * 255) | int(0) %}
290299
{%- set B = (b * 255) | int(0) %}
291300
{%- else %}
292-
{#- Input was not valid #}
301+
{#- Input was not valid #}
293302
{%- set R = 0 %}
294303
{%- set G = 0 %}
295304
{%- set B = 0 %}
@@ -315,7 +324,7 @@
315324
REMEMBER:
316325
Everything returned from a macro template is a string.
317326
#}
318-
{#- First a test to make sure this is a list #}
327+
{#- First a test to make sure input is valid #}
319328
{%- if chkHS(hsl) | bool %}
320329
{%- set fH = (hsl[0] | float(0)) %}
321330
{%- set fS = (hsl[1] | float(0)) / 100 %}
@@ -358,14 +367,14 @@
358367
{%- set G = g | int(0) %}
359368
{%- set B = b | int(0) %}
360369
{%- else %}
361-
{#- Color started as white #}
370+
{#- Color started as white #}
362371
{%- set fV = (fB * 255) | int(0) %}
363372
{%- set R = fV | int(0) %}
364373
{%- set G = fV | int(0) %}
365374
{%- set B = fV | int(0) %}
366375
{%- endif %}
367376
{%- else %}
368-
{#- Input was not valid #}
377+
{#- Input was not valid #}
369378
{%- set R = 0 %}
370379
{%- set G = 0 %}
371380
{%- set B = 0 %}
@@ -391,47 +400,47 @@
391400
REMEMBER:
392401
Everything returned from a macro template is a string.
393402
#}
394-
{#- First tests to make sure this is a list #}
403+
{#- First a test to make sure input is valid #}
395404
{%- if chkRGB(rgbl) | bool %}
396405
{%- set r = rgbl[0] | int(0) %}
397406
{%- set g = rgbl[1] | int(0) %}
398407
{%- set b = rgbl[2] | int(0) %}
399408
{%- if r + g + b != 0 %}
400409
{%- set min = [r, g, b] | min %}
401410
{%- set max = [r, g, b] | max %}
402-
{#- Set brightness to 100% #}
403-
{#- set _V = max (alternate) #}
411+
{#- Set brightness to 100% #}
412+
{#- set _V = max (alternate) #}
404413
{%- set _V = 255 %}
405-
{#- Calculate S #}
414+
{#- Calculate S #}
406415
{%- set delta = max-min %}
407416
{%- set _S = (delta / max) * 100 %}
408-
{#- Calculate H #}
417+
{#- Calculate H #}
409418
{%- if r == max %}
410-
{#- between yellow & magenta #}
419+
{#- between yellow & magenta #}
411420
{%- set _H = ( g - b ) / delta %}
412421
{%- elif g == max %}
413-
{#- between cyan & yellow #}
422+
{#- between cyan & yellow #}
414423
{%- set _H = 2 + ( b - r ) / delta %}
415424
{%- else %}
416-
{#- between magenta & cyan #}
425+
{#- between magenta & cyan #}
417426
{%- set _H = 4 + ( r - g ) / delta %}
418427
{%- endif %}
419428
{%- set _H = _H * 60 %}
420429
{%- if _H < 0 %}
421430
{%- set _H = _H + 360 %}
422431
{%- endif %}
423-
{#- Calculated output #}
432+
{#- Calculate the output #}
424433
{%- set H = _H | float(0) | round(3) %}
425434
{%- set S = _S | float(0) | round(3) %}
426435
{%- set V = _V | float(0) | round(3) %}
427436
{%- else %}
428-
{#- Color started as black #}
437+
{#- Color started as black #}
429438
{%- set H = 0.0 %}
430439
{%- set S = 0.0 %}
431440
{%- set V = 0.0 %}
432441
{%- endif %}
433442
{%- else %}
434-
{#- Input was not valid #}
443+
{#- Input was not valid #}
435444
{%- set H = 0.0 %}
436445
{%- set S = 0.0 %}
437446
{%- set V = 0.0 %}
@@ -456,17 +465,17 @@
456465
REMEMBER:
457466
Everything returned from a macro template is a string.
458467
#}
459-
{#- First a test to make sure this is a list #}
468+
{#- First a test to make sure input is valid #}
460469
{%- if chkHS(hsl) | bool %}
461470
{%- set _hs2rgb = hs2rgb(hsl).split(",") | list %}
462471
{%- set _hs2rgb_list = [_hs2rgb[0]|int(0),_hs2rgb[1]|int(0),_hs2rgb[2]|int(0)] | list %}
463472
{%- set _rgb2xy = rgb2xy(_hs2rgb_list).split(",") | list %}
464473
{%- set _rgb2xy_list = [_rgb2xy[0]|float(0)|round(3),_rgb2xy[1]|float(0)|round(3)] | list %}
465-
{#- Calculated output #}
474+
{#- Calculate the output #}
466475
{%- set X = _rgb2xy_list[0] | float(0.0) | round(3) %}
467476
{%- set Y = _rgb2xy_list[1] | float(0.0) | round(3) %}
468477
{%- else %}
469-
{#- Input was not valid #}
478+
{#- Input was not valid #}
470479
{%- set X = 0.0 %}
471480
{%- set Y = 0.0 %}
472481
{%- endif %}
@@ -490,17 +499,17 @@
490499
REMEMBER:
491500
Everything returned from a macro template is a string.
492501
#}
493-
{#- First a test to make sure this is a list #}
502+
{#- First a test to make sure input is valid #}
494503
{%- if chkXY(xyl) | bool %}
495504
{%- set _xy2rgb = xy2rgb(xyl).split(",") | list %}
496505
{%- set _xy2rgb_list = [_xy2rgb[0]|int(0),_xy2rgb[1]|int(0),_xy2rgb[2]|int(0)] | list %}
497506
{%- set _rgb2hs = rgb2hs(_xy2rgb_list).split(",") | list %}
498507
{%- set _rgb2hs_list = [_rgb2hs[0]|float(0)|round(3),_rgb2hs[1]|float(0)|round(3)] | list %}
499-
{#- Calculated output #}
508+
{#- Calculate the output #}
500509
{%- set H = _rgb2hs_list[0] | float(0.0) | round(3) %}
501510
{%- set S = _rgb2hs_list[1] | float(0.0) | round(3) %}
502511
{%- else %}
503-
{#- Input was not valid #}
512+
{#- Input was not valid #}
504513
{%- set H = 0.0 %}
505514
{%- set S = 0.0 %}
506515
{%- endif %}
@@ -557,9 +566,9 @@ Development credit to @123 on the
557566
certain of the result.
558567
#}
559568
{{- _xyl is list and
560-
_xyl | select('number') | list | count == 2 and
561-
_xyl | select('<', 0) | list | count == 0 and
562-
_xyl | select('>', 1) | list | count == 0 -}}
569+
_xyl | select('number') | list | count == 2 and
570+
_xyl | select('<', 0) | list | count == 0 and
571+
_xyl | select('>', 1) | list | count == 0 -}}
563572
{%- endmacro %}
564573

565574
{% macro chkHS(_hsl) %}
@@ -584,10 +593,10 @@ Development credit to @123 on the
584593
certain of the result.
585594
#}
586595
{{- _hsl is list and
587-
_hsl | select('number') | list | count == 2 and
588-
_hsl | select('<', 0) | list | count == 0 and
589-
_hsl[0] <= 100 and
590-
_hsl[1] <= 360 -}}
596+
_hsl | select('number') | list | count == 2 and
597+
_hsl | select('<', 0) | list | count == 0 and
598+
_hsl[0] <= 100 and
599+
_hsl[1] <= 360 -}}
591600
{%- endmacro %}
592601

593602
{% macro chkNAME(color_name) %}
@@ -610,11 +619,12 @@ If any is not true, return false.
610619
#}
611620
{%- if color_name is string_like and
612621
color_name == color_name | regex_replace('[^a-z]', '') %}
622+
{#- Is the name provided on the list? #}
613623
{%- set ns = namespace(found = false) %}
614624
{%- for color_item in _nameMap._rgb %}
615-
{%- if color_item.color == color_name %}
616-
{%- set ns.found = true %}
617-
{%- break %}{%- endif %}{%- endfor %}
625+
{%- if color_item.color == color_name %}
626+
{%- set ns.found = true -%}
627+
{%- break %}{%- endif -%}{%- endfor -%}
618628
{{- ns.found -}}
619629
{%- else %}
620630
{{- false -}}

0 commit comments

Comments
 (0)