From a2b63f5d12b5711cc474208c2002da37ad380040 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Tue, 13 Jul 2010 13:22:09 -0700 Subject: [PATCH] Allow selection of format and entering of commit message via frontend. --- lib/gollum/frontend/app.rb | 25 +++++++++++++------ lib/gollum/frontend/templates/create.mustache | 13 ++++++++++ lib/gollum/frontend/templates/edit.mustache | 12 +++++++++ lib/gollum/frontend/views/create.rb | 6 +++++ lib/gollum/frontend/views/edit.rb | 2 ++ lib/gollum/frontend/views/editable.rb | 13 ++++++++++ lib/gollum/page.rb | 9 +++++++ 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 lib/gollum/frontend/views/editable.rb diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 4aa6bb4f..60b06d80 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -3,6 +3,7 @@ require 'gollum' require 'mustache/sinatra' require 'gollum/frontend/views/layout' +require 'gollum/frontend/views/editable' module Precious class App < Sinatra::Base @@ -41,6 +42,7 @@ module Precious @name = params[:name] wiki = Gollum::Wiki.new($path) if page = wiki.page(@name) + @page = page @content = page.raw_data mustache :edit else @@ -52,20 +54,18 @@ module Precious 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) + + wiki.update_page(page, params[:content], commit_message) 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) + + format = params[:format].intern + + wiki.write_page(page, format, params[:content], commit_message) redirect "/#{page}" end @@ -100,5 +100,14 @@ module Precious mustache :create 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 diff --git a/lib/gollum/frontend/templates/create.mustache b/lib/gollum/frontend/templates/create.mustache index 4bb9aa76..f4c8123f 100644 --- a/lib/gollum/frontend/templates/create.mustache +++ b/lib/gollum/frontend/templates/create.mustache @@ -6,11 +6,24 @@ + + +
diff --git a/lib/gollum/frontend/templates/edit.mustache b/lib/gollum/frontend/templates/edit.mustache index 3d6ae8d7..fb3a904b 100644 --- a/lib/gollum/frontend/templates/edit.mustache +++ b/lib/gollum/frontend/templates/edit.mustache @@ -3,10 +3,22 @@

Editing “{{name}}”

+ +
diff --git a/lib/gollum/frontend/views/create.rb b/lib/gollum/frontend/views/create.rb index 30417379..48a1db2d 100644 --- a/lib/gollum/frontend/views/create.rb +++ b/lib/gollum/frontend/views/create.rb @@ -1,11 +1,17 @@ module Precious module Views class Create < Layout + include Editable + attr_reader :page def title "Create a new page" end + + def formats + super(:markdown) + end end end end diff --git a/lib/gollum/frontend/views/edit.rb b/lib/gollum/frontend/views/edit.rb index 01153767..4f1177d8 100644 --- a/lib/gollum/frontend/views/edit.rb +++ b/lib/gollum/frontend/views/edit.rb @@ -1,6 +1,8 @@ module Precious module Views class Edit < Layout + include Editable + attr_reader :page, :content def title diff --git a/lib/gollum/frontend/views/editable.rb b/lib/gollum/frontend/views/editable.rb new file mode 100644 index 00000000..8fb6caef --- /dev/null +++ b/lib/gollum/frontend/views/editable.rb @@ -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 diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index ee142520..86a414fd 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -5,6 +5,15 @@ module Gollum Wiki.page_class = self 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. #