Sha256: 5a54fee3229ec3a39b2e901bac74096c00cff78ce7bc487dece664da2e2d127d

Contents?: true

Size: 724 Bytes

Versions: 15

Compression:

Stored size: 724 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_regexp Regexp.new("^http(?:s)?://gist\\.(?:(?:\\w)+\\.)?(github)\\.com(?:/)?")

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

      def to_html
        "<script src=\"//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

15 entries across 15 versions & 1 rubygems

Version Path
onebox-1.5.5 lib/onebox/engine/github_gist_onebox.rb
onebox-1.5.3 lib/onebox/engine/github_gist_onebox.rb
onebox-1.5.2 lib/onebox/engine/github_gist_onebox.rb
onebox-1.5.1 lib/onebox/engine/github_gist_onebox.rb
onebox-1.5.0 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.9 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.8 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.7 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.5 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.4 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.3 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.2 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.1 lib/onebox/engine/github_gist_onebox.rb
onebox-1.4.0 lib/onebox/engine/github_gist_onebox.rb
onebox-1.3.9 lib/onebox/engine/github_gist_onebox.rb