Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
feat: ✨ Allow svg in partial without passing "site: site" explicitly (#4
Browse files Browse the repository at this point in the history
)

* Adding parts to the test suite which borked for me

* When you don't pass site: site, it breaks

* Applying my fix

* run format

Co-authored-by: Andrew Mason <andrewmcodes@protonmail.com>
  • Loading branch information
MikeRogers0 and andrewmcodes committed Jul 20, 2020
1 parent b072c40 commit 542aea2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/bridgetown-inline-svg/svg-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def self.parse_params(markup)
matched = markup.strip.match(PATH_SYNTAX)
unless matched
raise SyntaxError, <<~END
Syntax Error in tag 'highlight' while parsing the following markup:
Syntax Error in tag 'svg' while parsing the following markup:
#{markup}
Valid syntax: svg <path> [property=value]
END
Expand Down Expand Up @@ -119,6 +119,7 @@ def render(context)
# check if given name is a variable. Otherwise use it as a file name
svg_file = Bridgetown.sanitized_path(site.source, interpolate(@svg, context))
return unless svg_file

add_file_to_dependency(site, svg_file, context)
# replace variables with their current value
params = split_params(@params, context)
Expand All @@ -128,15 +129,16 @@ def render(context)
end
# params = @params
file = File.open(svg_file, "rb").read
conf = lookup_variable(context, "site.svg")

conf = site.config["svg"] || {}

if conf["optimize"] == true
xml = SvgOptimizer.optimize(file, [create_plugin(params)] + PLUGINS)
SvgOptimizer.optimize(file, [create_plugin(params)] + PLUGINS)
else
xml = Nokogiri::XML(file)
params.each { |key, val| xml.root.set_attribute(key, val) }
xml = xml.root.to_xml
xml.root.to_xml
end
xml
end
end
end
3 changes: 3 additions & 0 deletions spec/fixtures/src/_components/navbar.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="component-navbar">
{% svg images/square.svg width="100" height="100" %}
</div>
3 changes: 3 additions & 0 deletions spec/fixtures/src/_components/partial.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="component-partial">
{% svg images/square.svg width="100" height="100" %}
</div>
6 changes: 6 additions & 0 deletions spec/fixtures/src/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
<body>
THIS IS MY LAYOUT
{{ content }}

{% render "navbar" site: site %}

<div id="layout">
{% svg images/square.svg width: 100 height: 100 %}
</div>
</body>
</html>
2 changes: 2 additions & 0 deletions spec/fixtures/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@
<div id="optimize">
{% svg /images/{{page.svgname}}.svg data-foo="" %}
</div>

{% render "partial" %}

0 comments on commit 542aea2

Please sign in to comment.