From fbc0548b43ee562d50473eb49cab4b1635cf88d0 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Mon, 22 Oct 2012 19:03:21 -0600 Subject: [PATCH] Add --show-all --show-all will show all files in file view (not just valid pages). Default is false. --- bin/gollum | 4 ++++ lib/gollum/file_view.rb | 17 +++++++++++++++-- lib/gollum/frontend/app.rb | 5 ++++- lib/gollum/wiki.rb | 5 +++++ test/test_file_view.rb | 4 ++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/bin/gollum b/bin/gollum index 38ce38cd..924144a1 100755 --- a/bin/gollum +++ b/bin/gollum @@ -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 diff --git a/lib/gollum/file_view.rb b/lib/gollum/file_view.rb index 272f1d9a..b869ddf4 100644 --- a/lib/gollum/file_view.rb +++ b/lib/gollum/file_view.rb @@ -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 diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 9aa0ae47..b01b7daa 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -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 diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index c1bde58a..58051690 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -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. diff --git a/test/test_file_view.rb b/test/test_file_view.rb index a801b89b..b943f52a 100644 --- a/test/test_file_view.rb +++ b/test/test_file_view.rb @@ -12,6 +12,10 @@ class FakePage ::File.basename(@filepath, ::File.extname(@filepath)) end + def filename + ::File.basename(@filepath) + end + def path return @filepath end