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
Constant Summary collapse
- GIST_HOST =
GIST script base URL
"https://gist.github.com"
- GIST_EXT =
"js"
Instance Method Summary collapse
-
#gist(gist_id, filename = nil) ⇒ Object
Generates the script tag for the supplied Gist ID optionaly displays only the specified file.
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
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 content_tag :script, "", :src => url end |