diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index e7044548..3757a470 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -6,7 +6,7 @@ require 'mustache/sinatra' require 'gollum/frontend/views/layout' -$path = "~/dev/mojombo/gollum/test/examples/lotr.git" +$path = "~/dev/sandbox/lotr2" module Precious class App < Sinatra::Base @@ -41,6 +41,38 @@ module Precious show_page_or_file('Home') 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 show_page_or_file(params[:splat].first) end @@ -48,12 +80,14 @@ module Precious def show_page_or_file(name) wiki = Gollum::Wiki.new($path) if page = wiki.page(name) + @name = name @content = page.formatted_data mustache :page elsif file = wiki.file(name) file.raw_data else - halt 404 + @name = name + mustache :create end end end diff --git a/lib/gollum/frontend/public/css/global.css b/lib/gollum/frontend/public/css/global.css index 9a4b256a..54706a1d 100644 --- a/lib/gollum/frontend/public/css/global.css +++ b/lib/gollum/frontend/public/css/global.css @@ -34,6 +34,12 @@ p { line-height: 22pt; } +#nav { + width: 60em; + margin: 0 auto; + color: #666; +} + #content { width: 60em; margin: 0 auto; @@ -44,6 +50,13 @@ a.absent { color: #a00; } +/* Forms */ + +textarea { + width: 100%; + height: 20em; +} + /* Images */ .frame { diff --git a/lib/gollum/frontend/templates/create.mustache b/lib/gollum/frontend/templates/create.mustache new file mode 100644 index 00000000..1678ccff --- /dev/null +++ b/lib/gollum/frontend/templates/create.mustache @@ -0,0 +1,13 @@ +
a J. R. R. Tolkien's b
\n}, output 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 %{a
b