lib/nanoc/toolbox/helpers/github_gist.rb
# Generates the script tag for the supplied Gist ID
# optionaly displays only the specified file
#
# @example
#   gist(1)
#   #=> <script src="https://gist.github.com/1.js"> </script>
#   gist(1, "gistfile1.txt")
#   #=> <script src="https://gist.github.com/1.js?file=gistfile1.txt"></script>
#
# @param [Integer] gist_id - the ID of the Gist
# @param [String] filename - the optional filename to display
Generates the script tag for the supplied Gist ID
optionaly displays only the specified file
Generates the script tag for the supplied Gist ID optionaly displays only the specified file
def gist(gist_id, filename=nil)
      raise ArgumentError, "Gist ID should be a hex number" unless (gist_id.to_s).match(/^\h+$/)
      url = "#{GIST_HOST}/#{gist_id}.#{GIST_EXT}"
      if filename
        raise ArgumentError, "Filename should be a string" unless filename.is_a? String
        url += "?file=#{filename}"
      end
      content_tag :script, "", :src => url
    end
def gist ( gist_id , filename = nil ) raise ArgumentError , "Gist ID should be a hex number" unless ( gist_id . to_s ) . match ( / ^ \h +$ / ) url = "#{GIST_HOST}/#{gist_id}.#{GIST_EXT}" if filename raise ArgumentError , "Filename should be a string" unless filename . is_a? String url += "?file=#{filename}" end content_tag :script , "" , :src => url end
Generates the script tag for the supplied Gist ID
optionaly displays only the specified file
Generates the script tag for the supplied Gist ID optionaly displays only the specified file
gist_id
filename
the optional filename to display
the optional filename to display
example
None