Module: Nanoc::Toolbox::Helpers::GithubGist

Includes:
HtmlTag
Defined in:
lib/nanoc/toolbox/helpers/github_gist.rb

Overview

NANOC Helper for Github Gists

This module contains helper functions to embed gists to your content

See Also:

Author:

Constant Summary collapse

GIST_HOST =

GIST script base URL

"https://gist.github.com"
GIST_EXT =
"js"

Instance Method Summary collapse

Methods included from HtmlTag

#content_tag, #tag, #tag_options

Instance Method Details

#gist(gist_id, filename = nil) ⇒ Object

Generates the script tag for the supplied Gist ID optionaly displays only the specified file

Examples:

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>

Parameters:

  • gist_id (Integer)
    • the ID of the Gist

  • filename (String) (defaults to: nil)
    • the optional filename to display

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nanoc/toolbox/helpers/github_gist.rb', line 28

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

   :script, "", :src => url
end