Last active
May 4, 2021 05:15
-
-
Save dchacke/277786be964d1ca3a2c8e9412bf4b618 to your computer and use it in GitHub Desktop.
Revisions
-
Dennis Hackethal revised this gist
May 4, 2021 . 1 changed file with 10 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,18 @@ def to_html structure if structure.is_a? Hash structure.reduce([]) do |acc, (key, val)| acc + [[key.to_s, '="', val.to_s, '"'].join] end.join(' ') elsif structure.is_a? Array if structure[1].is_a? Hash tag, attrs, *children = structure.map { |s| to_html s} tag_and_attrs = structure[1].any? ? [tag, ' ', attrs].join : tag else tag, *children = structure.map { |s| to_html s} end ['<', tag_and_attrs || tag, '>', children.join, '</', tag, '>'].join else structure.to_s end end -
Dennis Hackethal revised this gist
May 4, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ def to_html structure elsif structure.is_a? Array tag = to_html structure[0] attrs = to_html structure[1] children = structure.drop(2).map { |s| to_html s }.join "<#{tag} #{attrs}>#{children}</#{tag}>" else -
Dennis Hackethal created this gist
May 4, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ def to_html structure if structure.is_a? Hash structure.reduce([]) do |acc, curr| acc + [[curr[0].to_s, '="', curr[1].to_s, '"'].join] end.join(' ') elsif structure.is_a? Array tag = to_html structure[0] attrs = to_html structure[1] children = structure.drop(2).map { |s| to_html s }.join() "<#{tag} #{attrs}>#{children}</#{tag}>" else structure.to_s end end # to_html [:html, {lang: 'en'}, [:h1, {class: 'heading big'}, 'some header']] # => "<html lang=\"en\"><h1 class=\"heading big\">some header</h1></html>"