Skip to content

Commit

Permalink
Update to use render
Browse files Browse the repository at this point in the history
  • Loading branch information
cfxd committed May 12, 2023
1 parent 8f35774 commit 410915f
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 140 deletions.
5 changes: 4 additions & 1 deletion examples/youtube/shortcode-youtube.liquid
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<iframe id="ytplayer" type="text/html" width="{% include 'shortcode-render' render:'width' default:'640' %}" height="{% include 'shortcode-render' render:'height' default:'390' %}" src="//www.youtube.com/embed/{% include 'shortcode-render' render:'src' default:'M7lc1UVf-VE' %}" frameborder="0" ></iframe>
{% comment %}
Usage: [youtube width="800" height="500" src="DmnNrrnXrts"]
{% endcomment %}
<iframe id="ytplayer" type="text/html" width="{% render 'shortcode-render', render_var: 'width', default:'640', keys_final: keys_final, variables_arr: variables_arr %}" height="{% render 'shortcode-render', render_var: 'height', default:'390', keys_final: keys_final, variables_arr: variables_arr %}" src="//www.youtube.com/embed/{% render 'shortcode-render', render_var: 'src', default:'M7lc1UVf-VE', keys_final: keys_final, variables_arr: variables_arr %}" frameborder="0" ></iframe>
23 changes: 13 additions & 10 deletions shortcode-render.liquid
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{%- assign shortcodekeyfound = false -%}
{%- for keys in key -%}
{%- if keys == render -%}
{{-variable[forloop.index0]-}}
{%- assign shortcodekeyfound = true -%}
{%- endif -%}
{%- endfor -%}
{%- if shortcodekeyfound == false -%}
{{-default-}}
{%- endif -%}
{%- liquid
assign shortcodekeyfound = false
for key in keys_final
if key == render_var
echo variables_arr[forloop.index0]
assign shortcodekeyfound = true
endif
endfor

if shortcodekeyfound == false
echo default
endif
-%}
258 changes: 129 additions & 129 deletions shortcode.liquid
Original file line number Diff line number Diff line change
@@ -1,131 +1,131 @@
{%- capture loadnew -%}{{- load | replace: '<!--[', '[' -}}{%- endcapture -%}
{%- capture loadnew -%}{{- loadnew | replace: ']-->', ']' -}}{%- endcapture -%}
{%- capture loadnew -%}{{- loadnew | replace: ']</p>', ']' -}}{%- endcapture -%}
{%- capture loadnew -%}{{- loadnew | replace: '<p>[', '[' -}}{%- endcapture -%}
{%- assign shortcodeBeginnings = loadnew | split: '[' -%}

{%- if shortcodeBeginnings.size > 1 -%}

{%- for shortcodeBegin in shortcodeBeginnings -%}
{%- assign forloopNextIndex = forloop.index0 | plus: 1 -%}

{%- comment -%}
// First Iteration will contain everithing before the first shortcode
{%- endcomment -%}

{%- if forloop.first -%}
{{-shortcodeBegin-}}
{%- else -%}
{%- assign shortcodeEndings = shortcodeBegin | split: ']' -%}
{%- assign contentAfterClosingTag = shortcodeEndings[1] -%}

{%- capture shortcodeFull -%}{{-shortcodeEndings[0]-}}{%- endcapture -%}

{%- assign shortcodes = shortcodeFull | split: '"' -%}
{%- assign variables = '' -%}
{%- assign keys = '' -%}
{%- assign thecycle = 'even' -%}

{%- for section in shortcodes -%}
{%- if thecycle == 'odd' -%}
{%- assign thecycle = 'even' -%}
{%- else -%}
{%- assign thecycle = 'odd'-%}
{%- endif -%}

{%- if forloop.first -%}

{%- comment -%}
// Handle Closing Tags and pass 'content'
{%- endcomment -%}

{%- assign sectionSpace = section | split: ' ' -%}

{%- assign content = '' -%}

{%- assign currentSection = sectionSpace[0] -%}

{%- assign nextSection = shortcodeBeginnings[forloopNextIndex] -%}
{%- assign nextSection = nextSection | split: ']' -%}
{%- assign nextSection = nextSection[0] -%}
{%- assign nextSection = nextSection | replace: '/', '' -%}

{%- if currentSection == nextSection -%}
{%- assign content = content | append: contentAfterClosingTag -%}
{%- assign variables = variables | append: content | append: '||' -%}
{%- assign keys = keys | append: 'content' | append: '||' -%}
{%- assign contentAfterClosingTag = '' -%}
{%- endif -%}

{%- if forloop.last -%}
{%- for space in sectionSpace -%}

{%- comment -%}
// First Iteration will setup the correct template
{%- endcomment -%}

{%- if forloop.first -%}
{%- assign template = space | prepend: 'shortcode-' -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- else -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}

{%- capture output -%}{%- assign buildVariables = variables | split: '||' -%}{%- include template variable: buildVariables -%}{%- endcapture -%}

{%- if output contains 'Liquid error' -%}
[{{- shortcodeFull -}}]
{%- else -%}
{{-output-}}
{%- endif -%}
{%- else -%}
{%- assign sectionSpace = section | split: ' ' -%}

{%- for space in sectionSpace -%}
{%- if forloop.first -%}
{%- assign template = sectionSpace.first | prepend: 'shortcode-' -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign keys = keys | append: space | replace: '=', ''| append: '||' -%}
{%- else -%}
{%- assign keys = keys | append: "nokey_" | append: space | replace: '=', ''| append: '||' -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign variables = variables | append: section -%}
{%- assign variablesFinal = variables | split: '||' -%}
{%- assign keysFinal = keys | replace: ' ', '' | split: '||' -%}

{%- capture output -%}{%- include template variable: variablesFinal key: keysFinal -%}{%- endcapture -%}

{%- if output contains 'Liquid error' -%}
[{{- shortcodeFull -}}]
{%- else -%}
{{-output-}}
{%- endif -%}
{%- else -%}
{%- if thecycle == 'even' -%}
{%- assign variables = variables | append: section | append: '||' -%}
{%- endif -%}

{%- if thecycle == 'odd' -%}
{%- assign keys = keys | append: section | replace: '=', ''| append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}

{{-contentAfterClosingTag-}}
{%- endif -%}
{%- endfor -%}
{%- capture load_new -%}{{- load | replace: '<!--[', '[' -}}{%- endcapture -%}
{%- capture load_new -%}{{- load_new | replace: ']-->', ']' -}}{%- endcapture -%}
{%- capture load_new -%}{{- load_new | replace: ']</p>', ']' -}}{%- endcapture -%}
{%- capture load_new -%}{{- load_new | replace: '<p>[', '[' -}}{%- endcapture -%}
{%- assign shortcode_beginnings = load_new | split: '[' -%}

{%- if shortcode_beginnings.size > 1 -%}

{%- for shortcode_begin in shortcode_beginnings -%}
{%- assign forloop_next_index0 = forloop.index0 | plus: 1 -%}

{%- comment -%}
// First Iteration will contain everithing before the first shortcode
{%- endcomment -%}

{%- if forloop.first -%}
{{-shortcode_begin-}}
{%- else -%}
{%- assign shortcode_endings = shortcode_begin | split: ']' -%}
{%- assign content_after_closing_tag = shortcode_endings[1] -%}

{%- capture shortcode_full -%}{{-shortcode_endings[0]-}}{%- endcapture -%}

{%- assign shortcodes = shortcode_full | split: '"' -%}
{%- assign variables = '' -%}
{%- assign keys = '' -%}
{%- assign thecycle = 'even' -%}

{%- for segment in shortcodes -%}
{%- if thecycle == 'odd' -%}
{%- assign thecycle = 'even' -%}
{%- else -%}
{%- assign thecycle = 'odd'-%}
{%- endif -%}

{%- if forloop.first -%}

{%- comment -%}
// Handle Closing Tags and pass 'content'
{%- endcomment -%}

{%- assign section_space = segment | split: ' ' -%}

{%- assign content = '' -%}

{%- assign current_section = section_space[0] -%}

{%- assign next_section = shortcode_beginnings[forloop_next_index0] -%}
{%- assign next_section = next_section | split: ']' -%}
{%- assign next_section = next_section[0] -%}
{%- assign next_section = next_section | replace: '/', '' -%}

{%- if current_section == next_section -%}
{%- assign content = content | append: content_after_closing_tag -%}
{%- assign variables = variables | append: content | append: '||' -%}
{%- assign keys = keys | append: 'content' | append: '||' -%}
{%- assign content_after_closing_tag = '' -%}
{%- endif -%}

{%- if forloop.last -%}
{%- for space in section_space -%}

{%- comment -%}
// First Iteration will setup the correct template
{%- endcomment -%}

{%- if forloop.first -%}
{%- assign template_name = space | prepend: 'shortcode-' -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- else -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}

{%- capture output -%}{%- assign variables_arr = variables | split: '||' -%}{%- render 'shortcode-youtube', variables_arr: variables_arr -%}{%- endcapture -%}

{%- if output contains 'Liquid error' -%}
[{{- shortcode_full -}}]
{%- else -%}
{{-output-}}
{%- endif -%}
{%- else -%}
{%- assign section_space = segment | split: ' ' -%}

{%- for space in section_space -%}
{%- if forloop.first -%}
{%- assign template_name = section_space.first | prepend: 'shortcode-' -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign keys = keys | append: space | replace: '=', ''| append: '||' -%}
{%- else -%}
{%- assign keys = keys | append: "nokey_" | append: space | replace: '=', ''| append: '||' -%}
{%- assign variables = variables | append: space | append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- else -%}
{%- if forloop.last -%}
{%- assign variables = variables | append: segment -%}
{%- assign variables_final = variables | split: '||' -%}
{%- assign keys_final = keys | replace: ' ', '' | split: '||' -%}

{%- capture output -%}{%- render 'shortcode-youtube', variables_arr: variables_final, keys_final: keys_final -%}{%- endcapture -%}

{%- if output contains 'Liquid error' -%}
[{{- shortcode_full -}}]
{%- else -%}
{{-output-}}
{%- endif -%}
{%- else -%}
{%- if thecycle == 'even' -%}
{%- assign variables = variables | append: segment | append: '||' -%}
{%- endif -%}

{%- if thecycle == 'odd' -%}
{%- assign keys = keys | append: segment | replace: '=', ''| append: '||' -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
{%- endfor -%}

{{-content_after_closing_tag-}}
{%- endif -%}
{%- endfor -%}
{%- else -%}
{{- load -}}
{{- load -}}
{%- endif -%}

0 comments on commit 410915f

Please sign in to comment.