Module: Dolt::Sinatra::Actions
- Included in:
- Base
- Defined in:
- lib/dolt/sinatra/actions.rb
Instance Method Summary collapse
- #blame(repo, ref, path, custom_data = {}) ⇒ Object
- #blob(repo, ref, path, custom_data = {}, options = { :template => :blob }) ⇒ Object
- #error(error, repo, ref) ⇒ Object
- #history(repo, ref, path, count, custom_data = {}) ⇒ Object
- #raw(repo, ref, path, custom_data = {}) ⇒ Object
- #redirect(url) ⇒ Object
- #refs(repo, custom_data = {}) ⇒ Object
- #resolve_repository(repo) ⇒ Object
- #tree(repo, ref, path, custom_data = {}) ⇒ Object
- #tree_entry(repo, ref, path, custom_data = {}) ⇒ Object
- #tree_history(repo, ref, path, count = 1, custom_data = {}) ⇒ Object
Instance Method Details
#blame(repo, ref, path, custom_data = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/dolt/sinatra/actions.rb', line 109 def blame(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(blame_url(repo, oid, path)) and return end data = (custom_data || {}).merge(actions.blame(repo, u(ref), path)) add_headers(response, :ref => ref) body(renderer.render(:blame, data)) rescue Exception => err error(err, repo, ref) end |
#blob(repo, ref, path, custom_data = {}, options = { :template => :blob }) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/dolt/sinatra/actions.rb', line 68 def blob(repo, ref, path, custom_data = {}, = { :template => :blob }) if oid = lookup_ref_oid(repo, ref) redirect(blob_url(repo, oid, path)) and return end data = (custom_data || {}).merge(actions.blob(repo, u(ref), path)) blob = data[:blob] return redirect(tree_url(repo, ref, path)) if blob.class.to_s !~ /\bBlob/ add_headers(response, .merge(:ref => ref)) = [:template_options] || {} body(renderer.render([:template], data, )) rescue Exception => err error(err, repo, ref) 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 54 |
# File 'lib/dolt/sinatra/actions.rb', line 31 def error(error, repo, ref) template = error.class.to_s == "Rugged::IndexerError" ? :"404" : :"500" add_headers(response) body(renderer.render(template, { :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, custom_data = {}) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/dolt/sinatra/actions.rb', line 121 def history(repo, ref, path, count, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(history_url(repo, oid, path)) and return end data = (custom_data || {}).merge(actions.history(repo, u(ref), path, count)) add_headers(response, :ref => ref) body(renderer.render(:commits, data)) rescue Exception => err error(err, repo, ref) end |
#raw(repo, ref, path, custom_data = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dolt/sinatra/actions.rb', line 56 def raw(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(raw_url(repo, oid, path)) and return end blob(repo, ref, path, custom_data, { :template => :raw, :content_type => "text/plain", :template_options => { :layout => nil } }) end |
#redirect(url) ⇒ Object
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, custom_data = {}) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/dolt/sinatra/actions.rb', line 133 def refs(repo, custom_data = {}) data = (custom_data || {}).merge(actions.refs(repo)) add_headers(response, :content_type => "application/json") body(renderer.render(:refs, data, :layout => nil)) rescue Exception => err error(err, repo, nil) end |
#resolve_repository(repo) ⇒ Object
153 154 155 156 |
# File 'lib/dolt/sinatra/actions.rb', line 153 def resolve_repository(repo) @cache ||= {} @cache[repo] ||= actions.resolve_repository(repo) end |
#tree(repo, ref, path, custom_data = {}) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/dolt/sinatra/actions.rb', line 83 def tree(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(tree_url(repo, oid, path)) and return end data = (custom_data || {}).merge(actions.tree(repo, u(ref), path)) tree = data[:tree] return redirect(blob_url(repo, ref, path)) if tree.class.to_s !~ /\bTree/ add_headers(response, :ref => ref) body(renderer.render(:tree, data)) rescue Exception => err error(err, repo, ref) end |
#tree_entry(repo, ref, path, custom_data = {}) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dolt/sinatra/actions.rb', line 97 def tree_entry(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(tree_entry_url(repo, oid, path)) and return end data = (custom_data || {}).merge(actions.tree_entry(repo, u(ref), path)) add_headers(response, :ref => ref) body(renderer.render(data.key?(:tree) ? :tree : :blob, data)) rescue Exception => err error(err, repo, ref) end |
#tree_history(repo, ref, path, count = 1, custom_data = {}) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/dolt/sinatra/actions.rb', line 141 def tree_history(repo, ref, path, count = 1, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(tree_history_url(repo, oid, path)) and return end data = (custom_data || {}).merge(actions.tree_history(repo, u(ref), path, count)) add_headers(response, :content_type => "application/json", :ref => ref) body(renderer.render(:tree_history, data, :layout => nil)) rescue Exception => err error(err, repo, ref) end |