gitdocs 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/gitdocs/cli.rb CHANGED
@@ -60,7 +60,6 @@ module Gitdocs
60
60
 
61
61
  desc "create PATH REMOTE", "Creates a new gitdoc root based on an existing remote"
62
62
  def create(path, remote)
63
- path = self.config.normalize_path(path)
64
63
  FileUtils.mkdir_p(File.dirname(path))
65
64
  system("git clone -q #{remote} #{path}") or raise "Unable to clone into #{path}"
66
65
  self.add(path)
@@ -39,12 +39,14 @@ module Gitdocs
39
39
  end
40
40
 
41
41
  def add_path(path, opts = nil)
42
+ path = self.normalize_path(path)
42
43
  path_opts = {:path => path}
43
44
  path_opts.merge!(opts) if opts
44
45
  Share.new(path_opts).save!
45
46
  end
46
47
 
47
48
  def remove_path(path)
49
+ path = self.normalize_path(path)
48
50
  Share.where(:path => path).destroy_all
49
51
  end
50
52
 
@@ -38,8 +38,6 @@ module Gitdocs
38
38
  gd = gds[idx]
39
39
  halt 404 if gd.nil?
40
40
  file_path = request.path_info
41
- file_path = request.path_info.gsub('/save', '') if save_file = request.path_info =~ %r{/save$}
42
- file_path = request.path_info.gsub('/upload', '') if upload_file = request.path_info =~ %r{/upload$}
43
41
  file_ext = File.extname(file_path)
44
42
  expanded_path = File.expand_path(".#{file_path}", gd.root)
45
43
  halt 400 unless expanded_path[/^#{Regexp.quote(gd.root)}/]
@@ -48,10 +46,10 @@ module Gitdocs
48
46
  parent = nil if parent == '.'
49
47
  locals = {:idx => idx, :parent => parent, :root => gd.root, :file_path => expanded_path}
50
48
  mode, mime = request.params['mode'], `file -I #{expanded_path}`.strip
51
- if save_file # Saving
49
+ if mode == 'save' # Saving
52
50
  File.open(expanded_path, 'w') { |f| f.print request.params['data'] }
53
51
  redirect! "/" + idx.to_s + file_path
54
- elsif upload_file # Uploading
52
+ elsif mode == 'upload' # Uploading
55
53
  halt 404 unless file = request.params['file']
56
54
  tempfile, filename = file[:tempfile], file[:filename]
57
55
  FileUtils.mv(tempfile.path, File.expand_path(filename, expanded_path))
@@ -1,3 +1,3 @@
1
1
  module Gitdocs
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -23,7 +23,7 @@
23
23
  %input{:type => 'text', :name => "path", :class => "edit" }
24
24
  %input{:type => 'submit', :value => "New file" }
25
25
 
26
- %form.upload{ :method => "post", :enctype => "multipart/form-data", :action => "/#{idx}#{request.path_info}/upload" }
26
+ %form.upload{ :method => "post", :enctype => "multipart/form-data", :action => "/#{idx}#{request.path_info}?mode=upload" }
27
27
  %p Upload a file to this directory
28
28
  %input{:type => 'file', :value => "Select a file", :name => "file", :class => "uploader" }
29
29
  %input{:type => 'submit', :value => "Upload file"}
@@ -13,7 +13,7 @@
13
13
  %a{ :href => "?mode=edit" } (edit)
14
14
  %a{ :href => "?mode=delete", :onclick => "javascript:return confirm('Are you sure?')" } (delete)
15
15
 
16
- %form{ :class => "edit", :action => "/#{idx}#{request.path_info}/save", :method => "post", :style => "display:none;" }
16
+ %form{ :class => "edit", :action => "/#{idx}#{request.path_info}?mode=save", :method => "post", :style => "display:none;" }
17
17
  #editor
18
18
  %textarea{ :id => 'data', :name => "data" }= preserve contents
19
19
  %input{ :type => 'submit', :value => "Save" }
@@ -14,7 +14,7 @@ describe "gitdocs configuration" do
14
14
  end
15
15
 
16
16
  it "can have a path added" do
17
- @config.add_path('/my/path')
17
+ @config.add_path('/my/../my/path') # normalized test
18
18
  assert_equal "/my/path", @config.shares.first.path
19
19
  assert_equal 15.0, @config.shares.first.polling_interval
20
20
  end
@@ -22,7 +22,7 @@ describe "gitdocs configuration" do
22
22
  it "can have a path removed" do
23
23
  @config.add_path('/my/path')
24
24
  @config.add_path('/my/path/2')
25
- @config.remove_path('/my/path/2')
25
+ @config.remove_path('/my/../my/path/2') # normalized test
26
26
  assert_equal ["/my/path"], @config.shares.map(&:path)
27
27
  end
28
28
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gitdocs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.1
5
+ version: 0.3.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Hull
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-12-05 00:00:00 -08:00
14
+ date: 2011-12-06 00:00:00 -08:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency