fredit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +5 -0
- data/Rakefile +13 -0
- data/app/controllers/fredit_controller.rb +51 -0
- data/app/views/fredit/index.html.erb +104 -0
- data/app/views/fredit/layout.html.erb +16 -0
- data/config/routes.rb +5 -0
- data/lib/fredit.rb +40 -0
- data/lib/fredit/engine.rb +7 -0
- data/lib/fredit/erb.rb +51 -0
- metadata +73 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'bundler'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'bundler/setup'
|
9
|
+
rescue LoadError
|
10
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
11
|
+
end
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class FreditController < ::ApplicationController
|
2
|
+
|
3
|
+
layout false
|
4
|
+
|
5
|
+
CSS_DIR = Rails.root + 'public/stylesheets/**/*.css'
|
6
|
+
JS_DIR = Rails.root + 'public/javascripts/**/*.js'
|
7
|
+
|
8
|
+
def index
|
9
|
+
@path ||= params[:file] || params[:new_path] || Fredit.editables[:views].first
|
10
|
+
if !File.size?(@path)
|
11
|
+
File.open(@path, 'w') {|f| f.write("REPLACE WITH CONTENT")}
|
12
|
+
end
|
13
|
+
@source = File.read(Rails.root + @path)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
@path = params[:file_path]
|
18
|
+
|
19
|
+
edit_msg = !params[:edit_message].blank? ? params[:edit_message] : "unspecified edit"
|
20
|
+
|
21
|
+
author = (session[:commit_author] = params[:commit_author])
|
22
|
+
if session[:commit_author].blank?
|
23
|
+
flash.now[:notice] = "Edited By must not be blank"
|
24
|
+
@source = params[:source]
|
25
|
+
render :action => 'index'
|
26
|
+
return
|
27
|
+
end
|
28
|
+
|
29
|
+
if params[:commit] =~ /delete/i
|
30
|
+
`git rm #@path`
|
31
|
+
flash[:notice] = "#@path deleted"
|
32
|
+
`git commit --author='#{author}' -m '#{edit_msg}' #{@path}`
|
33
|
+
@path = nil
|
34
|
+
else
|
35
|
+
n = params[:source].gsub(/\r\n/, "\n")
|
36
|
+
File.open(@path, 'w') {|f| f.write(n)}
|
37
|
+
`git add #{@path}`
|
38
|
+
flash[:notice] = "#@path updated"
|
39
|
+
`git commit --author='#{author}' -m '#{edit_msg}' #{@path}`
|
40
|
+
end
|
41
|
+
params.delete(:source)
|
42
|
+
|
43
|
+
redirect_to :action => 'index', :file => @path
|
44
|
+
end
|
45
|
+
|
46
|
+
def create
|
47
|
+
@path = params[:file]
|
48
|
+
File.open(@path, 'w') {|f| f.write("REPLACE WITH CONTENT")}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%=@path%></title>
|
5
|
+
<style>
|
6
|
+
|
7
|
+
body {
|
8
|
+
padding-bottom: 30px;
|
9
|
+
}
|
10
|
+
textarea {
|
11
|
+
width: 80%;
|
12
|
+
height: 500px;
|
13
|
+
font-family: monospace;
|
14
|
+
}
|
15
|
+
#notice {
|
16
|
+
background-color: yellow;
|
17
|
+
}
|
18
|
+
input#deleteBtn {
|
19
|
+
float:right;
|
20
|
+
}
|
21
|
+
input[type=text] {
|
22
|
+
width: 100%;
|
23
|
+
}
|
24
|
+
table {
|
25
|
+
width: 80%
|
26
|
+
}
|
27
|
+
form#createFileForm {
|
28
|
+
border-top: 1px solid #CCC;
|
29
|
+
margin-top: 30px;
|
30
|
+
padding-top: 30px;
|
31
|
+
}
|
32
|
+
|
33
|
+
</style>
|
34
|
+
</head>
|
35
|
+
<body>
|
36
|
+
|
37
|
+
<% if flash[:notice] %>
|
38
|
+
<div id="notice"><%= flash[:notice] %></div>
|
39
|
+
<% end %>
|
40
|
+
|
41
|
+
<h1>Fredit: front-end edit</h1>
|
42
|
+
|
43
|
+
<form action="<%=url_for%>">
|
44
|
+
<select name="file">
|
45
|
+
<% Fredit.editables.each_pair do |k, v| %>
|
46
|
+
<optgroup label="<%= k %>">
|
47
|
+
<% v.each do |path| %>
|
48
|
+
<option value="<%= path %>" <%= @path == path ? 'selected=\"selected\"' : nil %>><%= Fredit.link(path)%></li>
|
49
|
+
<% end %>
|
50
|
+
</optgroup>
|
51
|
+
<% end %>
|
52
|
+
</select>
|
53
|
+
<input type="submit" value="load"/>
|
54
|
+
</form>
|
55
|
+
|
56
|
+
<form action="<%=url_for(:action => :update)%>" method="post">
|
57
|
+
<input type="hidden" name="file" value="<%=@path%>"/>
|
58
|
+
<textarea name='source'><%= @source %></textarea>
|
59
|
+
|
60
|
+
<table>
|
61
|
+
<tr>
|
62
|
+
<td>Edit Message (optional):</td>
|
63
|
+
<td>
|
64
|
+
<input type="text" name="edit_message" value="" placeholder="Describe the edit " size="50"/>
|
65
|
+
</td>
|
66
|
+
</tr>
|
67
|
+
<tr>
|
68
|
+
<td>Edited By (required): </td>
|
69
|
+
<td>
|
70
|
+
<input type="text" name="commit_author" value="<%=session[:commit_author]%>" placeholder="Your Name <yourname@example.com>" size="50"/>
|
71
|
+
</td>
|
72
|
+
</tr>
|
73
|
+
<tr>
|
74
|
+
<td>Action:</td>
|
75
|
+
<td>
|
76
|
+
<input hidden="text" name="file_path" value="<%=@path%>" />
|
77
|
+
<input type="submit" name="commit" value="update this file"/>
|
78
|
+
<input id="deleteBtn" type="submit" name="commit" value="delete this file"/>
|
79
|
+
</td>
|
80
|
+
</tr>
|
81
|
+
</table>
|
82
|
+
</form>
|
83
|
+
|
84
|
+
<form id="createFileForm" action="<%=url_for%>" method="get">
|
85
|
+
<table>
|
86
|
+
<tr>
|
87
|
+
<td>Create file at path:</td>
|
88
|
+
<td>
|
89
|
+
<input type="text" name="new_path" value="" placeholder="<%=Fredit.editables[:views].first%>" size="50"/>
|
90
|
+
</td>
|
91
|
+
</tr>
|
92
|
+
<tr>
|
93
|
+
<td>Action:</td>
|
94
|
+
<td>
|
95
|
+
<input type="submit" name="commit" value="create file"/>
|
96
|
+
</td>
|
97
|
+
</tr>
|
98
|
+
</table>
|
99
|
+
</form>
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
</body>
|
104
|
+
</html>
|
data/config/routes.rb
ADDED
data/lib/fredit.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'fredit/erb'
|
2
|
+
|
3
|
+
module Fredit
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def rel_path(path)
|
7
|
+
path.sub(Rails.root.to_s + '/', '')
|
8
|
+
end
|
9
|
+
|
10
|
+
def rel_paths(paths)
|
11
|
+
paths.map {|x| rel_path(x)}
|
12
|
+
end
|
13
|
+
|
14
|
+
def link(x)
|
15
|
+
s = <<-END
|
16
|
+
<a href="/fredit?file=#{x}">#{x}</a>
|
17
|
+
END
|
18
|
+
s.strip.html_safe
|
19
|
+
end
|
20
|
+
|
21
|
+
def entries(glob)
|
22
|
+
Dir[Rails.root + glob].entries.map {|e| rel_path(e)}
|
23
|
+
end
|
24
|
+
|
25
|
+
def editables
|
26
|
+
css = entries('public/stylesheets/**/*.css')
|
27
|
+
js = entries('public/javascripts/**/*.js')
|
28
|
+
views = entries('app/views/**/*.html.{erb,haml}')
|
29
|
+
{:css => css, :views => views, :javascript => js}
|
30
|
+
end
|
31
|
+
|
32
|
+
def template_editable?(template)
|
33
|
+
template.identifier.index(Rails.root.to_s) == 0 &&
|
34
|
+
template.formats &&
|
35
|
+
template.formats.include?(:html)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
require 'fredit/engine'
|
data/lib/fredit/erb.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
module ActionView
|
3
|
+
class Template
|
4
|
+
module Handlers
|
5
|
+
class ERB < Handler
|
6
|
+
def compile(template)
|
7
|
+
|
8
|
+
# copied from original
|
9
|
+
|
10
|
+
if template.source.encoding_aware?
|
11
|
+
# First, convert to BINARY, so in case the encoding is
|
12
|
+
# wrong, we can still find an encoding tag
|
13
|
+
# (<%# encoding %>) inside the String using a regular
|
14
|
+
# expression
|
15
|
+
template_source = template.source.dup.force_encoding("BINARY")
|
16
|
+
|
17
|
+
erb = template_source.gsub(ENCODING_TAG, '')
|
18
|
+
encoding = $2
|
19
|
+
|
20
|
+
erb.force_encoding valid_encoding(template.source.dup, encoding)
|
21
|
+
|
22
|
+
# Always make sure we return a String in the default_internal
|
23
|
+
erb.encode!
|
24
|
+
else
|
25
|
+
erb = template.source.dup
|
26
|
+
end
|
27
|
+
|
28
|
+
# begin Fredit patch
|
29
|
+
|
30
|
+
if Fredit.template_editable?(template)
|
31
|
+
source_file = Fredit.rel_path template.identifier
|
32
|
+
edit_link = "<div style='color:red'>#{Fredit.link(source_file)}</div> "
|
33
|
+
if erb =~ /^\s*<!DOCTYPE/ && erb =~ /<body[^>]*>/
|
34
|
+
erb = erb.sub(/<body[^>]*>/, '\&' + edit_link)
|
35
|
+
else
|
36
|
+
erb = edit_link + erb
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# end Fredit patch
|
41
|
+
|
42
|
+
self.class.erb_implementation.new(
|
43
|
+
erb,
|
44
|
+
:trim => (self.class.erb_trim_mode == "-")
|
45
|
+
).src
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fredit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Choi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-25 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: &73525730 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *73525730
|
25
|
+
description: Edit the front end of Rails apps through the browser.
|
26
|
+
email:
|
27
|
+
- dhchoi@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- app/views/fredit/index.html.erb
|
33
|
+
- app/views/fredit/layout.html.erb
|
34
|
+
- app/controllers/fredit_controller.rb
|
35
|
+
- lib/fredit.rb
|
36
|
+
- lib/fredit/erb.rb
|
37
|
+
- lib/fredit/engine.rb
|
38
|
+
- config/routes.rb
|
39
|
+
- MIT-LICENSE
|
40
|
+
- Rakefile
|
41
|
+
- Gemfile
|
42
|
+
- README.rdoc
|
43
|
+
homepage:
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
hash: 434428307
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
hash: 434428307
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.11
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: fredit 0.0.1
|
73
|
+
test_files: []
|