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
- #history(repo, ref, path, count, custom_data = {}) ⇒ Object
- #lookup_ref_oid(repo, ref) ⇒ Object
- #raw(repo, ref, path, custom_data = {}) ⇒ Object
- #redirect(url, status = 302) ⇒ Object
- #refs(repo, custom_data = {}) ⇒ Object
- #render_error(error, repo, ref, 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
116 117 118 119 120 121 122 123 124 |
# File 'lib/dolt/sinatra/actions.rb', line 116 def blame(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(blame_url(repo, oid, path), 307) and return end data = (custom_data || {}).merge(actions.blame(repo, u(ref), path)) add_headers(response, :ref => ref) body(renderer.render(:blame, data)) end |
#blob(repo, ref, path, custom_data = {}, options = { :template => :blob }) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/dolt/sinatra/actions.rb', line 81 def blob(repo, ref, path, custom_data = {}, = { :template => :blob }) if oid = lookup_ref_oid(repo, ref) redirect(blob_url(repo, oid, path), 307) 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, )) end |
#history(repo, ref, path, count, custom_data = {}) ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/dolt/sinatra/actions.rb', line 126 def history(repo, ref, path, count, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(history_url(repo, oid, path), 307) and return end data = (custom_data || {}).merge(actions.history(repo, u(ref), path, count)) add_headers(response, :ref => ref) body(renderer.render(:commits, data)) end |
#lookup_ref_oid(repo, ref) ⇒ Object
157 158 159 160 |
# File 'lib/dolt/sinatra/actions.rb', line 157 def lookup_ref_oid(repo, ref) return if !respond_to?(:redirect_refs?) || !redirect_refs? || ref.length == 40 actions.rev_parse_oid(repo, ref) end |
#raw(repo, ref, path, custom_data = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dolt/sinatra/actions.rb', line 69 def raw(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(raw_url(repo, oid, path), 307) and return end blob(repo, ref, path, custom_data, { :template => :raw, :content_type => "text/plain", :template_options => { :layout => nil } }) end |
#redirect(url, status = 302) ⇒ Object
25 26 27 28 29 |
# File 'lib/dolt/sinatra/actions.rb', line 25 def redirect(url, status = 302) response.status = status response["Location"] = url body "" end |
#refs(repo, custom_data = {}) ⇒ Object
136 137 138 139 140 |
# File 'lib/dolt/sinatra/actions.rb', line 136 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)) end |
#render_error(error, repo, ref, data = {}) ⇒ 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 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dolt/sinatra/actions.rb', line 31 def render_error(error, repo, ref, data = {}) if error.class.to_s == "Rugged::ReferenceError" && ref == "HEAD" return body(renderer.render("empty", { :repository => repo, :ref => ref }.merge(data))) end template = error.class.to_s == "Rugged::IndexerError" ? :"404" : :"500" add_headers(response) body(renderer.render(template, { :error => error, :repository_slug => repo, :ref => ref }.merge(data))) 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> <p>Tried to render the #{template} template with the following data:</p> <dl> <dt>Repository</dt> <dd>#{repo}</dd> <dt>Ref</dt> <dd>#{ref}</dd> </dl> <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 |
#resolve_repository(repo) ⇒ Object
152 153 154 155 |
# File 'lib/dolt/sinatra/actions.rb', line 152 def resolve_repository(repo) @cache ||= {} @cache[repo] ||= actions.resolve_repository(repo) end |
#tree(repo, ref, path, custom_data = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dolt/sinatra/actions.rb', line 94 def tree(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(tree_url(repo, oid, path), 307) 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)) end |
#tree_entry(repo, ref, path, custom_data = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/dolt/sinatra/actions.rb', line 106 def tree_entry(repo, ref, path, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(tree_entry_url(repo, oid, path), 307) 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)) end |
#tree_history(repo, ref, path, count = 1, custom_data = {}) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/dolt/sinatra/actions.rb', line 142 def tree_history(repo, ref, path, count = 1, custom_data = {}) if oid = lookup_ref_oid(repo, ref) redirect(tree_history_url(repo, oid, path), 307) 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)) end |