fredit 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'git'
2
+ require 'fileutils'
2
3
 
3
4
  class FreditController < ::ApplicationController
4
5
  skip_before_filter :verify_authenticity_token
@@ -62,6 +63,33 @@ class FreditController < ::ApplicationController
62
63
  redirect_to fredit_path(:file => @path)
63
64
  end
64
65
 
66
+ def upload
67
+ @path = secure_path params[:file_path]
68
+ upload = params[:upload_file]
69
+ if !upload.respond_to?(:original_filename)
70
+ flash[:notice] = "You need to choose a file to upload"
71
+ redirect_to fredit_path(file: @path)
72
+ return
73
+ end
74
+ filename = upload.original_filename
75
+ upload_dir = secure_path( params[:target_dir] || 'public/images' )
76
+ FileUtils::mkdir_p upload_dir
77
+ upload_path = File.join(upload_dir, filename)
78
+ File.open(upload_path, 'wb') {|f| f.write(upload.read)}
79
+ flash[:notice] = "File successfully uploaded to #{upload_path}"
80
+ system %Q|git add #{upload_path}|
81
+ author = session[:commit_author] = (params[:commit_author] || '').gsub(/[^\w@<>. ]/, '')
82
+ if author.blank?
83
+ flash[:notice] = "Uploaded By must not be blank"
84
+ redirect_to :back
85
+ return
86
+ end
87
+ cmd = %Q|git commit --author='#{author}' -m 'added #{filename}' #{upload_path}|
88
+ logger.debug cmd
89
+ res = system cmd
90
+ redirect_to fredit_path(@path)
91
+ end
92
+
65
93
  def revision
66
94
  @path = secure_path params[:file]
67
95
  load_git_log
@@ -23,58 +23,91 @@
23
23
  </script>
24
24
  <% end %>
25
25
 
26
- <form id="sourceEditor" action="<%= fredit_path %>" method="post">
27
- <input name="_method" type="hidden" value="put" />
28
- <input name="utf8" type="hidden" value="&#x2713;" />
29
- <input type="hidden" name="file" value="<%=@path%>"/>
26
+ <hr/>
30
27
 
31
- <div id='sourceEditBox' name='source'><%= @source %></div>
28
+ <form id="sourceEditor" action="<%= fredit_path %>" method="post">
29
+ <input name="_method" type="hidden" value="put" />
30
+ <input name="utf8" type="hidden" value="&#x2713;" />
31
+ <input type="hidden" name="file" value="<%=@path%>"/>
32
32
 
33
- <table>
34
- <tr>
35
- <td>File:</td>
36
- <td>
37
- <%= @path %>
38
- </td>
39
- </tr>
40
- <tr>
41
- <td>Edit Message (optional):</td>
42
- <td>
43
- <input type="text" name="edit_message" value="" placeholder="Describe the edit " size="50"/>
44
- </td>
45
- </tr>
46
- <tr>
47
- <td>Edited By (required): </td>
48
- <td>
49
- <input type="text" name="commit_author" value="<%=session[:commit_author]%>" placeholder="Your Name <yourname@example.com>" size="50"/>
50
- </td>
51
- </tr>
52
- <tr>
53
- <td>Action:</td>
54
- <td>
55
- <input hidden="text" name="file_path" value="<%=@path%>" />
56
- <input type="submit" name="commit" value="update this file"/>
57
- <input id="deleteBtn" type="submit" name="commit" value="delete this file"/>
58
- </td>
59
- </tr>
60
- </table>
61
- </form>
33
+ <div id='sourceEditBox' name='source'><%= @source %></div>
62
34
 
63
- <form id="createFileForm" action="<%= fredit_path %>" method="post">
64
- <table>
65
- <tr>
66
- <td>Create file at path:</td>
67
- <td>
68
- <input type="text" name="new_file" value="" placeholder="<%=Fredit.editables[:views].first%>" size="50"/>
69
- </td>
70
- </tr>
71
- <tr>
72
- <td>Action:</td>
73
- <td>
74
- <input type="submit" name="commit" value="create file"/>
75
- </td>
76
- </tr>
77
- </table>
78
- </form>
35
+ <table>
36
+ <tr>
37
+ <td>File:</td>
38
+ <td>
39
+ <%= @path %>
40
+ </td>
41
+ </tr>
42
+ <tr>
43
+ <td>Edit Message (optional):</td>
44
+ <td>
45
+ <input type="text" name="edit_message" value="" placeholder="Describe the edit " size="50"/>
46
+ </td>
47
+ </tr>
48
+ <tr>
49
+ <td>Edited By (required): </td>
50
+ <td>
51
+ <input type="text" name="commit_author" value="<%=session[:commit_author]%>" placeholder="Your Name <yourname@example.com>" size="50"/>
52
+ </td>
53
+ </tr>
54
+ <tr>
55
+ <td>Action:</td>
56
+ <td>
57
+ <input hidden="text" name="file_path" value="<%=@path%>" />
58
+ <input type="submit" name="commit" value="update this file"/>
59
+ <input id="deleteBtn" type="submit" name="commit" value="delete this file"/>
60
+ </td>
61
+ </tr>
62
+ </table>
63
+ </form>
79
64
 
65
+ <form id="createFileForm" action="<%= fredit_path %>" method="post">
66
+ <table>
67
+ <tr>
68
+ <td>Create file at path:</td>
69
+ <td>
70
+ <input type="text" name="new_file" value="" placeholder="<%=Fredit.editables[:views].first%>" size="50"/>
71
+ </td>
72
+ </tr>
73
+ <tr>
74
+ <td>Action:</td>
75
+ <td>
76
+ <input type="submit" name="commit" value="create file"/>
77
+ </td>
78
+ </tr>
79
+ </table>
80
+ </form>
81
+ <hr/>
80
82
 
83
+ <form id="uploadFileForm" action="/fredit/upload" method="post" enctype='multipart/form-data'>
84
+ <input hidden="text" name="file_path" value="<%=@path%>" />
85
+ <table>
86
+ <tr>
87
+ <td>Upload file to application directory:</td>
88
+ <td>
89
+ <input type="text" name="target_dir" value="public/images" size="50"/>
90
+ </td>
91
+ </tr>
92
+ <tr>
93
+ <td>Select file to upload:</td>
94
+ <td>
95
+ <input type="file" name="upload_file" />
96
+ </td>
97
+ </tr>
98
+ <tr>
99
+ <td>Uploaded By (required): </td>
100
+ <td>
101
+ <input type="text" name="commit_author" value="<%=session[:commit_author]%>" placeholder="Your Name <yourname@example.com>" size="50"/>
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td>Action:</td>
106
+ <td>
107
+ <input type="submit" name="upload" value="upload file"/>
108
+ </td>
109
+ </tr>
110
+ </table>
111
+ </form>
112
+
113
+ <br/>
@@ -62,9 +62,6 @@ form#fileSelector {
62
62
  float:right;
63
63
  }
64
64
  form#createFileForm {
65
- border-top: 1px solid #CCC;
66
- margin-top: 10px;
67
- padding-top: 10px;
68
65
  }
69
66
 
70
67
  #sourceEditBox {
data/config/routes.rb CHANGED
@@ -3,5 +3,6 @@ Rails.application.routes.draw do
3
3
  get 'fredit' => "fredit#show"
4
4
  put 'fredit' => "fredit#update"
5
5
  post 'fredit' => "fredit#create"
6
+ post 'fredit/upload' => "fredit#upload"
6
7
  end
7
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fredit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-28 00:00:00.000000000Z
12
+ date: 2011-10-31 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
16
- requirement: &69680210 !ruby/object:Gem::Requirement
16
+ requirement: &83868010 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *69680210
24
+ version_requirements: *83868010
25
25
  description: Edit the front end of Rails apps through the browser.
26
26
  email:
27
27
  - dhchoi@gmail.com
@@ -56,7 +56,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
56
  version: '0'
57
57
  segments:
58
58
  - 0
59
- hash: -254691487
59
+ hash: 1045934387
60
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  segments:
67
67
  - 0
68
- hash: -254691487
68
+ hash: 1045934387
69
69
  requirements: []
70
70
  rubyforge_project:
71
71
  rubygems_version: 1.8.11