Class: Onebox::Engine::GithubBlobOnebox

Inherits:
Object
  • Object
show all
Includes:
Mixins::GitBlobOnebox
Defined in:
lib/onebox/engine/github_blob_onebox.rb

Constant Summary

Constants included from Mixins::GitBlobOnebox

Mixins::GitBlobOnebox::DEFAULTS, Mixins::GitBlobOnebox::EXPAND_AFTER, Mixins::GitBlobOnebox::EXPAND_BEFORE, Mixins::GitBlobOnebox::EXPAND_NONE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::GitBlobOnebox

included

Class Method Details

.git_regexpObject



8
9
10
# File 'lib/onebox/engine/github_blob_onebox.rb', line 8

def self.git_regexp
  /^https?:\/\/(www\.)?github\.com.*\/blob\//
end

.onebox_nameObject



11
12
13
# File 'lib/onebox/engine/github_blob_onebox.rb', line 11

def self.onebox_name
  "githubblob"
end

Instance Method Details

#raw_regexpObject



16
17
18
# File 'lib/onebox/engine/github_blob_onebox.rb', line 16

def raw_regexp
  /github\.com\/(?<user>[^\/]+)\/(?<repo>[^\/]+)\/blob\/(?<sha1>[^\/]+)\/(?<file>[^#]+)(#(L(?<from>[^-]*)(-L(?<to>.*))?))?/mi
end

#raw_template(m) ⇒ Object



19
20
21
# File 'lib/onebox/engine/github_blob_onebox.rb', line 19

def raw_template(m)
  "https://raw.githubusercontent.com/#{m[:user]}/#{m[:repo]}/#{m[:sha1]}/#{m[:file]}"
end

#titleObject



22
23
24
# File 'lib/onebox/engine/github_blob_onebox.rb', line 22

def title
  Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(/^https?\:\/\/github\.com\//, ''))
end