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



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

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



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

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



32
33
34
35
36
37
38
39
# File 'lib/dolt/sinatra/actions.rb', line 32

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



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

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



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

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.



26
27
28
29
30
# File 'lib/dolt/sinatra/actions.rb', line 26

def redirect(url)
  response.status = 302
  response["Location"] = url
  body ""
end

#refs(repo) ⇒ Object



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

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



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

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.class.to_s !~ /\bTree/
    response["Content-Type"] = "text/html"
    body(renderer.render(:tree, data))
  end
end

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



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

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