Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'master' into base-url
Conflicts:
	lib/gollum/frontend/public/gollum/css/_styles.css
	lib/gollum/frontend/public/gollum/javascript/gollum.js
	lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js
	lib/gollum/frontend/templates/file_view.mustache
	lib/gollum/frontend/templates/layout.mustache
	lib/gollum/frontend/templates/page.mustache
  • Loading branch information
sunny committed Jul 25, 2012
2 parents 0269cd0 + f811ac5 commit b565346
Show file tree
Hide file tree
Showing 119 changed files with 1,321 additions and 11,610 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -526,7 +526,7 @@ your changes merged back into core is as follows:
$ gem push gollum-X.Y.Z.gem

## BUILDING THE GEM FROM MASTER

$ gem uninstall -aix gollum
$ git clone https://github.com/github/gollum.git
$ cd gollum
gollum$ rake build
Expand Down
11 changes: 9 additions & 2 deletions bin/gollum
Expand Up @@ -48,11 +48,15 @@ opts = OptionParser.new do |opts|
opts.on("--page-file-dir [PATH]", "Specify the sub directory for all page files (default: repository root).") do |path|
wiki_options[:page_file_dir] = path
end

opts.on("--base-path [PATH]", "Specify the base path.") do |path|
wiki_options[:base_path] = path
end

opts.on("--gollum-path [PATH]", "Specify the gollum path.") do |path|
wiki_options[:gollum_path] = path
end

opts.on("--ref [REF]", "Specify the repository ref to use (default: master).") do |ref|
wiki_options[:ref] = ref
end
Expand All @@ -75,7 +79,10 @@ rescue OptionParser::InvalidOption
exit
end

gollum_path = ARGV[0] || Dir.pwd
# --gollum-path wins over ARGV[0]
gollum_path = wiki_options[:gollum_path] ?
wiki_options[:gollum_path] :
ARGV[0] || Dir.pwd

if options['irb']
require 'irb'
Expand Down
1 change: 1 addition & 0 deletions gollum.gemspec
Expand Up @@ -33,6 +33,7 @@ Gem::Specification.new do |s|
s.add_dependency('sanitize', "~> 2.0.0")
s.add_dependency('nokogiri', "~> 1.4")
s.add_dependency('useragent', "~> 0.4.9")
s.add_dependency('stringex', "~> 1.4.0")

s.add_development_dependency('RedCloth')
s.add_development_dependency('mocha')
Expand Down
69 changes: 27 additions & 42 deletions lib/gollum/file_view.rb
Expand Up @@ -15,19 +15,19 @@ def enclose_tree string

def new_page page
name = page.name
%Q( <li class="file"><a href="#{name}">#{name}</a></li>\n)
url = page.filename_stripped
%Q( <li class="file"><a href="#{url}">#{name}</a></li>\n)
end

def new_folder page
new_sub_folder ::File.dirname(page.path), page.name
def new_folder folder_path
new_sub_folder folder_path
end

def new_sub_folder path, name
def new_sub_folder path
<<-HTML
<li>
<label>#{path}</label> <input type="checkbox" checked />
<ol>
<li class="file"><a href="#{name}">#{name}</a></li>
HTML
end

Expand Down Expand Up @@ -65,11 +65,12 @@ def render_files
if (count - folder_start == 1)
page = @pages[ folder_start ]
name = page.name
url = page.filename_stripped
html += <<-HTML
<li>
<label>#{::File.dirname(page.path)}</label> <input type="checkbox" checked />
<ol>
<li class="file"><a href="#{name}">#{name}</a></li>
<li class="file"><a href="#{url}">#{name}</a></li>
</ol>
</li>
HTML
Expand Down Expand Up @@ -99,54 +100,38 @@ def render_files
end
end

# Process first folder
page = @pages[ sorted_folders[ 0 ][1] ]
html += new_folder page

last_folder = ::File.dirname page.path # define last_folder

# keep track of folder depth, 0 = at root.
depth = 0
cwd_array = []
changed = false

# process rest of folders
1.upto(sorted_folders.size - 1) do | index |
page = @pages[ sorted_folders[ index ][1] ]
(0...sorted_folders.size).each do | index |
page = @pages[ sorted_folders[ index ][ 1 ] ]
path = page.path
folder = ::File.dirname path

if last_folder == folder
# same folder
html += new_page page
elsif folder.include?('/')
# check if we're going up or down a depth level
if last_folder.scan('/').size > folder.scan('/').size
# end tag for 1 subfolder & 1 parent folder
# so emit 2 end tags
2.times { html += end_folder; }
depth -= 1
else
depth += 1
tmp_array = folder.split '/'

(0...tmp_array.size).each do | index |
if cwd_array[ index ].nil? || changed
html += new_sub_folder tmp_array[ index ]
next
end

# subfolder
html += new_sub_folder ::File.dirname(page.path).split('/').last, page.name
else
# depth+1 because we need an additional end_folder
(depth+1).times { html += end_folder; }
depth = 0
# New root folder
html += new_folder page
if cwd_array[ index ] != tmp_array[ index ]
changed = true
(cwd_array.size - index).times do
html += end_folder
end
html += new_sub_folder tmp_array[ index ]
end
end

last_folder = folder
html += new_page page
cwd_array = tmp_array
changed = false
end

# Process last folder's ending tags.
(depth+1).times {
depth.times { html += end_folder; }
depth = 0
}

# return the completed html
enclose_tree html
end # end render_files
Expand Down
70 changes: 51 additions & 19 deletions lib/gollum/frontend/app.rb
Expand Up @@ -3,6 +3,7 @@
require 'gollum'
require 'mustache/sinatra'
require 'useragent'
require 'stringex'

require 'gollum/frontend/views/layout'
require 'gollum/frontend/views/editable'
Expand All @@ -11,6 +12,17 @@
require File.expand_path '../uri_encode_component', __FILE__
require File.expand_path '../helpers', __FILE__

# Fix to_url
class String
alias :upstream_to_url :to_url
# _Header => header which causes errors
def to_url
return nil if self.nil?
return self if ['_Header', '_Footer', '_Sidebar'].include? self
upstream_to_url
end
end

# Run the frontend, based on Sinatra
#
# There are a number of wiki options that can be set for the frontend
Expand All @@ -30,15 +42,17 @@ class App < Sinatra::Base
dir = File.dirname(File.expand_path(__FILE__))

# Detect unsupported browsers.
@@supported_browsers = ['Firefox', 'Chrome', 'Safari']
Browser = Struct.new(:browser, :version)
@@ie9 = Browser.new('Internet Explorer', '9.0')

@@min_ua = [
Browser.new('Internet Explorer', '10.0'),
Browser.new('Chrome', '7.0'),
Browser.new('Firefox', '4.0'),
]

def supported_useragent?(user_agent)
ua = UserAgent.parse(user_agent)
return true if ua >= @@ie9

@@supported_browsers.include? ua.browser
@@min_ua.detect {|min| ua >= min }
end

# We want to serve public assets for now
Expand Down Expand Up @@ -102,7 +116,8 @@ def supported_useragent?(user_agent)
else
@page = page
@page.version = wiki.repo.log(wiki.ref, @page.path).first
@content = page.raw_data
raw_data = page.raw_data
@content = raw_data.respond_to?(:force_encoding) ? raw_data.force_encoding('UTF-8') : raw_data
mustache :edit
end
else
Expand All @@ -111,11 +126,12 @@ def supported_useragent?(user_agent)
end

post '/edit/*' do
path = sanitize_empty_params(params[:path])
path = extract_path(sanitize_empty_params(params[:path]))
wiki_options = settings.wiki_options.merge({ :page_file_dir => path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
page = wiki.page(CGI.unescape(params[:page]))
name = params[:rename] || page.name
rename = params[:rename].to_url if params[:rename]
name = rename || page.name
committer = Gollum::Committer.new(wiki, commit_message)
commit = {:committer => committer}

Expand All @@ -125,23 +141,38 @@ def supported_useragent?(user_agent)
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
committer.commit

page = wiki.page(params[:rename]) if params[:rename]
page = wiki.page(rename) if rename

redirect to("/#{page.escaped_url_path}")
end


get '/delete/*' do
@path = extract_path(params[:splat].first)
@name = extract_name(params[:splat].first)
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
@page = wiki.page(@name)
wiki.delete_page(@page, { :message => "Destroyed #{@name} (#{@page.format})" })

redirect '/'
end

get '/create/*' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@name = params[:splat].first
if wiki.page(@name)
redirect "/#{CGI.escape(@name)}"
@path = extract_path(params[:splat].first)
@name = extract_name(params[:splat].first).to_url
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)

page = wiki.page(@name)
if page
redirect "/#{page.escaped_url_path}"
else
mustache :create
end
end

post '/create' do
name = params[:page]
name = params[:page].to_url
path = sanitize_empty_params(params[:path])
format = params[:format].intern

Expand Down Expand Up @@ -314,17 +345,18 @@ def show_page_or_file(fullpath)
content_type file.mime_type
file.raw_data
else
redirect "/create/#{CGI.escape(name)}"
page_path = [path, name].compact.join('/')
redirect "/create/#{CGI.escape(page_path).gsub('%2F','/')}"
end
end

def update_wiki_page(wiki, page, content, commit_message, name = nil, format = nil)
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
return if !page ||
((!content || page.raw_data == content) && page.format == format)
name ||= page.name
format = (format || page.format).to_sym
content ||= page.raw_data
wiki.update_page(page, name, format, content.to_s, commit_message)
wiki.update_page(page, name, format, content.to_s, commit)
end

def commit_message
Expand Down
1 change: 1 addition & 0 deletions lib/gollum/frontend/helpers.rb
Expand Up @@ -2,6 +2,7 @@ module Precious
module Helpers
# Extract the path string that Gollum::Wiki expects
def extract_path(file_path)
return nil if file_path.nil?
last_slash = file_path.rindex("/")
if last_slash
file_path[0, last_slash]
Expand Down

0 comments on commit b565346

Please sign in to comment.