Module: Dolt::Sinatra::Actions

Included in:
Base
Defined in:
lib/dolt/sinatra/actions.rb

Instance Method Summary collapse

Instance Method Details

#blame(repo, ref, path) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/dolt/sinatra/actions.rb', line 65

def blame(repo, ref, path)
  actions.blame(repo, ref, path) do |err, data|
    return error(err) 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



44
45
46
47
48
49
50
51
52
53
# File 'lib/dolt/sinatra/actions.rb', line 44

def blob(repo, ref, path, options = { :template => :blob, :content_type => "text/html" })
  actions.blob(repo, ref, path) do |err, data|
    return error(err) if !err.nil?
    blob = data[:blob]
    return redirect(tree_url(repo, ref, path)) if !blob.is_a?(Rugged::Blob)
    response["Content-Type"] = options[:content_type]
    tpl_options = options[:template_options] || {}
    body(renderer.render(options[:template], data, tpl_options))
  end
end

#error(error) ⇒ Object



31
32
33
34
# File 'lib/dolt/sinatra/actions.rb', line 31

def error(error)
  response["Content-Type"] = "text/plain"
  body("Process failed with exit code #{error.exit_code}:\n#{error.message}")
end

#history(repo, ref, path, count) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/dolt/sinatra/actions.rb', line 73

def history(repo, ref, path, count)
  actions.history(repo, ref, path, count) do |err, data|
    return error(err) if !err.nil?
    response["Content-Type"] = "text/html"
    body(renderer.render(:commits, data))
  end
end

#raw(repo, ref, path) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/dolt/sinatra/actions.rb', line 36

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



81
82
83
84
85
86
87
# File 'lib/dolt/sinatra/actions.rb', line 81

def refs(repo)
  actions.refs(repo) do |err, data|
    return error(err) if !err.nil?
    response["Content-Type"] = "application/json"
    body(renderer.render(:refs, data, :layout => nil))
  end
end

#tree(repo, ref, path) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/dolt/sinatra/actions.rb', line 55

def tree(repo, ref, path)
  actions.tree(repo, ref, path) do |err, data|
    return error(err) if !err.nil?
    tree = data[:tree]
    return redirect(blob_url(repo, ref, path)) if !tree.is_a?(Rugged::Tree)
    response["Content-Type"] = "text/html"
    body(renderer.render(:tree, data))
  end
end