Class: Onebox::Engine::GithubBlobOnebox

Inherits:
Object
  • Object
show all
Includes:
Mixins::GitBlobOnebox, Mixins::GithubAuthHeader
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

Methods included from Mixins::GithubAuthHeader

#github_auth_header

Class Method Details

.git_regexpObject



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

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

.onebox_nameObject



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

def self.onebox_name
  "githubblob"
end

Instance Method Details

#auth_headers(match) ⇒ Object



42
43
44
# File 'lib/onebox/engine/github_blob_onebox.rb', line 42

def auth_headers(match)
  github_auth_header(match[:org])
end

#i18nObject



21
22
23
24
25
26
27
28
# File 'lib/onebox/engine/github_blob_onebox.rb', line 21

def i18n
  {
    binary_file: I18n.t("onebox.github.binary_file"),
    truncated_file: I18n.t("onebox.github.truncated_file"),
    show_original: I18n.t("onebox.github.show_original"),
    requires_iframe: I18n.t("onebox.github.requires_iframe"),
  }
end

#raw_regexpObject



30
31
32
# File 'lib/onebox/engine/github_blob_onebox.rb', line 30

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

#raw_template(match) ⇒ Object



34
35
36
# File 'lib/onebox/engine/github_blob_onebox.rb', line 34

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

#titleObject



38
39
40
# File 'lib/onebox/engine/github_blob_onebox.rb', line 38

def title
  Sanitize.fragment(Onebox::Helpers.uri_unencode(link).sub(%r{^https?\://github\.com/}, ""))
end