public
Last active

Jekyll Dev Only Tag

  • Download Gist
devonly_tag.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#
# Jekyll Dev Only Tag
#
# Author : Colin Kennedy
# Usage :
#
# The markup/script/css included within the `devonly` tags
# is included in the rendered page when either:
#
# * `server` mode is used
# * A top level `dev` key is `true` in `_config.yml`
#
# Examples:
#
# For dealing with something like Disqus:
#
# <script>
# dosomedisqusstuff();
#
# {% devonly %}
# var developer = 1;
# {% enddevonly %}
# </script>
#
# Include a debug script tag:
#
# {% devonly %}
# <script type="text/javascript" src="/js/somescript.js"></script>
# {% enddevonly %}
#
#
# It can also be used to see if it's dev mode from another
# plugin.
#
 
module Jekyll
 
class DevOnlyTag < Liquid::Block
 
def render(context)
if DevOnlyTag.dev?(context)
super(context)
end
end
 
def self.dev?(context)
# Compatible with both Jekyll v1 and older config styles
if context.registers[:site].config['server'] ||
context.registers[:site].config['serving']
return true
end
 
if context.registers[:site].config.key?('dev')
return context.registers[:site].config['dev'] ? true : false
end
 
false
end
 
end
end
 
Liquid::Template.register_tag('devonly', Jekyll::DevOnlyTag)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.