Module: Dolt::Sinatra::Actions
- Included in:
- Base
- Defined in:
- lib/dolt/sinatra/actions.rb
Instance Method Summary collapse
- #blame(repo, ref, path) ⇒ Object
- #blob(repo, ref, path, options = { :template => :blob, :content_type => "text/html" }) ⇒ Object
- #error(error, repo, ref) ⇒ Object
- #history(repo, ref, path, count) ⇒ Object
- #raw(repo, ref, path) ⇒ Object
-
#redirect(url) ⇒ Object
Built-in redirect seems to not work with Sinatra::Async, it throws an error.
- #refs(repo) ⇒ Object
- #tree(repo, ref, path) ⇒ Object
- #tree_history(repo, ref, path, count = 1) ⇒ Object
Instance Method Details
#blame(repo, ref, path) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/dolt/sinatra/actions.rb', line 88 def blame(repo, ref, path) actions.blame(repo, ref, path) do |err, data| next error(err, repo, ref) if !err.nil? response["Content-Type"] = "text/html" body(renderer.render(:blame, data)) end end |
#blob(repo, ref, path, options = { :template => :blob, :content_type => "text/html" }) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/dolt/sinatra/actions.rb', line 63 def blob(repo, ref, path, = { :template => :blob, :content_type => "text/html" }) actions.blob(repo, ref, path) do |err, data| next error(err, repo, ref) if !err.nil? blob = data[:blob] next redirect(tree_url(repo, ref, path)) if blob.class.to_s !~ /\bBlob/ response["Content-Type"] = [:content_type] = [:template_options] || {} body(renderer.render([:template], data, )) end end |
#error(error, repo, ref) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dolt/sinatra/actions.rb', line 31 def error(error, repo, ref) response["Content-Type"] = "text/html" body(renderer.render(:"500", { :error => error, :repository_slug => repo, :ref => ref })) rescue Exception => err err_backtrace = err.backtrace.map { |s| "<li>#{s}</li>" } error_backtrace = error.backtrace.map { |s| "<li>#{s}</li>" } body(<<-HTML) <h1>Fatal Dolt Error</h1> <p> Dolt encountered an exception, and additionally triggered another exception trying to render the error. </p> <h2>Error: #{err.class} #{err.}</h2> <ul>#{err_backtrace.join()}</ul> <h2>Original error: #{error.class} #{error.}</h2> <ul>#{error_backtrace.join()}</ul> HTML end |
#history(repo, ref, path, count) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/dolt/sinatra/actions.rb', line 96 def history(repo, ref, path, count) actions.history(repo, ref, path, count) do |err, data| next error(err, repo, ref) if !err.nil? response["Content-Type"] = "text/html" body(renderer.render(:commits, data)) end end |
#raw(repo, ref, path) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/dolt/sinatra/actions.rb', line 55 def raw(repo, ref, path) blob(repo, ref, path, { :template => :raw, :content_type => "text/plain", :template_options => { :layout => nil } }) end |
#redirect(url) ⇒ Object
Built-in redirect seems to not work with Sinatra::Async, it throws an error.
25 26 27 28 29 |
# File 'lib/dolt/sinatra/actions.rb', line 25 def redirect(url) response.status = 302 response["Location"] = url body "" end |
#refs(repo) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/dolt/sinatra/actions.rb', line 104 def refs(repo) actions.refs(repo) do |err, data| next error(err, repo, ref) if !err.nil? response["Content-Type"] = "application/json" body(renderer.render(:refs, data, :layout => nil)) end end |
#tree(repo, ref, path) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dolt/sinatra/actions.rb', line 74 def tree(repo, ref, path) actions.tree(repo, ref, path) do |err, data| begin next error(err, repo, ref) if !err.nil? tree = data[:tree] next redirect(blob_url(repo, ref, path)) if tree.class.to_s !~ /\bTree/ response["Content-Type"] = "text/html" body(renderer.render(:tree, data)) rescue Exception => err error(err, repo, ref) end end end |
#tree_history(repo, ref, path, count = 1) ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/dolt/sinatra/actions.rb', line 112 def tree_history(repo, ref, path, count = 1) actions.tree_history(repo, ref, path, count) do |err, data| if !err.nil? error(err, repo, ref) else response["Content-Type"] = "application/json" body(renderer.render(:tree_history, data, :layout => nil)) end end end |