Class: Jekyll::SvgTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::SvgTag
- Defined in:
- lib/jekyll-svg-plugin.rb
Instance Method Summary collapse
-
#initialize(tag_name, svg, tokens) ⇒ SvgTag
constructor
A new instance of SvgTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, svg, tokens) ⇒ SvgTag
Returns a new instance of SvgTag.
37 38 39 40 |
# File 'lib/jekyll-svg-plugin.rb', line 37 def initialize( tag_name, svg, tokens ) super @svg = svg.strip end |
Instance Method Details
#render(context) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jekyll-svg-plugin.rb', line 42 def render(context) png = @svg.sub( /(\.svg)$/, '.png' ) png_file = png # png file is relative to this page, if relative unless png_file =~ %r{^/} png_file = File.join( File.dirname( context[ 'page' ][ 'url' ] ), png ) end # And found in the site source png_file = File.join( context.registers[ :site ].source, png_file ) w,h = open( png_file, 'rb' ) do |fpng| ImageSize.new( fpng.read ).size end <<END <div class="svg-object"> <object data="#{@svg}" type="image/svg+xml" width="#{w}" height="#{h}"> <img src="#{png}" width="#{w}" height="#{h}" /> </object> </div> END end |