Skip to content

Instantly share code, notes, and snippets.

@brandonmwest
Last active December 29, 2015 03:09
Show Gist options
  • Save brandonmwest/7605571 to your computer and use it in GitHub Desktop.
Save brandonmwest/7605571 to your computer and use it in GitHub Desktop.
module Jekyll
class ApiExample < Liquid::Block
def initialize(tag_name, markup, tokens)
attributes = markup.split
@identifier = attributes[0]
@http_method = attributes[1]
@url = attributes[2]
@data = attributes[3]
super
end
def render(context)
output = super
output = <<-HTML
{% xmljsontabs #{@identifier}%}
<div class="tab-content">
#{output}
</div>
HTML
end
end
class ResponseBlock < Liquid::Block
def initialize(tag_name, markup, tokens)
parameters = markup.split
if parameters[0]
@format = parameters[0].downcase
else
@format = "json"
end
super
end
def render(context)
output = super
active = @format == "json" ? "active" : ""
output = <<-HTML
<div class="tab-page #{active}" id="{{identifier}}-#{@format}">
<h3>Call</h3>
{% requestblock %}
{% requesturl {{http_method}} %}{{url}}.#{@format}{% endrequesturl %}
{% requestdata Data {{http_method}} %}{{data}}{% endrequestdata %}
{% endrequestblock %}
<h3>Response</h3>
{% codeblock lang:#{@format} %}
#{output}
{% endcodeblock %}
</div>
HTML
return Liquid::Template.parse(output).render context
end
end
end
Liquid::Template.register_tag('response', Jekyll::ResponseBlock)
Liquid::Template.register_tag('apiexample', Jekyll::ApiExample)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment