Class: Onebox::Engine::GitlabBlobOnebox

Inherits:
Object
  • Object
show all
Includes:
Mixins::GitBlobOnebox
Defined in:
lib/onebox/engine/gitlab_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/gitlab_blob_onebox.rb', line 8

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

.onebox_nameObject



12
13
14
# File 'lib/onebox/engine/gitlab_blob_onebox.rb', line 12

def self.onebox_name
  "gitlabblob"
end

Instance Method Details

#auth_headers(_match) ⇒ Object



37
38
39
# File 'lib/onebox/engine/gitlab_blob_onebox.rb', line 37

def auth_headers(_match)
  {}
end

#i18nObject



18
19
20
21
22
23
# File 'lib/onebox/engine/gitlab_blob_onebox.rb', line 18

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

#raw_regexpObject



25
26
27
# File 'lib/onebox/engine/gitlab_blob_onebox.rb', line 25

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

#raw_template(m) ⇒ Object



29
30
31
# File 'lib/onebox/engine/gitlab_blob_onebox.rb', line 29

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

#titleObject



33
34
35
# File 'lib/onebox/engine/gitlab_blob_onebox.rb', line 33

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