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 @@ +

Create a new page

+ +
+
+ +
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/lib/gollum/frontend/templates/edit.mustache b/lib/gollum/frontend/templates/edit.mustache new file mode 100644 index 00000000..d3f942ea --- /dev/null +++ b/lib/gollum/frontend/templates/edit.mustache @@ -0,0 +1,10 @@ +

Editing {{name}}

+ +
+
+ +
+
+ +
+
\ No newline at end of file diff --git a/lib/gollum/frontend/templates/layout.mustache b/lib/gollum/frontend/templates/layout.mustache index 5d3ad456..2c4b82ba 100644 --- a/lib/gollum/frontend/templates/layout.mustache +++ b/lib/gollum/frontend/templates/layout.mustache @@ -8,6 +8,9 @@ +
{{{yield}}}
diff --git a/lib/gollum/frontend/views/create.rb b/lib/gollum/frontend/views/create.rb new file mode 100644 index 00000000..30417379 --- /dev/null +++ b/lib/gollum/frontend/views/create.rb @@ -0,0 +1,11 @@ +module Precious + module Views + class Create < Layout + attr_reader :page + + def title + "Create a new page" + end + end + end +end diff --git a/lib/gollum/frontend/views/edit.rb b/lib/gollum/frontend/views/edit.rb new file mode 100644 index 00000000..01153767 --- /dev/null +++ b/lib/gollum/frontend/views/edit.rb @@ -0,0 +1,11 @@ +module Precious + module Views + class Edit < Layout + attr_reader :page, :content + + def title + "Edit" + end + end + end +end diff --git a/lib/gollum/frontend/views/layout.rb b/lib/gollum/frontend/views/layout.rb index ae53aa24..4fba39c3 100644 --- a/lib/gollum/frontend/views/layout.rb +++ b/lib/gollum/frontend/views/layout.rb @@ -4,6 +4,8 @@ module Precious include Rack::Utils alias_method :h, :escape_html + attr_reader :name + def title "Home" end diff --git a/lib/gollum/markup.rb b/lib/gollum/markup.rb index 316c3112..e8802a70 100644 --- a/lib/gollum/markup.rb +++ b/lib/gollum/markup.rb @@ -85,8 +85,15 @@ module Gollum def process_image_tag(tag) parts = tag.split('|') name = parts[0].strip + path = nil 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) containered = false @@ -143,7 +150,7 @@ module Gollum %{} + %{} else - %{} + %{} end end end diff --git a/test/test_markup.rb b/test/test_markup.rb index c0ea7323..e7c023e3 100644 --- a/test/test_markup.rb +++ b/test/test_markup.rb @@ -32,6 +32,16 @@ context "Markup" do assert_equal %{

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

\n}, output + end + end + test "image with absolute path" do index = @wiki.repo.index index.add("alpha.jpg", "hi")