Module: Dolt::View::Blob
- Included in:
- Sinatra::MultiRepoBrowser, Sinatra::SingleRepoBrowser
- Defined in:
- lib/dolt/view/blob.rb
Instance Method Summary collapse
- #binary?(content) ⇒ Boolean
- #blame_url(repository, ref, path) ⇒ Object
- #blob_url(repository, ref, path) ⇒ Object
- #entityfy(content) ⇒ Object
- #format_binary_blob(path, content, repository = nil, ref = nil) ⇒ Object
- #format_blob(path, content, repo = nil, ref = nil) ⇒ Object
- #format_text_blob(path, content, repository = nil, ref = nil) ⇒ Object
- #format_whitespace(text) ⇒ Object
- #history_url(repository, ref, path) ⇒ Object
- #link_binary_blob(path, content, repository = nil, ref = nil) ⇒ Object
- #multiline(blob, options = {}) ⇒ Object
- #raw_url(repository, ref, path) ⇒ Object
Instance Method Details
#binary?(content) ⇒ Boolean
23 24 25 |
# File 'lib/dolt/view/blob.rb', line 23 def binary?(content) !content[0...(content.length-1)].index("\000").nil? end |
#blame_url(repository, ref, path) ⇒ Object
58 59 60 |
# File 'lib/dolt/view/blob.rb', line 58 def blame_url(repository, ref, path) repo_url(repository, "/blame/#{ref}:#{path}") end |
#blob_url(repository, ref, path) ⇒ Object
54 55 56 |
# File 'lib/dolt/view/blob.rb', line 54 def blob_url(repository, ref, path) repo_url(repository, "/blob/#{ref}:#{path}") end |
#entityfy(content) ⇒ Object
27 28 29 30 |
# File 'lib/dolt/view/blob.rb', line 27 def entityfy(content) @coder ||= HTMLEntities.new @coder.encode(content) end |
#format_binary_blob(path, content, repository = nil, ref = nil) ⇒ Object
37 38 39 |
# File 'lib/dolt/view/blob.rb', line 37 def format_binary_blob(path, content, repository = nil, ref = nil) link_binary_blob(path, content, repository, ref) end |
#format_blob(path, content, repo = nil, ref = nil) ⇒ Object
32 33 34 35 |
# File 'lib/dolt/view/blob.rb', line 32 def format_blob(path, content, repo = nil, ref = nil) return format_binary_blob(path, content, repo, ref) if binary?(content) format_text_blob(path, content, repo, ref) end |
#format_text_blob(path, content, repository = nil, ref = nil) ⇒ Object
50 51 52 |
# File 'lib/dolt/view/blob.rb', line 50 def format_text_blob(path, content, repository = nil, ref = nil) multiline(entityfy(content)) end |
#format_whitespace(text) ⇒ Object
70 71 72 |
# File 'lib/dolt/view/blob.rb', line 70 def format_whitespace(text) text end |
#history_url(repository, ref, path) ⇒ Object
62 63 64 |
# File 'lib/dolt/view/blob.rb', line 62 def history_url(repository, ref, path) repo_url(repository, "/history/#{ref}:#{path}") end |
#link_binary_blob(path, content, repository = nil, ref = nil) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/dolt/view/blob.rb', line 41 def link_binary_blob(path, content, repository = nil, ref = nil) <<-HTML <p class="prettyprint"> The content you're attempting to browse appears to be binary. <a href="#{raw_url(repository, ref, path)}">Download #{File.basename(path)}</a>. </p> HTML end |
#multiline(blob, options = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dolt/view/blob.rb', line 74 def multiline(blob, = {}) class_names = [:class_names] || [] class_names << "prettyprint" << "linenums" num = 0 lines = blob.split("\n").inject("") do |html, line| num += 1 # Empty elements causes annoying rendering artefacts # Forcing one space on each line affects copy-paste negatively # TODO: Don't force one space, find CSS fix line = format_whitespace(line).sub(/^$/, " ") "#{html}<li class=\"L#{num}\"><span class=\"line\">#{line}</span></li>" end "<pre class=\"#{class_names.join(' ')}\">" + "<ol class=\"linenums\">#{lines}</ol></pre>" end |
#raw_url(repository, ref, path) ⇒ Object
66 67 68 |
# File 'lib/dolt/view/blob.rb', line 66 def raw_url(repository, ref, path) repo_url(repository, "/raw/#{ref}:#{path}") end |