Created
September 7, 2014 23:13
-
-
Save nurinamu/4ccf7197a1bdfb0d7079 to your computer and use it in GitHub Desktop.
jekyll plugin for custom size img tag.
This file contains 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 characters
module Jekyll | |
class RenderImgTag < Liquid::Tag | |
def initialize(tag_name, text, tokens) | |
super | |
@url , *@val= text.split(/ /) | |
if @val.length > 0 | |
@width , *@height = @val[0].split(/x/) | |
end | |
@img_style = "width:#{@width}px;" | |
if @height.length > 0 | |
@img_style = @img_style + "height:#{@height[0]}px;" | |
end | |
end | |
def render(context) | |
"<img src=\"#{@url}\" style=\"#{@img_style}\">" | |
end | |
end | |
end | |
Liquid::Template.register_tag('img', Jekyll::RenderImgTag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment