Module: Webgit::Helpers
- Defined in:
- lib/webgit/helpers.rb
Constant Summary collapse
- EXT_WITH_LANGUAGE =
{ ru: :ruby, rb: :ruby, rake: :ruby, clj: :clojure, h: :c, py: :python, txt: :text, sh: :text, js: :java_script, htm: :html, yml: :yaml }
Instance Method Summary collapse
- #git_blob_path(branch, item) ⇒ Object
- #git_tree_path(branch, item) ⇒ Object
- #navigation(branch) ⇒ Object
- #preview(blob, format) ⇒ Object
- #preview_path(branch, path) ⇒ Object
- #show_path(oid, name = nil) ⇒ Object
- #upper_path(branch) ⇒ Object
- #webgit_path(branch, path) ⇒ Object
Instance Method Details
#git_blob_path(branch, item) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/webgit/helpers.rb', line 31 def git_blob_path(branch, item) if params[:splat] && params[:splat].first webgit_path(branch, "#{params[:splat].first}/#{item}") else webgit_path(branch, item) end end |
#git_tree_path(branch, item) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/webgit/helpers.rb', line 23 def git_tree_path(branch, item) if params[:splat] && params[:splat].first webgit_path(branch, "#{params[:splat].first}/#{item}") else webgit_path(branch, item) end end |
#navigation(branch) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/webgit/helpers.rb', line 5 def (branch) paths = if params[:splat] && params[:splat].first params[:splat].first.split('/') else [] end i = -1 nav = paths.map do|p| i += 1 if i < paths.length - 1 "<a href=#{webgit_path(branch, paths[0..i].join('/'))}>#{p}</a>" else p end end.join(" / ") nav end |
#preview(blob, format) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/webgit/helpers.rb', line 78 def preview(blob, format) f = format_to_sym(format) path = params[:splat].first case f when :html, :htm then "<div>#{blob.content}</div>" when :ruby, :java, :java_script, :python, :scss, :php, :lua, :html, :json, :go, :sql, :yaml, :text, :coffee then CodeRay.scan(blob.content.force_encoding('UTF-8'), f).div(:line_numbers => :table, :css => :class) when :png, :jpg, :gif then "<img src=\"#{preview_path(@branch.name, path)}\" />" when '.pdf' then "<iframe src=\"#{preview_path(@branch.name, path)}\" width='860' height='800' border='0' style='border:none'></iframe>" else "Binary File <#{path}>" end end |
#preview_path(branch, path) ⇒ Object
43 44 45 |
# File 'lib/webgit/helpers.rb', line 43 def preview_path(branch, path) "/preview/#{branch}/#{path}" end |
#show_path(oid, name = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/webgit/helpers.rb', line 47 def show_path(oid, name = nil) if (name) "/objects/#{oid}/show?name=#{name}" else "/objects/#{oid}/show" end end |
#upper_path(branch) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/webgit/helpers.rb', line 55 def upper_path(branch) path_url = ""; if params[:splat] && params[:splat].first paths = params[:splat].first.split("/") path_url = paths.tap{|paths| paths.pop }.join("/") end webgit_path(branch, path_url) end |
#webgit_path(branch, path) ⇒ Object
39 40 41 |
# File 'lib/webgit/helpers.rb', line 39 def webgit_path(branch, path) "/#{branch}/#{path}" end |