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



69
70
71
72
73
74
75
# File 'lib/dolt/sinatra/actions.rb', line 69

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



48
49
50
51
52
53
54
55
56
57
# File 'lib/dolt/sinatra/actions.rb', line 48

def blob(repo, ref, path, options = { :template => :blob, :content_type => "text/html" })
  actions.blob(repo, ref, path) do |err, data|
    return error(err, repo, ref) 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, repo, ref) ⇒ Object



31
32
33
34
35
36
37
38
# 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 => repo,
                         :ref => ref
                       }))
end

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



77
78
79
80
81
82
83
# File 'lib/dolt/sinatra/actions.rb', line 77

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

#raw(repo, ref, path) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/dolt/sinatra/actions.rb', line 40

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



85
86
87
88
89
90
91
# File 'lib/dolt/sinatra/actions.rb', line 85

def refs(repo)
  actions.refs(repo) do |err, data|
    return 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



59
60
61
62
63
64
65
66
67
# File 'lib/dolt/sinatra/actions.rb', line 59

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

#tree_history(repo, ref, path, count = 1) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/dolt/sinatra/actions.rb', line 93

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