Allow selection of format and entering of commit message via frontend.
This commit is contained in:
@@ -3,6 +3,7 @@ require 'gollum'
|
|||||||
require 'mustache/sinatra'
|
require 'mustache/sinatra'
|
||||||
|
|
||||||
require 'gollum/frontend/views/layout'
|
require 'gollum/frontend/views/layout'
|
||||||
|
require 'gollum/frontend/views/editable'
|
||||||
|
|
||||||
module Precious
|
module Precious
|
||||||
class App < Sinatra::Base
|
class App < Sinatra::Base
|
||||||
@@ -41,6 +42,7 @@ module Precious
|
|||||||
@name = params[:name]
|
@name = params[:name]
|
||||||
wiki = Gollum::Wiki.new($path)
|
wiki = Gollum::Wiki.new($path)
|
||||||
if page = wiki.page(@name)
|
if page = wiki.page(@name)
|
||||||
|
@page = page
|
||||||
@content = page.raw_data
|
@content = page.raw_data
|
||||||
mustache :edit
|
mustache :edit
|
||||||
else
|
else
|
||||||
@@ -52,20 +54,18 @@ module Precious
|
|||||||
name = params[:name]
|
name = params[:name]
|
||||||
wiki = Gollum::Wiki.new($path)
|
wiki = Gollum::Wiki.new($path)
|
||||||
page = wiki.page(name)
|
page = wiki.page(name)
|
||||||
commit = { :message => 'commit message',
|
|
||||||
:name => 'Tom Preston-Werner',
|
wiki.update_page(page, params[:content], commit_message)
|
||||||
:email => 'tom@github.com' }
|
|
||||||
wiki.update_page(page, params[:content], commit)
|
|
||||||
redirect "/#{name}"
|
redirect "/#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/create/:page' do
|
post '/create/:page' do
|
||||||
page = params[:page]
|
page = params[:page]
|
||||||
wiki = Gollum::Wiki.new($path)
|
wiki = Gollum::Wiki.new($path)
|
||||||
commit = { :message => 'commit message',
|
|
||||||
:name => 'Tom Preston-Werner',
|
format = params[:format].intern
|
||||||
:email => 'tom@github.com' }
|
|
||||||
wiki.write_page(page, :markdown, params[:content], commit)
|
wiki.write_page(page, format, params[:content], commit_message)
|
||||||
redirect "/#{page}"
|
redirect "/#{page}"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -100,5 +100,14 @@ module Precious
|
|||||||
mustache :create
|
mustache :create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commit_message
|
||||||
|
message = params[:message]
|
||||||
|
author_name = `git config --get user.name`.strip || 'Anonymous'
|
||||||
|
author_email = `git config --get user.email`.strip || 'anon@anon.com'
|
||||||
|
{ :message => message,
|
||||||
|
:name => author_name,
|
||||||
|
:email => author_email }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,11 +6,24 @@
|
|||||||
<label>
|
<label>
|
||||||
Title<br />
|
Title<br />
|
||||||
<input class="text" type="text" name="page" value="{{name}}" />
|
<input class="text" type="text" name="page" value="{{name}}" />
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
Format<br />
|
||||||
|
<select name="format">
|
||||||
|
{{#formats}}
|
||||||
|
<option {{#selected}}selected="true" {{/selected}}value="{{id}}">{{name}}</option>
|
||||||
|
{{/formats}}
|
||||||
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Body
|
Body
|
||||||
<textarea name="content"></textarea>
|
<textarea name="content"></textarea>
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
Edit Summary <small>(Briefly describe the changes you have made)</small><br />
|
||||||
|
<input type="text" class="text" name="message" value="Create '{{name}}' page." />
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<input type="submit" value="Create page" />
|
<input type="submit" value="Create page" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,10 +3,22 @@
|
|||||||
<h1>Editing “{{name}}”</h1>
|
<h1>Editing “{{name}}”</h1>
|
||||||
|
|
||||||
<form class="edit_wiki" method="post" action="/edit/{{name}}">
|
<form class="edit_wiki" method="post" action="/edit/{{name}}">
|
||||||
|
<label>
|
||||||
|
Format<br />
|
||||||
|
<select name="format">
|
||||||
|
{{#formats}}
|
||||||
|
<option {{#selected}}selected="true" {{/selected}}value="{{id}}">{{name}}</option>
|
||||||
|
{{/formats}}
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Body
|
Body
|
||||||
<textarea name="content">{{content}}</textarea>
|
<textarea name="content">{{content}}</textarea>
|
||||||
</label>
|
</label>
|
||||||
|
<label>
|
||||||
|
Edit Summary <small>(Briefly describe the changes you have made)</small><br />
|
||||||
|
<input type="text" class="text" name="message" />
|
||||||
|
</label>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<input type="submit" value="Save page" />
|
<input type="submit" value="Save page" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
module Precious
|
module Precious
|
||||||
module Views
|
module Views
|
||||||
class Create < Layout
|
class Create < Layout
|
||||||
|
include Editable
|
||||||
|
|
||||||
attr_reader :page
|
attr_reader :page
|
||||||
|
|
||||||
def title
|
def title
|
||||||
"Create a new page"
|
"Create a new page"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def formats
|
||||||
|
super(:markdown)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
module Precious
|
module Precious
|
||||||
module Views
|
module Views
|
||||||
class Edit < Layout
|
class Edit < Layout
|
||||||
|
include Editable
|
||||||
|
|
||||||
attr_reader :page, :content
|
attr_reader :page, :content
|
||||||
|
|
||||||
def title
|
def title
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
module Precious
|
||||||
|
module Editable
|
||||||
|
def formats(selected = @page.format)
|
||||||
|
Gollum::Page::FORMAT_NAMES.map do |key, val|
|
||||||
|
{ :name => val,
|
||||||
|
:id => key.to_s,
|
||||||
|
:selected => selected == key}
|
||||||
|
end.sort do |a, b|
|
||||||
|
a[:name].downcase <=> b[:name].downcase
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,6 +5,15 @@ module Gollum
|
|||||||
Wiki.page_class = self
|
Wiki.page_class = self
|
||||||
|
|
||||||
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|creole|re?st(\.txt)?|asciidoc|pod|\d)$/i
|
VALID_PAGE_RE = /^(.+)\.(md|mkdn?|mdown|markdown|textile|rdoc|org|creole|re?st(\.txt)?|asciidoc|pod|\d)$/i
|
||||||
|
FORMAT_NAMES = { :markdown => "Markdown",
|
||||||
|
:textile => "Textile",
|
||||||
|
:rdoc => "RDoc",
|
||||||
|
:org => "Org-mode",
|
||||||
|
:creole => "Creole",
|
||||||
|
:rest => "reStructuredText",
|
||||||
|
:asciidoc => "AsciiDoc",
|
||||||
|
:pod => "Pod",
|
||||||
|
:roff => "roff" }
|
||||||
|
|
||||||
# Public: Initialize a page.
|
# Public: Initialize a page.
|
||||||
#
|
#
|
||||||
|
|||||||
Reference in New Issue
Block a user