gitdocs 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/gitdocs.gemspec +1 -0
- data/lib/gitdocs/public/css/app.css +15 -9
- data/lib/gitdocs/runner.rb +3 -9
- data/lib/gitdocs/server.rb +10 -4
- data/lib/gitdocs/version.rb +1 -1
- data/lib/gitdocs.rb +8 -6
- data/test/configuration_test.rb +1 -1
- data/test/test_helper.rb +2 -26
- metadata +20 -9
data/gitdocs.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_dependency 'sqlite3', "~> 1.3.4"
|
32
32
|
s.add_dependency 'activerecord', "~> 3.1.0"
|
33
33
|
s.add_dependency 'grit', "~> 2.4.1"
|
34
|
+
s.add_dependency 'shell_tools', "~> 0.1.0"
|
34
35
|
|
35
36
|
s.add_development_dependency 'minitest', "~> 2.6.1"
|
36
37
|
s.add_development_dependency 'rake'
|
@@ -4,14 +4,14 @@ body {
|
|
4
4
|
font-family: Helvetica, Arial, Verdana;
|
5
5
|
}
|
6
6
|
|
7
|
-
|
7
|
+
h1, h2 {
|
8
8
|
margin: 0;
|
9
9
|
padding-bottom: 0.8em;
|
10
10
|
font-weight: bold;
|
11
11
|
}
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
h1 { font-size: 1.8em; }
|
14
|
+
h2 { font-size: 1.5em; margin-top: 0.2em; }
|
15
15
|
|
16
16
|
.nav h1 {
|
17
17
|
text-align: center;
|
@@ -47,7 +47,7 @@ div.share input {
|
|
47
47
|
width :100%;
|
48
48
|
}
|
49
49
|
|
50
|
-
|
50
|
+
.container {
|
51
51
|
min-width: 700px;
|
52
52
|
background: #FCEA97;
|
53
53
|
border-style: solid;
|
@@ -58,21 +58,27 @@ body .container {
|
|
58
58
|
margin-top: 1.2em;
|
59
59
|
}
|
60
60
|
|
61
|
-
|
62
|
-
|
61
|
+
.container .inline-file {
|
62
|
+
width:100%;
|
63
|
+
min-height: 600px;
|
64
|
+
background: white;
|
65
|
+
}
|
66
|
+
|
67
|
+
a { text-decoration: none; color: #33e; }
|
68
|
+
a:hover { text-decoration: underline; }
|
63
69
|
|
64
|
-
|
70
|
+
#editor {
|
65
71
|
position: relative;
|
66
72
|
width: 700px;
|
67
73
|
height: 600px;
|
68
74
|
margin-bottom: 1em;
|
69
75
|
}
|
70
76
|
|
71
|
-
|
77
|
+
form.upload, form.add {
|
72
78
|
padding-top: 1.4em;
|
73
79
|
}
|
74
80
|
|
75
|
-
|
81
|
+
form.upload p, form.add p {
|
76
82
|
padding-bottom: 0.6em;
|
77
83
|
font-weight: bold;
|
78
84
|
}
|
data/lib/gitdocs/runner.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Gitdocs
|
2
2
|
class Runner
|
3
|
+
include ShellTools
|
4
|
+
|
3
5
|
attr_reader :root, :listener
|
4
6
|
|
5
7
|
def initialize(share)
|
@@ -148,18 +150,10 @@ module Gitdocs
|
|
148
150
|
(val.nil? || val.empty?) ? default : val
|
149
151
|
end
|
150
152
|
|
151
|
-
def sh(cmd)
|
152
|
-
out, code = sh_with_code(cmd)
|
153
|
-
code == 0 ? out : raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
|
154
|
-
end
|
155
|
-
|
156
153
|
# Run in shell, return both status and output
|
157
154
|
# @see #sh
|
158
155
|
def sh_with_code(cmd)
|
159
|
-
cmd
|
160
|
-
outbuf = ''
|
161
|
-
outbuf = `cd "#{@root}" && #{cmd}`
|
162
|
-
[outbuf, $?]
|
156
|
+
ShellTools.sh_with_code(cmd, @root)
|
163
157
|
end
|
164
158
|
end
|
165
159
|
end
|
data/lib/gitdocs/server.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'thin'
|
2
2
|
require 'renee'
|
3
3
|
require 'coderay'
|
4
|
+
require 'uri'
|
4
5
|
|
5
6
|
module Gitdocs
|
6
7
|
class Server
|
@@ -37,7 +38,7 @@ module Gitdocs
|
|
37
38
|
var :int do |idx|
|
38
39
|
gd = gds[idx]
|
39
40
|
halt 404 if gd.nil?
|
40
|
-
file_path = request.path_info
|
41
|
+
file_path = URI.unescape(request.path_info)
|
41
42
|
file_ext = File.extname(file_path)
|
42
43
|
expanded_path = File.expand_path(".#{file_path}", gd.root)
|
43
44
|
halt 400 unless expanded_path[/^#{Regexp.quote(gd.root)}/]
|
@@ -45,7 +46,8 @@ module Gitdocs
|
|
45
46
|
parent = '' if parent == '/'
|
46
47
|
parent = nil if parent == '.'
|
47
48
|
locals = {:idx => idx, :parent => parent, :root => gd.root, :file_path => expanded_path}
|
48
|
-
mode, mime = request.params['mode'], `file -I #{expanded_path}`.strip
|
49
|
+
mode, mime = request.params['mode'], `file -I #{ShellTools.escape(expanded_path)}`.strip
|
50
|
+
puts "mode, mime: #{mode.inspect}, #{mime.inspect}"
|
49
51
|
if mode == 'save' # Saving
|
50
52
|
File.open(expanded_path, 'w') { |f| f.print request.params['data'] }
|
51
53
|
redirect! "/" + idx.to_s + file_path
|
@@ -65,11 +67,15 @@ module Gitdocs
|
|
65
67
|
elsif mode == 'edit' && mime.match(%r{text/}) # edit file
|
66
68
|
contents = File.read(expanded_path)
|
67
69
|
render! "edit", :layout => 'app', :locals => locals.merge(:contents => contents)
|
68
|
-
elsif mode != 'raw'
|
70
|
+
elsif mode != 'raw' # render file
|
69
71
|
begin # attempting to render file
|
70
72
|
contents = '<div class="tilt">' + Tilt.new(expanded_path).render + '</div>'
|
71
73
|
rescue RuntimeError => e # not tilt supported
|
72
|
-
contents =
|
74
|
+
contents = if mime.match(%r{text/})
|
75
|
+
'<pre class="CodeRay">' + CodeRay.scan_file(expanded_path).encode(:html) + '</pre>'
|
76
|
+
else
|
77
|
+
%|<embed class="inline-file" src="/#{idx}#{request.path_info}?mode=raw"></embed>|
|
78
|
+
end
|
73
79
|
end
|
74
80
|
render! "file", :layout => 'app', :locals => locals.merge(:contents => contents)
|
75
81
|
else # other file
|
data/lib/gitdocs/version.rb
CHANGED
data/lib/gitdocs.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
require 'gitdocs/version'
|
2
|
-
require 'gitdocs/configuration'
|
3
|
-
require 'gitdocs/runner'
|
4
|
-
require 'gitdocs/server'
|
5
|
-
require 'gitdocs/cli'
|
6
|
-
require 'gitdocs/manager'
|
7
1
|
require 'thread'
|
8
2
|
require 'rb-fsevent'
|
9
3
|
require 'growl'
|
10
4
|
require 'yajl'
|
11
5
|
require 'dante'
|
12
6
|
require 'socket'
|
7
|
+
require 'shell_tools'
|
8
|
+
|
9
|
+
require 'gitdocs/version'
|
10
|
+
require 'gitdocs/configuration'
|
11
|
+
require 'gitdocs/runner'
|
12
|
+
require 'gitdocs/server'
|
13
|
+
require 'gitdocs/cli'
|
14
|
+
require 'gitdocs/manager'
|
13
15
|
|
14
16
|
module Gitdocs
|
15
17
|
|
data/test/configuration_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.expand_path('../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
describe "gitdocs configuration" do
|
4
4
|
before do
|
5
|
-
|
5
|
+
ShellTools.capture { @config = Gitdocs::Configuration.new("/tmp/gitdocs") }
|
6
6
|
end
|
7
7
|
|
8
8
|
it "has sensible default config root" do
|
data/test/test_helper.rb
CHANGED
@@ -11,38 +11,14 @@ FakeWeb.allow_net_connect = false
|
|
11
11
|
## Kernel Extensions
|
12
12
|
require 'stringio'
|
13
13
|
|
14
|
-
module Kernel
|
15
|
-
# Redirect standard out, standard error and the buffered logger for sprinkle to StringIO
|
16
|
-
# capture_stdout { any_commands; you_want } => "all output from the commands"
|
17
|
-
def capture_out
|
18
|
-
yield and return if ENV['DEBUG']
|
19
|
-
begin
|
20
|
-
old_out, old_err = STDOUT.dup, STDERR.dup
|
21
|
-
stdout_read, stdout_write = IO.pipe
|
22
|
-
stderr_read, stderr_write = IO.pipe
|
23
|
-
$stdout.reopen(stdout_write)
|
24
|
-
$stderr.reopen(stderr_write)
|
25
|
-
yield
|
26
|
-
stdout_write.close
|
27
|
-
stderr_write.close
|
28
|
-
out = stdout_read.rewind && stdout_read.read rescue nil
|
29
|
-
err = stderr_read.rewind && stderr_read.read rescue nil
|
30
|
-
[out, err]
|
31
|
-
ensure
|
32
|
-
$stdout.reopen(old_out)
|
33
|
-
$stderr.reopen(old_err)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
14
|
class MiniTest::Spec
|
39
15
|
def with_clones(count = 3)
|
40
16
|
FileUtils.rm_rf("/tmp/gitdocs")
|
41
17
|
master_path = "/tmp/gitdocs/master"
|
42
18
|
FileUtils.mkdir_p("/tmp/gitdocs/master")
|
43
|
-
|
19
|
+
ShellTools.capture { `git init /tmp/gitdocs/master --bare` }
|
44
20
|
sub_paths = count.times.map do |c|
|
45
|
-
|
21
|
+
ShellTools.capture { `cd /tmp/gitdocs && git clone file://#{master_path} #{c}` }
|
46
22
|
conf_path = "/tmp/gitdocs/config/#{c}"
|
47
23
|
FileUtils.mkdir_p(conf_path)
|
48
24
|
["/tmp/gitdocs/#{c}", conf_path]
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gitdocs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Josh Hull
|
@@ -158,29 +158,29 @@ dependencies:
|
|
158
158
|
type: :runtime
|
159
159
|
version_requirements: *id013
|
160
160
|
- !ruby/object:Gem::Dependency
|
161
|
-
name:
|
161
|
+
name: shell_tools
|
162
162
|
prerelease: false
|
163
163
|
requirement: &id014 !ruby/object:Gem::Requirement
|
164
164
|
none: false
|
165
165
|
requirements:
|
166
166
|
- - ~>
|
167
167
|
- !ruby/object:Gem::Version
|
168
|
-
version:
|
169
|
-
type: :
|
168
|
+
version: 0.1.0
|
169
|
+
type: :runtime
|
170
170
|
version_requirements: *id014
|
171
171
|
- !ruby/object:Gem::Dependency
|
172
|
-
name:
|
172
|
+
name: minitest
|
173
173
|
prerelease: false
|
174
174
|
requirement: &id015 !ruby/object:Gem::Requirement
|
175
175
|
none: false
|
176
176
|
requirements:
|
177
|
-
- -
|
177
|
+
- - ~>
|
178
178
|
- !ruby/object:Gem::Version
|
179
|
-
version:
|
179
|
+
version: 2.6.1
|
180
180
|
type: :development
|
181
181
|
version_requirements: *id015
|
182
182
|
- !ruby/object:Gem::Dependency
|
183
|
-
name:
|
183
|
+
name: rake
|
184
184
|
prerelease: false
|
185
185
|
requirement: &id016 !ruby/object:Gem::Requirement
|
186
186
|
none: false
|
@@ -191,7 +191,7 @@ dependencies:
|
|
191
191
|
type: :development
|
192
192
|
version_requirements: *id016
|
193
193
|
- !ruby/object:Gem::Dependency
|
194
|
-
name:
|
194
|
+
name: mocha
|
195
195
|
prerelease: false
|
196
196
|
requirement: &id017 !ruby/object:Gem::Requirement
|
197
197
|
none: false
|
@@ -201,6 +201,17 @@ dependencies:
|
|
201
201
|
version: "0"
|
202
202
|
type: :development
|
203
203
|
version_requirements: *id017
|
204
|
+
- !ruby/object:Gem::Dependency
|
205
|
+
name: fakeweb
|
206
|
+
prerelease: false
|
207
|
+
requirement: &id018 !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: "0"
|
213
|
+
type: :development
|
214
|
+
version_requirements: *id018
|
204
215
|
description: Open-source Dropbox using Ruby and Git.
|
205
216
|
email:
|
206
217
|
- joshbuddy@gmail.com
|