Sha256: c33818d6059743c8e2bda6f834dc99335032ab239ae73d5882ec8eb8f73f863b

Contents?: true

Size: 742 Bytes

Versions: 4

Compression:

Stored size: 742 Bytes

Contents

# This is broken, document.write is only allowed on load
# See: http://stackoverflow.com/questions/9154026/jquery-dynamically-load-a-gist-embed
module Onebox
  module Engine
    class GithubGistOnebox
      include Engine

      matches do
        http
        with("gist.")
        domain("github")
        tld("com")
      end

      def url
        "https://api.github.com/gists/#{match[:sha]}"
      end

      def to_html
        "<script src=\"http://gist.github.com/#{match[:sha]}.js\"></script>"
      end

      private

      def data
        { sha: match[:sha], title: match[:sha], link: @url }
      end

      def match
        @match ||= @url.match(%r{gist\.github\.com/([^/]+/)?(?<sha>[0-9a-f]+)})
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
onebox-1.3.0 lib/onebox/engine/github_gist_onebox.rb
onebox-1.2.9 lib/onebox/engine/github_gist_onebox.rb
onebox-1.2.8 lib/onebox/engine/github_gist_onebox.rb
onebox-1.2.7 lib/onebox/engine/github_gist_onebox.rb