Skip to content
This repository has been archived by the owner on Feb 28, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into merge_upstream
Browse files Browse the repository at this point in the history
* upstream/master: (81 commits)
  Rename is_supported to supported_useragent?.
  Fall back to old edit mode for browsers that are not officially supported by Ace.
  stay on 1.8.7 for the foreseeable future
  Add --base-path option.
  Call page.versions once.
  Add mathjax using SSL CDN.
  Remove empty line.
  Gem uninstall does not require sudo (pointed out by @michaelklishin).
  nuke the ffi gem on travis boxes
  Update README.md
  Avoid nil.
  Only use versions.
  Avoid nil.
  Merge modified gollum#350.
  Only set parentpage if a subpage was found Fixes error if there's no header or footer
  Use org-ruby 0.6.3. Fixes gollum#86.
  Revert "Merge pull request gollum#350 from blmarket/pageauthor"
  Fix click.
  Remove unload on save.
  Add unload confirmation on live preview, edit, and create.
  ...

Conflicts:
	gollum.gemspec
	lib/gollum/frontend/app.rb
	lib/gollum/frontend/templates/layout.mustache
  • Loading branch information
dazoakley committed May 30, 2012
2 parents bc2b50e + c60ca4a commit a588c48
Show file tree
Hide file tree
Showing 63 changed files with 1,741 additions and 306 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -4,4 +4,5 @@ rvm:
notifications:
disabled: true
before_install:
- sudo apt-get install -y asciidoc
- gem uninstall ffi -a
- sudo apt-get install -y asciidoc
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -59,6 +59,7 @@ utility, you can run it like so:

$ gollum --help

Note that the gollum server will not run on Windows because of [an issue](https://github.com/rtomayko/posix-spawn/issues/9) with posix-spawn (which is used by Grit).

## REPO STRUCTURE

Expand Down Expand Up @@ -288,6 +289,22 @@ wiki page, simply preface the link with a single quote (like in LISP):

This is useful for writing about the link syntax in your wiki pages.

## TABLE OF CONTENTS

Gollum has a special tag to insert a table of contents (new in v2.1)

'[[_TOC_]]

This tag is case sensitive, use all upper case. The TOC tag can be inserted
into the `_Header`, `_Footer` or `_Sidebar` files too.

There is also a wiki option `:universal_toc` which will display a
table of contents at the top of all your wiki pages if it is enabled.
The `:universal_toc` is not enabled by default. To set the option,
add the option to the `:wiki_options` hash before starting the
frontend app:

Precious::App.set(:wiki_options, {:universal_toc => true})

## SYNTAX HIGHLIGHTING

Expand Down Expand Up @@ -470,6 +487,7 @@ like Rack::Auth, OmniAuth, etc.
gollum_path = File.expand_path(File.dirname(__FILE__)) # CHANGE THIS TO POINT TO YOUR OWN WIKI REPO
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown) # set your favorite markup language
Precious::App.set(:wiki_options, {:universal_toc => false})
run Precious::App

## Windows Filename Validation
Expand Down
8 changes: 8 additions & 0 deletions bin/gollum
Expand Up @@ -48,10 +48,18 @@ 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("--ref [REF]", "Specify the repository ref to use (default: master).") do |ref|
wiki_options[:ref] = ref
end

opts.on("--no-mathjax", "Disables mathjax.") do
options['mathjax'] = false
end
end

# Read command line options into `options` hash
Expand Down
4 changes: 3 additions & 1 deletion gollum.gemspec
Expand Up @@ -2,6 +2,7 @@ Gem::Specification.new do |s|
s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.rubygems_version = '1.3.5'
s.required_ruby_version = ">= 1.8.7"

s.name = 'gollum'
s.version = '2.1.0'
Expand Down Expand Up @@ -31,11 +32,12 @@ Gem::Specification.new do |s|
s.add_dependency('mustache', [">= 0.11.2", "< 1.0.0"])
s.add_dependency('sanitize', "~> 2.0.0")
s.add_dependency('nokogiri', "~> 1.4")
s.add_dependency('useragent', "~> 0.4.9")
s.add_dependency('net-ldap', '~> 0.3.1')

s.add_development_dependency('RedCloth')
s.add_development_dependency('mocha')
s.add_development_dependency('org-ruby', '~>0.6.2')
s.add_development_dependency('org-ruby', '~>0.6.3')
s.add_development_dependency('shoulda')
s.add_development_dependency('rack-test')
s.add_development_dependency('wikicloth', '~>0.8.0')
Expand Down
1 change: 1 addition & 0 deletions lib/gollum.rb
Expand Up @@ -15,6 +15,7 @@
require File.expand_path('../gollum/wiki', __FILE__)
require File.expand_path('../gollum/page', __FILE__)
require File.expand_path('../gollum/file', __FILE__)
require File.expand_path('../gollum/file_view', __FILE__)
require File.expand_path('../gollum/markup', __FILE__)
require File.expand_path('../gollum/sanitization', __FILE__)
require File.expand_path('../gollum/tex', __FILE__)
Expand Down
154 changes: 154 additions & 0 deletions lib/gollum/file_view.rb
@@ -0,0 +1,154 @@
module Gollum
=begin
FileView requires that:
- All files in root dir are processed first
- Then all the folders are sorted and processed
=end
class FileView
def initialize pages
@pages = pages
end

def enclose_tree string
%Q(<ol class="tree">\n) + string + %Q(\n</ol>)
end

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

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

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

def end_folder
<<-HTML
</ol>
</li>
HTML
end

def render_files
html = ''
count = @pages.size
folder_start = -1

# Process all pages until folders start
count.times do | index |
page = @pages[ index ]
path = page.path

unless path.include? '/'
# Page processed (not contained in a folder)
html += new_page page
else
# Folders start at the next index
folder_start = index
break # Pages finished, move on to folders
end
end

# If there are no folders, then we're done.
return enclose_tree(html) if folder_start <= -1

# Handle special case of only one folder.
if (count - folder_start == 1)
path = @pages[ folder_start ]
name = page.name
html += <<-HTML
<li>
<label>#{::File.dirname(path)}</label> <input type="checkbox" checked />
<ol>
<li class="file"><a href="#{name}">#{name}</a></li>
</ol>
</li>
HTML

return enclose_tree html
end

sorted_folders = []
(folder_start).upto count - 1 do | index |
sorted_folders += [[ @pages[ index ].path, index ]]
end

# http://stackoverflow.com/questions/3482814/sorting-list-of-string-paths-in-vb-net
sorted_folders.sort! do |first,second|
a = first[0]
b = second[0]

# use :: operator because gollum defines its own conflicting File class
dir_compare = ::File.dirname(a) <=> ::File.dirname(b)

# Sort based on directory name unless they're equal (0) in
# which case sort based on file name.
if dir_compare == 0
::File.basename(a) <=> ::File.basename(b)
else
dir_compare
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

# process rest of folders
1.upto(sorted_folders.size - 1) 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
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
end

last_folder = folder
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
end # end FileView class
end # end Gollum module
48 changes: 42 additions & 6 deletions lib/gollum/frontend/app.rb
Expand Up @@ -3,20 +3,40 @@
require 'sinatra'
require 'gollum'
require 'mustache/sinatra'
require 'useragent'

require 'gollum/frontend/views/layout'
require 'gollum/frontend/views/editable'

require File.expand_path '../uri_encode_component', __FILE__
require File.expand_path '../ldap_authentication', __FILE__

# Run the frontend, based on Sinatra
#
# There are a number of wiki options that can be set for the frontend
#
# Example
# require 'gollum/frontend/app'
# Precious::App.set(:wiki_options, {
# :universal_toc => false,
# }
#
# See the wiki.rb file for more details on wiki options
module Precious
class App < Sinatra::Base
register Mustache::Sinatra
include LdapAuthentication

dir = File.dirname(File.expand_path(__FILE__))

# Detect unsupported browsers.
@@supported_browsers = ['Firefox', 'Chrome', 'Safari']

def supported_useragent?( user_agent )
browser = UserAgent.parse( user_agent ).browser
@@supported_browsers.include? browser
end

# We want to serve public assets for now
set :public_folder, "#{dir}/public/gollum"
set :static, true
Expand Down Expand Up @@ -130,7 +150,7 @@ def extract_format(filename)
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)

if page = wiki.page(@name)
if page.format.to_s.include?('markdown')
if page.format.to_s.include?('markdown') && supported_useragent?(request.user_agent)
redirect '/livepreview/index.html?page=' + encodeURIComponent(@name)
else
@page = page
Expand Down Expand Up @@ -215,10 +235,12 @@ def extract_format(filename)

post '/preview' do
authentication_required!
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@name = "Preview"
@page = wiki.preview_page(@name, params[:content], params[:format])
@content = @page.formatted_data
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@name = "Preview"
@page = wiki.preview_page(@name, params[:content], params[:format])
@content = @page.formatted_data
@toc_content = wiki.universal_toc ? @page.toc_data : nil
@mathjax = wiki.mathjax
@editable = false
mustache :page
end
Expand Down Expand Up @@ -311,6 +333,17 @@ def extract_format(filename)
mustache :pages
end

get '/fileview' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@results = Gollum::FileView.new(wiki.pages).render_files
File.open('/tmp/log.txt', 'w') {|f|
f.puts "log!"
f.puts @results
}
@ref = wiki.ref
mustache :file_view
end

get '/*' do
authentication_required!
show_page_or_file(params[:splat].first)
Expand All @@ -321,8 +354,11 @@ def show_page_or_file(name)
if page = wiki.page(name)
@page = page
@name = name
@content = page.formatted_data
@editable = true
@content = page.formatted_data
@toc_content = wiki.universal_toc ? @page.toc_data : nil
@mathjax = wiki.mathjax

mustache :page
elsif file = wiki.file(name)
content_type file.mime_type
Expand Down

0 comments on commit a588c48

Please sign in to comment.