Add --show-all

--show-all will show all files in file view (not just valid pages). Default is false.
This commit is contained in:
bootstraponline
2012-10-22 19:03:21 -06:00
parent a9807bd1e1
commit fbc0548b43
5 changed files with 32 additions and 3 deletions
+4
View File
@@ -68,6 +68,10 @@ opts = OptionParser.new do |opts|
opts.on("--mathjax", "Enables mathjax.") do
wiki_options[:mathjax] = true
end
opts.on("--show-all", "Shows all files in file view. By default only valid pages are shown.") do
wiki_options[:show_all] = true
end
end
# Read command line options into `options` hash
+15 -2
View File
@@ -5,8 +5,12 @@ module Gollum
- Then all the folders are sorted and processed
=end
class FileView
def initialize pages
# common use cases:
# set pages to wiki.pages and show_all to false
# set pages to wiki.files and show_all to true
def initialize pages, show_all = false
@pages = pages
@show_all = show_all
end
def enclose_tree string
@@ -39,7 +43,16 @@ module Gollum
end
def url_for_page page
url = ::File.join(::File.dirname(page.path), page.filename_stripped)
url = ''
if @show_all
# Remove ext for valid pages.
filename = page.filename
filename = Page::valid_page_name?(filename) ? filename.chomp(::File.extname(filename)) : filename
url = ::File.join(::File.dirname(page.path), filename)
else
url = ::File.join(::File.dirname(page.path), page.filename_stripped)
end
url = url[2..-1] if url[0,2] == './'
url
end
+4 -1
View File
@@ -329,7 +329,10 @@ module Precious
get '/fileview' do
wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options)
@results = Gollum::FileView.new(wiki.pages).render_files
show_all = settings.wiki_options[:show_all]
# if showing all files include wiki.files
@results = show_all ? Gollum::FileView.new(wiki.pages + wiki.files, show_all).render_files :
Gollum::FileView.new(wiki.pages).render_files
@ref = wiki.ref
mustache :file_view, { :layout => false }
end
+5
View File
@@ -180,6 +180,7 @@ module Gollum
@live_preview = options.fetch(:live_preview, true)
@universal_toc = options.fetch(:universal_toc, false)
@mathjax = options[:mathjax] || false
@show_all = options[:show_all] || false
end
# Public: check whether the wiki's git repo exists on the filesystem.
@@ -588,6 +589,10 @@ module Gollum
# Toggles mathjax.
attr_reader :mathjax
# Toggles showing all files in files view. Default is false.
# When false, only valid pages in the git repo are displayed.
attr_reader :show_all
# Normalize the data.
#
# data - The String data to be normalized.
+4
View File
@@ -12,6 +12,10 @@ class FakePage
::File.basename(@filepath, ::File.extname(@filepath))
end
def filename
::File.basename(@filepath)
end
def path
return @filepath
end