Skip to content

Instantly share code, notes, and snippets.

@jahnertz
Last active February 2, 2020 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahnertz/0e26ddb9807c6e9c6f5253e67a1976dc to your computer and use it in GitHub Desktop.
Save jahnertz/0e26ddb9807c6e9c6f5253e67a1976dc to your computer and use it in GitHub Desktop.
module BootstrapLiquidTags
module Base
def initialize (tag_name, params_string, tokens)
super
bind_params(eval("{#{params_string}}"))
end
def markdown_converter
@context.registers[:site].find_converter_instance(::Jekyll::Converters::Markdown)
end
def id
@context.registers[:page].id.split('/').last.gsub('-','_').downcase
end
def category
@context.registers[:page]['cagegory']
end
end
class Block < Liquid::Block
include BootstrapLiquidTags::Base
def render (context)
@context = context
@text = super
internal_render
end
end
class BootstrapLiquidTags::Row < BootstrapLiquidTags::Block
def bind_params (params)
@class = params[:class]
end
def internal_render
<<~ROW
<div class="row #{@class}">
#{@text}
</div>
ROW
end
end
class BootstrapLiquidTags::Col < BootstrapLiquidTags::Block
def bind_params (params)
@class = params[:class]
end
def internal_render
<<~COL
<div class="col #{@class}">
#{@text}
</div>
COL
end
end
end
Liquid::Template.register_tag('row', BootstrapLiquidTags::Row)
Liquid::Template.register_tag('col', BootstrapLiquidTags::Col)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment