From 51ce0d65c3187baba02ee2fb955593fd988c70ed Mon Sep 17 00:00:00 2001 From: Giovanni Date: Fri, 5 Nov 2010 11:18:16 +0100 Subject: [PATCH 1/2] remove use_in_file_templates! deprecated since sinatra 1.0; add public folder; add views folder --- git-wiki.rb | 46 +--------------------------- public/stylesheets/default_theme.css | 17 ++++++++++ views/edit.haml | 10 ++++++ views/layout.haml | 12 ++++++++ views/list.haml | 9 ++++++ views/show.haml | 8 +++++ 6 files changed, 57 insertions(+), 45 deletions(-) create mode 100644 public/stylesheets/default_theme.css create mode 100644 views/edit.haml create mode 100644 views/layout.haml create mode 100644 views/list.haml create mode 100644 views/show.haml diff --git a/git-wiki.rb b/git-wiki.rb index aad7d1cc..84b70d81 100755 --- a/git-wiki.rb +++ b/git-wiki.rb @@ -128,7 +128,6 @@ class App < Sinatra::Base set :app_file, __FILE__ set :haml, { :format => :html5, :attr_wrapper => '"' } - use_in_file_templates! error PageNotFound do page = request.env["sinatra.error"].name @@ -174,47 +173,4 @@ def list_item(page) %Q{#{page.name}} end end -end - -__END__ -@@ layout -!!! -%html - %head - %title= title - %body - %ul - %li - %a{ :href => "/#{GitWiki.homepage}" } Home - %li - %a{ :href => "/pages" } All pages - #content= yield - -@@ show -- title @page.name -#edit - %a{:href => "/#{@page}/edit"} Edit this page -%h1= title -#content - ~"#{@page.to_html}" - -@@ edit -- title "Editing #{@page.name}" -%h1= title -%form{:method => 'POST', :action => "/#{@page}"} - %p - %textarea{:name => 'body', :rows => 30, :style => "width: 100%"}= @page.content - %p - %input.submit{:type => :submit, :value => "Save as the newest version"} - or - %a.cancel{:href=>"/#{@page}"} cancel - -@@ list -- title "Listing pages" -%h1 All pages -- if @pages.empty? - %p No pages found. -- else - %ul#list - - @pages.each do |page| - %li= list_item(page) +end \ No newline at end of file diff --git a/public/stylesheets/default_theme.css b/public/stylesheets/default_theme.css new file mode 100644 index 00000000..843290e5 --- /dev/null +++ b/public/stylesheets/default_theme.css @@ -0,0 +1,17 @@ +body { + font-family: Helvetica, Arial, sans; +} + +a, a:active, a:visited { + color: #666; +} + +ul.main_menu { + list-style: none; + margin: 0; + padding: 0; +} + +ul.main_menu li { + display: inline; +} \ No newline at end of file diff --git a/views/edit.haml b/views/edit.haml new file mode 100644 index 00000000..a87ea955 --- /dev/null +++ b/views/edit.haml @@ -0,0 +1,10 @@ +- title "Editing #{@page.name}" + +%h1= title +%form{:method => 'POST', :action => "/#{@page}"} + %p + %textarea{:name => 'body', :rows => 30, :style => "width: 100%"}= @page.content + %p + %input.submit{:type => :submit, :value => "Save as the newest version"} + or + %a.cancel{:href=>"/#{@page}"} cancel \ No newline at end of file diff --git a/views/layout.haml b/views/layout.haml new file mode 100644 index 00000000..09f6edac --- /dev/null +++ b/views/layout.haml @@ -0,0 +1,12 @@ +!!! +%html + %head + %title= title + %link{:href => "/stylesheets/default_theme.css", :rel => "stylesheet", :type => "text/css"} + %body + %ul.main_menu + %li + %a{ :href => "/#{GitWiki.homepage}" } Home + %li + %a{ :href => "/pages" } All pages + #content= yield \ No newline at end of file diff --git a/views/list.haml b/views/list.haml new file mode 100644 index 00000000..31b5c78e --- /dev/null +++ b/views/list.haml @@ -0,0 +1,9 @@ +- title "Listing pages" + +%h1 All pages +- if @pages.empty? + %p No pages found. +- else + %ul#list + - @pages.each do |page| + %li= list_item(page) \ No newline at end of file diff --git a/views/show.haml b/views/show.haml new file mode 100644 index 00000000..86f023c0 --- /dev/null +++ b/views/show.haml @@ -0,0 +1,8 @@ +- title @page.name + +%h1= title +#content + ~"#{@page.to_html}" + +#edit + %a{:href => "/#{@page}/edit"} Edit this page \ No newline at end of file From a369f27586205723c2d35560c1a9408f650cd06a Mon Sep 17 00:00:00 2001 From: Giovanni Date: Fri, 5 Nov 2010 11:30:06 +0100 Subject: [PATCH 2/2] add custom commit message --- git-wiki.rb | 14 +++++++------- views/edit.haml | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/git-wiki.rb b/git-wiki.rb index 84b70d81..5f581268 100755 --- a/git-wiki.rb +++ b/git-wiki.rb @@ -94,26 +94,26 @@ def content @blob.data end - def update_content(new_content) + def update_content(new_content, commit_message) return if new_content == content File.open(file_name, "w") { |f| f << new_content } - add_to_index_and_commit! + add_to_index_and_commit!(commit_message) end private - def add_to_index_and_commit! + def add_to_index_and_commit!(message) Dir.chdir(self.class.repository.working_dir) { self.class.repository.add(@blob.name) } - self.class.repository.commit_index(commit_message) + self.class.repository.commit_index(commit_message(message)) end def file_name File.join(self.class.repository.working_dir, name + self.class.extension) end - def commit_message - new? ? "Created #{name}" : "Updated #{name}" + def commit_message(message) + message.size > 0 ? message : (new? ? "Created #{name}" : "Updated #{name}") end def wiki_link(str) @@ -159,7 +159,7 @@ class App < Sinatra::Base post "/:page" do @page = Page.find_or_create(params[:page]) - @page.update_content(params[:body]) + @page.update_content(params[:body], params[:commit_message]) redirect "/#{@page}" end diff --git a/views/edit.haml b/views/edit.haml index a87ea955..95b458b6 100644 --- a/views/edit.haml +++ b/views/edit.haml @@ -4,6 +4,9 @@ %form{:method => 'POST', :action => "/#{@page}"} %p %textarea{:name => 'body', :rows => 30, :style => "width: 100%"}= @page.content + %p + %label Commit message + %input{:name => 'commit_message', :type => :text, :size => '80'} %p %input.submit{:type => :submit, :value => "Save as the newest version"} or