Add create/edit powers to frontend. Support external image URLs.
This commit is contained in:
@@ -6,7 +6,7 @@ require 'mustache/sinatra'
|
|||||||
|
|
||||||
require 'gollum/frontend/views/layout'
|
require 'gollum/frontend/views/layout'
|
||||||
|
|
||||||
$path = "~/dev/mojombo/gollum/test/examples/lotr.git"
|
$path = "~/dev/sandbox/lotr2"
|
||||||
|
|
||||||
module Precious
|
module Precious
|
||||||
class App < Sinatra::Base
|
class App < Sinatra::Base
|
||||||
@@ -41,6 +41,38 @@ module Precious
|
|||||||
show_page_or_file('Home')
|
show_page_or_file('Home')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/edit/:name' do
|
||||||
|
@name = params[:name]
|
||||||
|
wiki = Gollum::Wiki.new($path)
|
||||||
|
if page = wiki.page(@name)
|
||||||
|
@content = page.raw_data
|
||||||
|
mustache :edit
|
||||||
|
else
|
||||||
|
mustache :create
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/edit/:name' do
|
||||||
|
name = params[:name]
|
||||||
|
wiki = Gollum::Wiki.new($path)
|
||||||
|
page = wiki.page(name)
|
||||||
|
commit = { :message => 'commit message',
|
||||||
|
:name => 'Tom Preston-Werner',
|
||||||
|
:email => 'tom@github.com' }
|
||||||
|
wiki.update_page(page, params[:content], commit)
|
||||||
|
redirect "/#{name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/create/:page' do
|
||||||
|
page = params[:page]
|
||||||
|
wiki = Gollum::Wiki.new($path)
|
||||||
|
commit = { :message => 'commit message',
|
||||||
|
:name => 'Tom Preston-Werner',
|
||||||
|
:email => 'tom@github.com' }
|
||||||
|
wiki.write_page(page, :markdown, params[:content], commit)
|
||||||
|
redirect "/#{page}"
|
||||||
|
end
|
||||||
|
|
||||||
get '/*' do
|
get '/*' do
|
||||||
show_page_or_file(params[:splat].first)
|
show_page_or_file(params[:splat].first)
|
||||||
end
|
end
|
||||||
@@ -48,12 +80,14 @@ module Precious
|
|||||||
def show_page_or_file(name)
|
def show_page_or_file(name)
|
||||||
wiki = Gollum::Wiki.new($path)
|
wiki = Gollum::Wiki.new($path)
|
||||||
if page = wiki.page(name)
|
if page = wiki.page(name)
|
||||||
|
@name = name
|
||||||
@content = page.formatted_data
|
@content = page.formatted_data
|
||||||
mustache :page
|
mustache :page
|
||||||
elsif file = wiki.file(name)
|
elsif file = wiki.file(name)
|
||||||
file.raw_data
|
file.raw_data
|
||||||
else
|
else
|
||||||
halt 404
|
@name = name
|
||||||
|
mustache :create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -34,6 +34,12 @@ p {
|
|||||||
line-height: 22pt;
|
line-height: 22pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#nav {
|
||||||
|
width: 60em;
|
||||||
|
margin: 0 auto;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
#content {
|
#content {
|
||||||
width: 60em;
|
width: 60em;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
@@ -44,6 +50,13 @@ a.absent {
|
|||||||
color: #a00;
|
color: #a00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Forms */
|
||||||
|
|
||||||
|
textarea {
|
||||||
|
width: 100%;
|
||||||
|
height: 20em;
|
||||||
|
}
|
||||||
|
|
||||||
/* Images */
|
/* Images */
|
||||||
|
|
||||||
.frame {
|
.frame {
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<h1>Create a new page</h1>
|
||||||
|
|
||||||
|
<form method="post" action="/create/{{name}}">
|
||||||
|
<div>
|
||||||
|
<input type="text" name="page" value="{{name}}" />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<textarea name="content"></textarea>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="submit" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<h1>Editing {{name}}</h1>
|
||||||
|
|
||||||
|
<form method="post" action="/edit/{{name}}">
|
||||||
|
<div>
|
||||||
|
<textarea name="content">{{content}}</textarea>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<input type="submit" value="Save page" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
@@ -8,6 +8,9 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div id="nav">
|
||||||
|
<a href="/">Home</a> | <a href="/edit/{{name}}">Edit</a>
|
||||||
|
</div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
{{{yield}}}
|
{{{yield}}}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module Precious
|
||||||
|
module Views
|
||||||
|
class Create < Layout
|
||||||
|
attr_reader :page
|
||||||
|
|
||||||
|
def title
|
||||||
|
"Create a new page"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
module Precious
|
||||||
|
module Views
|
||||||
|
class Edit < Layout
|
||||||
|
attr_reader :page, :content
|
||||||
|
|
||||||
|
def title
|
||||||
|
"Edit"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4,6 +4,8 @@ module Precious
|
|||||||
include Rack::Utils
|
include Rack::Utils
|
||||||
alias_method :h, :escape_html
|
alias_method :h, :escape_html
|
||||||
|
|
||||||
|
attr_reader :name
|
||||||
|
|
||||||
def title
|
def title
|
||||||
"Home"
|
"Home"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -85,8 +85,15 @@ module Gollum
|
|||||||
def process_image_tag(tag)
|
def process_image_tag(tag)
|
||||||
parts = tag.split('|')
|
parts = tag.split('|')
|
||||||
name = parts[0].strip
|
name = parts[0].strip
|
||||||
|
path = nil
|
||||||
|
|
||||||
if file = find_file(name)
|
if file = find_file(name)
|
||||||
|
path = "/#{file.path}"
|
||||||
|
elsif name =~ /^https?:\/\/.+(jpg|png|gif|svg|bmp)$/
|
||||||
|
path = name
|
||||||
|
end
|
||||||
|
|
||||||
|
if path
|
||||||
opts = parse_image_tag_options(tag)
|
opts = parse_image_tag_options(tag)
|
||||||
|
|
||||||
containered = false
|
containered = false
|
||||||
@@ -143,7 +150,7 @@ module Gollum
|
|||||||
%{</span>} +
|
%{</span>} +
|
||||||
%{</span>}
|
%{</span>}
|
||||||
else
|
else
|
||||||
%{<img src="/#{file.path}"#{style_string} #{attr_string}/>}
|
%{<img src="#{path}"#{style_string} #{attr_string}/>}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,6 +32,16 @@ context "Markup" do
|
|||||||
assert_equal %{<p>a <a class="internal absent" href="J.-R.-R.-Tolkien">J. R. R. Tolkien</a>'s b</p>\n}, output
|
assert_equal %{<p>a <a class="internal absent" href="J.-R.-R.-Tolkien">J. R. R. Tolkien</a>'s b</p>\n}, output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "image with http url" do
|
||||||
|
['http', 'https'].each do |scheme|
|
||||||
|
@wiki.write_page("Bilbo Baggins", :markdown, "a [[#{scheme}://example.com/bilbo.jpg]] b", @commit)
|
||||||
|
|
||||||
|
page = @wiki.page("Bilbo Baggins")
|
||||||
|
output = Gollum::Markup.new(page).render
|
||||||
|
assert_equal %{<p>a <img src="#{scheme}://example.com/bilbo.jpg" /> b</p>\n}, output
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test "image with absolute path" do
|
test "image with absolute path" do
|
||||||
index = @wiki.repo.index
|
index = @wiki.repo.index
|
||||||
index.add("alpha.jpg", "hi")
|
index.add("alpha.jpg", "hi")
|
||||||
|
|||||||
Reference in New Issue
Block a user