Skip to content
This repository was archived by the owner on Oct 4, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 8 additions & 52 deletions git-wiki.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -160,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

Expand All @@ -174,47 +173,4 @@ def list_item(page)
%Q{<a class="page_name" href="/#{page}">#{page.name}</a>}
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
17 changes: 17 additions & 0 deletions public/stylesheets/default_theme.css
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions views/edit.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- title "Editing #{@page.name}"

%h1= title
%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
%a.cancel{:href=>"/#{@page}"} cancel
12 changes: 12 additions & 0 deletions views/layout.haml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions views/list.haml
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions views/show.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- title @page.name

%h1= title
#content
~"#{@page.to_html}"

#edit
%a{:href => "/#{@page}/edit"} Edit this page