Module: UltraMarkdown::Filter::GistTag

Included in:
SyntaxConverter
Defined in:
lib/ultra_markdown/filter/gist_tag.rb

Instance Method Summary collapse

Instance Method Details

#gist_tag(input) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ultra_markdown/filter/gist_tag.rb', line 12

def gist_tag(input)
  input.gsub!(/^\{\% *gist ([^\n\}]+)\%\}/m) do
    markup = $1

    if markup =~ /([a-zA-Z\d]*) (.*)/
      gist = $1
      file = $2.strip if $2

      script_url = script_url_for(gist, file)

      "<script src='#{script_url}'> </script>"
    end

  end
end

#script_url_for(gist_id, filename) ⇒ Object



6
7
8
9
10
# File 'lib/ultra_markdown/filter/gist_tag.rb', line 6

def script_url_for(gist_id, filename)
  url = "https://gist.github.com/#{gist_id}.js"
  url = "#{url}?file=#{filename}" unless filename.nil? or filename.empty?
  url
end