Compare commits

..

52 Commits

Author SHA1 Message Date
Bart Kamphorst 906dab700f Normalize the page contents used to create a PreviewPage. Fixes #1617. 2020-09-20 18:32:15 +02:00
Bart Kamphorst c5894dd4df Filter _Template content. Proposed solution to #1603. 2020-08-25 16:55:00 +02:00
Dawa Ometto 986a76cf8e Release 5.1.1 2020-08-11 12:57:42 +02:00
Dawa Ometto 42439033c8 Release 5.1 2020-08-03 19:07:32 +02:00
Dawa Ometto 421ff18788 Updating assets for bugfix release. 2020-08-03 19:01:29 +02:00
Dawa Ometto 519a275ff0 Fix mathjax config path (#1605)
Related to #1602
2020-08-03 19:00:49 +02:00
Watal M. Iwasaki 5a95f79b32 Ensure page_route starts with a leading slash (#1604)
* Ensure page_route starts with a leading slash

* Handle base_url = nil in page_route()

* Refactor page_route()
2020-08-03 18:09:57 +02:00
Dawa Ometto 627ee5bbbe Merge pull request #1595 from heavywatal/upload-whitespaced-file
Address the uploads issue. Resolves #1584
2020-08-03 18:05:27 +02:00
Dawa Ometto a9d300341c Merge pull request #1594 from heavywatal/empty-search
Show search page even when no parameters are given
2020-07-15 12:46:18 +02:00
Dawa Ometto 6b7e912010 Merge pull request #1593 from heavywatal/fix-home-button
Address home button issue #1590
2020-07-15 12:44:13 +02:00
Watal M. Iwasaki 4feae80814 Update assets 2020-07-12 17:39:18 +09:00
Watal M. Iwasaki 5f5730fe2e Address the uploads issue #1584
'%20' in filenames are translated back to ' ' in both editor and file creation.
2020-07-12 17:37:20 +09:00
Watal M. Iwasaki 5f784f5e10 Show search page even when no parameters are given
This PR addresses the issue #1586
2020-07-12 15:22:18 +09:00
Watal M. Iwasaki 35a44efafd Address home button issue #1590
A trailing slash is added.
This fixes the behavior when base_url is nil.
2020-07-12 13:41:41 +09:00
Dawa Ometto b32dcfa8dd Merge pull request #1580 from heavywatal/reduce-direct-base_url
Reduce direct use of base_url
2020-06-17 10:37:15 +02:00
Watal M. Iwasaki 38fc32bbdd Return nil if url.empty? right after url.comact! 2020-06-16 17:55:01 +09:00
Watal M. Iwasaki 6c7b12ae5e Restore base_url for baseUrl in JavaScript 2020-06-16 17:29:32 +09:00
Dawa Ometto 649e19bdb1 Merge pull request #1578 from tpoliaw/no-edit-compare
Let compare versions be used in no-edit mode
2020-06-15 12:13:34 +02:00
Watal M. Iwasaki a4266170ea Address the issue #1572 (#1581)
* Add double-quote to data-file-path={{url}}
2020-06-15 12:02:32 +02:00
Watal M. Iwasaki 6e6d9d8c1f Use page_route() for custom.css, custom.js, and MathJax 2020-06-14 23:11:07 +09:00
Watal M. Iwasaki e49758334f Replace base_url with page_route() 2020-06-14 23:11:07 +09:00
Watal M. Iwasaki 580068212d Remove base_url from search.mustache 2020-06-14 23:11:07 +09:00
Watal M. Iwasaki 504278d9ba Move full_url_path from HasPage to Page
so that page_route() is accessible via Layout
2020-06-14 23:11:07 +09:00
Watal M. Iwasaki 214056a88a Refactor regex in clean_url() 2020-06-14 23:11:07 +09:00
Watal M. Iwasaki e310f76030 Enhance RouteHelpers
- page_route() accepts nil and return base_url
- clean_url() accepts multiple args and join them
2020-06-14 23:11:07 +09:00
Peter Holloway 83abe62125 Use GET for compare methods
POST requests are blocked when running in --no-edit mode so using POST
prevents compare being available (see #1546).

Change the history view form to use "get" as the form method and change
the routing in app to accept get requests for both forms of compare. The
order of the compare routes is switched to make the more specific form
checked first to prevent all requests being handled by the less specific
form.
2020-06-10 23:27:48 +01:00
Bart Kamphorst 8e7a714991 Merge pull request #1577 from gollum/fix_1571
Remove superfluous closing div tag. Add ids to all navigation buttons.
2020-06-09 09:30:27 +02:00
Bart Kamphorst 4f67710ed2 Remove superfluous closing div tag. Add ids to all navigation buttons. 2020-06-08 22:09:04 +02:00
Bart Kamphorst 8ec8be5db3 Merge pull request #1576 from mivok/feature/auto_save
Add auto save functionality
2020-06-08 21:26:54 +02:00
Watal M. Iwasaki 92da563211 Add quick access to diff of each commit in the history (#1555) 2020-06-08 20:49:34 +02:00
Mark Harrison 2eb5a7e4b8 Remove flash-full from the notification class list
It doesn't look right with the banner in the new position.
2020-06-05 22:59:20 -04:00
Mark Harrison 23110d5f05 Add autosave/restore for subpages too 2020-06-05 22:51:14 -04:00
Mark Harrison 18de3272e3 Move autosave message elements into the template 2020-06-05 21:34:07 -04:00
Mark Harrison 1e81c42818 Add auto save functionality
Fixes #527

This adds auto saving to gollum using local storage.
2020-06-04 22:30:40 -04:00
Dawa Ometto ef6e0e8a07 Fix gollum link tag highlighting (#1566) 2020-05-15 10:29:38 +02:00
Watal M. Iwasaki ba575b886d Simulate 'git show' when a single version is posted from /history/ (#1543) 2020-04-16 12:50:45 +02:00
Dawa Ometto c8f856109d Set environment to production when precompiling (#1554) 2020-04-14 11:50:29 +02:00
Sven Schwyn 4035c579c7 Don't uglify JS in development env (#1551) 2020-04-14 11:22:48 +02:00
Bart Kamphorst 8bab3de510 Merge pull request #1549 from yuttie/yuttie-patch-fix-data-file-path
Fix `data-file-path` in overview pages
2020-04-10 13:02:13 +02:00
Yuta Taniguchi 9ab4bbb17c Fix data-file-path
This correct the `data-file-path` attribute's value so that the value includes the ancestor directories to a file.
2020-04-09 23:51:02 +09:00
Bart Kamphorst ae024eb3b3 Merge pull request #1547 from heavywatal/flash-notice-h1
Fix a selector in flashNotice()
2020-04-08 20:16:04 +02:00
Watal M. Iwasaki db84653bf2 Fix a selector in flashNotice()
The original selector "#wiki-content h1" matches multiple times
when the page content has h1 headers, resulting in multiple notice
in a page, and what is worse, "$('#gollum-flash').fadeOut()" works
only for the first one.
2020-04-08 22:45:49 +09:00
Dawa Ometto d8ebba114f Release 5.0.1 2020-04-04 13:44:00 +02:00
Dawa Ometto b9d7375dba Fix migration script when using page-file-dir (#1542) 2020-04-04 13:43:29 +02:00
Dawa Ometto 676811206d Add tests for base_path (#1540) 2020-04-03 17:12:09 +02:00
Watal M. Iwasaki ff1baf0036 Replace redirect_to() with 'redirect to()` (#1536) 2020-04-03 15:32:51 +02:00
Sam 3d12aeb8b2 Update layout.mustache (#1539)
Fix loading of MathJax when run with a base path.
2020-04-03 15:28:00 +02:00
Dawa Ometto 5a8750a975 Fix migrate script path argument. Fix gollum --version (#1538) 2020-04-02 14:08:17 +02:00
Watal M. Iwasaki 0cb303f09f Check page.nil? before page.wiki (#1535) 2020-04-02 11:07:33 +02:00
Dawa Ometto edc7d0b50b Merge pull request #1531 from repotag/check_empty_repo
Add regression test against #1530
2020-03-31 16:51:19 +02:00
Dawa Ometto 2c268a9f8c Add regression test against #1530 2020-03-31 11:56:42 +02:00
Dawa Ometto d61a09d421 Update README.md 2020-03-30 12:33:57 +02:00
40 changed files with 450 additions and 149 deletions
+6
View File
@@ -1,3 +1,9 @@
# 5.1
* Bugfixes
* Add autosave feature (#1576)
* Add Add quick access to diff of each commit in the history
# 5.0 / 2020-03-17 # 5.0 / 2020-03-17
This is a major new release that introduces many new features, bugfixes, and removes major limitations. See [here](https://github.com/gollum/gollum/wiki/5.0-release-notes) for a list of changes. This is a major new release that introduces many new features, bugfixes, and removes major limitations. See [here](https://github.com/gollum/gollum/wiki/5.0-release-notes) for a list of changes.
+3 -1
View File
@@ -5,6 +5,8 @@ gollum -- A git-based Wiki
[![Build Status](https://travis-ci.org/gollum/gollum.svg?branch=master)](https://travis-ci.org/gollum/gollum) [![Build Status](https://travis-ci.org/gollum/gollum.svg?branch=master)](https://travis-ci.org/gollum/gollum)
[![Open Source Helpers](https://www.codetriage.com/gollum/gollum/badges/users.svg)](https://www.codetriage.com/gollum/gollum) [![Open Source Helpers](https://www.codetriage.com/gollum/gollum/badges/users.svg)](https://www.codetriage.com/gollum/gollum)
**Please update to gollum 5.1.1 to counter a recent exploit in the kramdown rendering gem, [CVE-2020-14001](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-14001)**
**Gollum version 5.0 is out!** See [here](https://github.com/gollum/gollum/wiki/5.0-release-notes) for a list of changes and new features compared to Gollum version 4.x, and see some [Screenshots](https://github.com/gollum/gollum/wiki/Screenshots) of Gollum's features. **Gollum version 5.0 is out!** See [here](https://github.com/gollum/gollum/wiki/5.0-release-notes) for a list of changes and new features compared to Gollum version 4.x, and see some [Screenshots](https://github.com/gollum/gollum/wiki/Screenshots) of Gollum's features.
## DESCRIPTION ## DESCRIPTION
@@ -17,7 +19,7 @@ Gollum is a simple wiki system built on top of Git. A Gollum Wiki is simply a gi
* May be written in a variety of [markups](#markups). * May be written in a variety of [markups](#markups).
* Can be edited with your favourite system editor or IDE (changes will be visible after committing) or with the built-in web interface. * Can be edited with your favourite system editor or IDE (changes will be visible after committing) or with the built-in web interface.
* Can be displayed in all versions, reverted, etc. * Can be displayed in all versions, reverted, etc.
* Gollum strives to be compatible with GitHub wikis (see `--hyphened-tag-lookup`) * Gollum strives to be compatible with GitHub wikis (see `--lenient-tag-lookup`)
* Gollum supports advanced functionality like: * Gollum supports advanced functionality like:
* [UML diagrams](https://github.com/gollum/gollum/wiki#plantuml-diagrams) * [UML diagrams](https://github.com/gollum/gollum/wiki#plantuml-diagrams)
* [BibTeX and Citation support](https://github.com/gollum/gollum/wiki/BibTeX-and-Citations) * [BibTeX and Citation support](https://github.com/gollum/gollum/wiki/BibTeX-and-Citations)
+2 -5
View File
@@ -181,11 +181,8 @@ end
desc 'Precompile assets' desc 'Precompile assets'
task :precompile do task :precompile do
require './lib/gollum/views/helpers.rb' require './lib/gollum/app.rb'
require './lib/gollum/assets.rb' Precious::App.set(:environment, :production)
require 'sprockets'
require 'sprockets-helpers'
require 'sass'
env = Precious::Assets.sprockets env = Precious::Assets.sprockets
path = ENV.fetch('GOLLUM_ASSETS_PATH', ::File.join(File.dirname(__FILE__), 'lib/gollum/public/assets')) path = ENV.fetch('GOLLUM_ASSETS_PATH', ::File.join(File.dirname(__FILE__), 'lib/gollum/public/assets'))
manifest = Sprockets::Manifest.new(env, path) manifest = Sprockets::Manifest.new(env, path)
+2 -23
View File
@@ -172,6 +172,7 @@ MSG
end end
opts.on('--version', 'Display the current version of Gollum.') do opts.on('--version', 'Display the current version of Gollum.') do
puts 'Gollum ' + Gollum::VERSION puts 'Gollum ' + Gollum::VERSION
exit 0
end end
opts.on('--versions', 'Display the current version of Gollum and auxiliary gems.') do opts.on('--versions', 'Display the current version of Gollum and auxiliary gems.') do
require 'gollum-lib' require 'gollum-lib'
@@ -286,29 +287,7 @@ else
else else
require 'rack' require 'rack'
class MapGollum
def initialize(base_path)
@mg = Rack::Builder.new do
map "/#{base_path}" do
run Precious::App
end
map '/' do
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
end
map '/*' do
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
end
end
end
def call(env)
@mg.call(env)
end
end
# Rack::Handler does not work with Ctrl + C. Use Rack::Server instead. # Rack::Handler does not work with Ctrl + C. Use Rack::Server instead.
Rack::Server.new(:app => MapGollum.new(base_path), :Port => options[:port], :Host => options[:bind]).start Rack::Server.new(:app => Precious::MapGollum.new(base_path), :Port => options[:port], :Host => options[:bind]).start
end end
end end
+4 -3
View File
@@ -4,8 +4,6 @@ require 'optparse'
require 'pathname' require 'pathname'
require 'rubygems' require 'rubygems'
REPO = ARGV[0] || Dir.pwd
wiki_options = {} wiki_options = {}
options = {} options = {}
@@ -83,12 +81,15 @@ begin
const = setting.to_s.upcase const = setting.to_s.upcase
Object.const_set(const, value) unless Object.const_defined?(const) Object.const_set(const, value) unless Object.const_defined?(const)
end end
wiki_options[:page_file_dir] = setting(:page_file_dir) ? setting(:page_file_dir) : wiki_options[:page_file_dir] # Allow settings :page_file_dir through PAGE_FILE_DIR constant.
rescue OptionParser::InvalidOption rescue OptionParser::InvalidOption
puts "gollum-migrate-tags: #{$!.message}" puts "gollum-migrate-tags: #{$!.message}"
puts "gollum-migrate-tags: try 'gollum-migrate-tags --help' for more information" puts "gollum-migrate-tags: try 'gollum-migrate-tags --help' for more information"
exit exit
end end
REPO = ARGV[0] || Dir.pwd
require 'gollum-lib' require 'gollum-lib'
if cfg = options[:config] if cfg = options[:config]
@@ -261,7 +262,7 @@ wiki.pages.each do |page|
log(:info,"Page #{page.path}") log(:info,"Page #{page.path}")
new_data = page.formatted_data new_data = page.formatted_data
if setting(:no_dry_run) if setting(:no_dry_run)
path = ::File.join([wiki.path, wiki.page_file_dir, page.path].compact) path = ::File.join(wiki.path, page.path)
f = File.new(path, 'w') f = File.new(path, 'w')
f.write(new_data) f.write(new_data)
f.close f.close
+10 -8
View File
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 1.9' s.required_ruby_version = '>= 1.9'
s.name = 'gollum' s.name = 'gollum'
s.version = '5.0.0' s.version = '5.1.1'
s.date = '2020-03-30' s.date = '2020-08-11'
s.license = 'MIT' s.license = 'MIT'
s.summary = 'A simple, Git-powered wiki.' s.summary = 'A simple, Git-powered wiki.'
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
s.extra_rdoc_files = %w[README.md LICENSE] s.extra_rdoc_files = %w[README.md LICENSE]
s.add_dependency 'gollum-lib', '~> 5.0' s.add_dependency 'gollum-lib', '~> 5.0'
s.add_dependency 'kramdown', '~> 2.1.0' s.add_dependency 'kramdown', '~> 2.3'
s.add_dependency 'kramdown-parser-gfm', '~> 1.0.0' s.add_dependency 'kramdown-parser-gfm', '~> 1.0.0'
s.add_dependency 'sinatra', '~> 2.0' s.add_dependency 'sinatra', '~> 2.0'
s.add_dependency 'sinatra-contrib', '~> 2.0' s.add_dependency 'sinatra-contrib', '~> 2.0'
@@ -68,15 +68,15 @@ Gem::Specification.new do |s|
lib/gollum/app.rb lib/gollum/app.rb
lib/gollum/assets.rb lib/gollum/assets.rb
lib/gollum/helpers.rb lib/gollum/helpers.rb
lib/gollum/public/assets/.sprockets-manifest-3edc7e21737459b21fbf150f5dccd15c.json lib/gollum/public/assets/.sprockets-manifest-459226ba5fc211b78ba9a3aa6ebde96c.json
lib/gollum/public/assets/app-982c7fca1832732a24e92474ca2729aeb56f2d0c05bb7a8ff913e9f58a6500d5.js lib/gollum/public/assets/app-6e925e38a12a40c4fa9e0400cc874e0f4f97b66fdeb90a144dea527dbb544fbd.js
lib/gollum/public/assets/app-982c7fca1832732a24e92474ca2729aeb56f2d0c05bb7a8ff913e9f58a6500d5.js.gz lib/gollum/public/assets/app-6e925e38a12a40c4fa9e0400cc874e0f4f97b66fdeb90a144dea527dbb544fbd.js.gz
lib/gollum/public/assets/app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css lib/gollum/public/assets/app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css
lib/gollum/public/assets/app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css.gz lib/gollum/public/assets/app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css.gz
lib/gollum/public/assets/criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css lib/gollum/public/assets/criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css
lib/gollum/public/assets/criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css.gz lib/gollum/public/assets/criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css.gz
lib/gollum/public/assets/editor-0dbae28c53db5a73d666d30504946671eb09948ffdaf1fdd9d1c8d856d4c0ba1.js lib/gollum/public/assets/editor-b2c10f22ef6ca1e120956a2d11ff4ca19ac44d7e7240f5cc43ec949184d8b708.js
lib/gollum/public/assets/editor-0dbae28c53db5a73d666d30504946671eb09948ffdaf1fdd9d1c8d856d4c0ba1.js.gz lib/gollum/public/assets/editor-b2c10f22ef6ca1e120956a2d11ff4ca19ac44d7e7240f5cc43ec949184d8b708.js.gz
lib/gollum/public/assets/print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css lib/gollum/public/assets/print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css
lib/gollum/public/assets/print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css.gz lib/gollum/public/assets/print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css.gz
lib/gollum/public/gollum/javascript/HOWTO_UPDATE_ACE.md lib/gollum/public/gollum/javascript/HOWTO_UPDATE_ACE.md
@@ -1190,6 +1190,7 @@ Gem::Specification.new do |s|
lib/gollum/public/gollum/stylesheets/spinner.scss lib/gollum/public/gollum/stylesheets/spinner.scss
lib/gollum/public/gollum/stylesheets/tables.scss lib/gollum/public/gollum/stylesheets/tables.scss
lib/gollum/public/gollum/stylesheets/template.scss.erb lib/gollum/public/gollum/stylesheets/template.scss.erb
lib/gollum/templates/commit.mustache
lib/gollum/templates/compare.mustache lib/gollum/templates/compare.mustache
lib/gollum/templates/create.mustache lib/gollum/templates/create.mustache
lib/gollum/templates/edit.mustache lib/gollum/templates/edit.mustache
@@ -1209,6 +1210,7 @@ Gem::Specification.new do |s|
lib/gollum/templates/searchbar.mustache lib/gollum/templates/searchbar.mustache
lib/gollum/templates/wiki_content.mustache lib/gollum/templates/wiki_content.mustache
lib/gollum/uri_encode_component.rb lib/gollum/uri_encode_component.rb
lib/gollum/views/commit.rb
lib/gollum/views/compare.rb lib/gollum/views/compare.rb
lib/gollum/views/create.rb lib/gollum/views/create.rb
lib/gollum/views/edit.rb lib/gollum/views/edit.rb
+1 -1
View File
@@ -12,7 +12,7 @@ require 'rhino' if RUBY_PLATFORM == 'java'
require File.expand_path('../gollum/uri_encode_component', __FILE__) require File.expand_path('../gollum/uri_encode_component', __FILE__)
module Gollum module Gollum
VERSION = '5.0.0' VERSION = '5.1.1'
def self.assets_path def self.assets_path
::File.expand_path('gollum/public', ::File.dirname(__FILE__)) ::File.expand_path('gollum/public', ::File.dirname(__FILE__))
+82 -24
View File
@@ -40,6 +40,30 @@ Gollum::set_git_max_filesize(190 * 10**6)
# See the wiki.rb file for more details on wiki options # See the wiki.rb file for more details on wiki options
module Precious module Precious
# For use with the --base-path option.
class MapGollum
def initialize(base_path)
@mg = Rack::Builder.new do
map "/#{base_path}" do
run Precious::App
end
map '/' do
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
end
map '/*' do
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
end
end
end
def call(env)
@mg.call(env)
end
end
class App < Sinatra::Base class App < Sinatra::Base
register Mustache::Sinatra register Mustache::Sinatra
register Sinatra::Namespace register Sinatra::Namespace
@@ -188,7 +212,8 @@ module Precious
@etag = page.sha @etag = page.sha
mustache :edit mustache :edit
else else
redirect_to("/create/#{encodeURIComponent(@name)}") path = ::File.join('gollum/create', @path, @name)
redirect to(clean_url(encodeURIComponent(path)))
end end
end end
@@ -205,14 +230,15 @@ module Precious
halt 500 unless tempfile.is_a? Tempfile halt 500 unless tempfile.is_a? Tempfile
if wiki.per_page_uploads if wiki.per_page_uploads
# remove base_url and gollum/* subpath if necessary dir = request.referer.sub(request.base_url, '')
dir = request.referer.
sub(request.base_url, '').
sub(/.*gollum\/[-\w]+\//, '')
# remove base path if it is set # remove base path if it is set
dir = dir.sub(wiki.base_path, '') if wiki.base_path dir.sub!(/^#{wiki.base_path}/, '') if wiki.base_path
# remove base_url and gollum/* subpath if necessary
dir.sub!(/^\/gollum\/[-\w]+\//, '')
# remove file extension # remove file extension
dir = dir.sub(::File.extname(dir), '') dir.sub!(/#{::File.extname(dir)}$/, '')
# revert escaped whitespaces
dir.gsub!(/%20/, ' ')
dir = ::File.join('uploads', dir) dir = ::File.join('uploads', dir)
else else
# store all uploads together # store all uploads together
@@ -329,6 +355,9 @@ module Precious
if settings.wiki_options[:template_page] then if settings.wiki_options[:template_page] then
temppage = wiki_page('/_Template') temppage = wiki_page('/_Template')
@template_page = (temppage.page != nil) ? temppage.page.raw_data : 'Template page option is set, but no /_Template page is present or committed.' @template_page = (temppage.page != nil) ? temppage.page.raw_data : 'Template page option is set, but no /_Template page is present or committed.'
if defined?(Gollum::TemplateFilter)
@template_page = Gollum::TemplateFilter.filter(@template_page)
end
end end
wikip = wiki_page(params[:splat].first) wikip = wiki_page(params[:splat].first)
@name = wikip.name @name = wikip.name
@@ -392,7 +421,7 @@ module Precious
post '/preview' do post '/preview' do
wiki = wiki_new wiki = wiki_new
@name = params[:page] ? strip_page_name(CGI.unescape(params[:page])) : 'Preview' @name = params[:page] ? strip_page_name(CGI.unescape(params[:page])) : 'Preview'
@page = wiki.preview_page(@name, params[:content], params[:format]) @page = wiki.preview_page(@name, wiki.normalize(params[:content]), params[:format])
['sidebar', 'header', 'footer'].each do |subpage| ['sidebar', 'header', 'footer'].each do |subpage|
@page.send("set_#{subpage}".to_sym, params[subpage]) if params[subpage] @page.send("set_#{subpage}".to_sym, params[subpage]) if params[subpage]
end end
@@ -413,8 +442,8 @@ module Precious
@page = wikip.page @page = wikip.page
@page_num = [params[:page_num].to_i, 1].max @page_num = [params[:page_num].to_i, 1].max
@max_count = settings.wiki_options.fetch(:pagination_count, 10) @max_count = settings.wiki_options.fetch(:pagination_count, 10)
@wiki = @page.wiki
unless @page.nil? unless @page.nil?
@wiki = @page.wiki
@versions = @page.versions( @versions = @page.versions(
per_page: @max_count, per_page: @max_count,
page_num: @page_num, page_num: @page_num,
@@ -434,20 +463,6 @@ module Precious
mustache :latest_changes mustache :latest_changes
end end
post '/compare/*' do
@file = encodeURIComponent(params[:splat].first)
@versions = params[:versions] || []
if @versions.size < 2
redirect_to("/history/#{@file}")
else
redirect_to("/compare/%s/%s...%s" % [
@file,
@versions.last,
@versions.first]
)
end
end
get %r{ get %r{
/compare/ # match any URL beginning with /compare/ /compare/ # match any URL beginning with /compare/
(.+) # extract the full path (including any directories) (.+) # extract the full path (including any directories)
@@ -471,8 +486,51 @@ module Precious
end end
end end
get '/compare/*' do
@file = clean_url(encodeURIComponent(params[:splat].first))
@versions = params[:versions] || []
if @versions.size == 1
wikip = wiki_page(params[:splat].first)
commit = wikip.wiki.repo.commit(@versions.first)
parent = commit.parent
if parent.nil?
redirect to("#{@file}/#{@commit.id}")
else
@versions.push(parent.id)
end
end
if @versions.empty?
redirect to("gollum/history/#{@file}")
else
redirect to("gollum/compare/%s/%s...%s" % [
@file,
@versions.last,
@versions.first]
)
end
end
get %r{
/commit/ # match any URL beginning with /show/
(\w+) # match the SHA1
}x do |version|
@version = version
wiki = wiki_new
begin
@commit = wiki.repo.commit(version)
parent = @commit.parent
parent_id = parent.nil? ? nil : parent.id
@diff = wiki.repo.diff(parent_id, version)
mustache :commit
rescue Gollum::Git::NoSuchShaFound
@message = "Invalid commit: #{@version}"
mustache :error
end
end
get '/search' do get '/search' do
@query = params[:q] @query = params[:q] || ''
@name = @query @name = @query
if @query.empty? if @query.empty?
@results = [] @results = []
+3 -3
View File
@@ -4,7 +4,7 @@ module Precious
module Assets module Assets
MANIFEST = %w(app.js editor.js app.css criticmarkup.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf) MANIFEST = %w(app.js editor.js app.css criticmarkup.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf)
ASSET_URL = 'gollum/assets' ASSET_URL = 'gollum/assets'
def self.sprockets(dir = File.dirname(File.expand_path(__FILE__))) def self.sprockets(dir = File.dirname(File.expand_path(__FILE__)))
env = Sprockets::Environment.new env = Sprockets::Environment.new
env.append_path ::File.join(dir, 'public/gollum/stylesheets/') env.append_path ::File.join(dir, 'public/gollum/stylesheets/')
@@ -12,7 +12,7 @@ module Precious
env.append_path ::File.join(dir, 'public/gollum/images') env.append_path ::File.join(dir, 'public/gollum/images')
env.append_path ::File.join(dir, 'public/gollum/fonts') env.append_path ::File.join(dir, 'public/gollum/fonts')
env.js_compressor = :uglify env.js_compressor = :uglify unless Precious::App.development?
env.css_compressor = :scss env.css_compressor = :scss
env.context_class.class_eval do env.context_class.class_eval do
@@ -26,4 +26,4 @@ module Precious
env env
end end
end end
end end
+1 -1
View File
@@ -19,7 +19,7 @@ module Precious
# Remove all double slashes # Remove all double slashes
def clean_url(url) def clean_url(url)
return url if url.nil? return url if url.nil?
url.gsub('%2F', '/').gsub(/^\/+/, '').gsub('//', '/') url.gsub('%2F', '/').gsub(%r{/{2,}}, '/').gsub(%r{^/}, '')
end end
def forbid(msg = "Forbidden. This wiki is set to no-edit mode.") def forbid(msg = "Forbidden. This wiki is set to no-edit mode.")
@@ -1 +1 @@
{"files":{"app-982c7fca1832732a24e92474ca2729aeb56f2d0c05bb7a8ff913e9f58a6500d5.js":{"logical_path":"app.js","mtime":"2020-03-30T11:12:22+02:00","size":136039,"digest":"982c7fca1832732a24e92474ca2729aeb56f2d0c05bb7a8ff913e9f58a6500d5","integrity":"sha256-mCx/yhgycyok6SR0yicprrVvLQwFu3qP+RPp9YplANU="},"editor-0dbae28c53db5a73d666d30504946671eb09948ffdaf1fdd9d1c8d856d4c0ba1.js":{"logical_path":"editor.js","mtime":"2020-03-29T22:28:50+02:00","size":746117,"digest":"0dbae28c53db5a73d666d30504946671eb09948ffdaf1fdd9d1c8d856d4c0ba1","integrity":"sha256-DbrijFPbWnPWZtMFBJRmcesJlI/9rx/dnRyNhW1MC6E="},"app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css":{"logical_path":"app.css","mtime":"2020-03-30T11:12:22+02:00","size":298111,"digest":"b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7","integrity":"sha256-sgXlk6MPHMAFTi6e2fyK82WNjvSmK5cIwg8gRWDe77c="},"criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css":{"logical_path":"criticmarkup.css","mtime":"2020-03-29T22:28:51+02:00","size":646,"digest":"31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4","integrity":"sha256-Ma5dMoK7uOe3w8mRfp+2jjMVprSnXabOxI0huIRpBcQ="},"print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css":{"logical_path":"print.css","mtime":"2020-03-30T11:12:22+02:00","size":75,"digest":"512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb","integrity":"sha256-USSYw2i+DT+xuhBd+oQomuSDgOyfy++Ui9TiOwsJW/s="}},"assets":{"app.js":"app-982c7fca1832732a24e92474ca2729aeb56f2d0c05bb7a8ff913e9f58a6500d5.js","editor.js":"editor-0dbae28c53db5a73d666d30504946671eb09948ffdaf1fdd9d1c8d856d4c0ba1.js","app.css":"app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css","criticmarkup.css":"criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css","print.css":"print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css"}} {"files":{"app-6e925e38a12a40c4fa9e0400cc874e0f4f97b66fdeb90a144dea527dbb544fbd.js":{"logical_path":"app.js","mtime":"2020-08-03T18:13:54+02:00","size":136032,"digest":"6e925e38a12a40c4fa9e0400cc874e0f4f97b66fdeb90a144dea527dbb544fbd","integrity":"sha256-bpJeOKEqQMT6ngQAzIdOD0+Xtm/euQoUTepSfbtUT70="},"editor-b2c10f22ef6ca1e120956a2d11ff4ca19ac44d7e7240f5cc43ec949184d8b708.js":{"logical_path":"editor.js","mtime":"2020-08-03T18:13:54+02:00","size":747273,"digest":"b2c10f22ef6ca1e120956a2d11ff4ca19ac44d7e7240f5cc43ec949184d8b708","integrity":"sha256-ssEPIu9soeEglWotEf9MoZrETX5yQPXMQ+yUkYTYtwg="},"app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css":{"logical_path":"app.css","mtime":"2020-03-30T11:12:22+02:00","size":298111,"digest":"b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7","integrity":"sha256-sgXlk6MPHMAFTi6e2fyK82WNjvSmK5cIwg8gRWDe77c="},"criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css":{"logical_path":"criticmarkup.css","mtime":"2020-03-29T22:28:51+02:00","size":646,"digest":"31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4","integrity":"sha256-Ma5dMoK7uOe3w8mRfp+2jjMVprSnXabOxI0huIRpBcQ="},"print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css":{"logical_path":"print.css","mtime":"2020-03-30T11:12:22+02:00","size":75,"digest":"512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb","integrity":"sha256-USSYw2i+DT+xuhBd+oQomuSDgOyfy++Ui9TiOwsJW/s="}},"assets":{"app.js":"app-6e925e38a12a40c4fa9e0400cc874e0f4f97b66fdeb90a144dea527dbb544fbd.js","editor.js":"editor-b2c10f22ef6ca1e120956a2d11ff4ca19ac44d7e7240f5cc43ec949184d8b708.js","app.css":"app-b205e593a30f1cc0054e2e9ed9fc8af3658d8ef4a62b9708c20f204560deefb7.css","criticmarkup.css":"criticmarkup-31ae5d3282bbb8e7b7c3c9917e9fb68e3315a6b4a75da6cec48d21b8846905c4.css","print.css":"print-512498c368be0d3fb1ba105dfa84289ae48380ec9fcbef948bd4e23b0b095bfb.css"}}
@@ -17,6 +17,8 @@
NoDefinitionsFor: [] NoDefinitionsFor: []
}; };
var ActiveOptions = {}; var ActiveOptions = {};
var autoSaveTimer = null;
var storageKey = 'gollum_autorecover_' + window.location;
function isRTL(s){ function isRTL(s){
var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF', var ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF',
@@ -32,6 +34,27 @@
window.ace_editor.renderer.updateFull(); window.ace_editor.renderer.updateFull();
} }
function autoSaveHandler() {
// Autosave
if (autoSaveTimer) {
// Reset the timer because we just changed the text
clearTimeout(autoSaveTimer);
}
$('#gollum-saved-msg').text('Saving...');
// Wait 2 seconds, then actualy save the text to local storage
autoSaveTimer = setTimeout(function() {
localStorage.setItem(storageKey, window.ace_editor.getSession().getValue());
// Save any subpage editor text that might exist
$('#gollum-editor-header, #gollum-editor-footer, #gollum-editor-sidebar').each(function(_, el) {
var spStorageKey = storageKey + el.id.replace('gollum-editor-', '_');
localStorage.setItem(spStorageKey, el.value);
});
$('#gollum-saved-msg').text('Saved recovery text');
}, 2000);
}
/** /**
* $.GollumEditor * $.GollumEditor
* *
@@ -55,6 +78,26 @@
var editor = ace.edit(editDiv[0], {rtlText: true}); var editor = ace.edit(editDiv[0], {rtlText: true});
window.ace_editor = editor; window.ace_editor = editor;
// Check to see if we have any autosaved text and show a message to
// restore it if present.
var savedText = localStorage.getItem(storageKey);
if (savedText) {
$('#gollum-autorecover-button').click(function(e) {
editor.getSession().setValue(savedText);
// Restore subpage editor values too, if they exist
['header', 'footer', 'sidebar'].forEach(function(i) {
var sbSavedText = localStorage.getItem(storageKey + '_' + i);
if (sbSavedText) {
$('#gollum-editor-' + i).val(sbSavedText);
}
});
$('#gollum-autorecover-msg')[0].hidden = true;
e.preventDefault();
});
$('#gollum-autorecover-msg')[0].hidden = false;
}
editor.setTheme("ace/theme/tomorrow"); editor.setTheme("ace/theme/tomorrow");
editor.setKeyboardHandler(); editor.setKeyboardHandler();
editor.renderer.setShowGutter(false); editor.renderer.setShowGutter(false);
@@ -64,8 +107,13 @@
editor.getSession().on('change', function(){ editor.getSession().on('change', function(){
textarea.val(editor.getSession().getValue()); textarea.val(editor.getSession().getValue());
autoSaveHandler();
}); });
// Autosave for the header, footer and sidebar
$('#gollum-editor-header, #gollum-editor-footer, #gollum-editor-sidebar')
.on('change keyup paste', autoSaveHandler);
if (isRTL(editor.getSession().getLine(0))) { if (isRTL(editor.getSession().getLine(0))) {
switchRtl(true); switchRtl(true);
} }
@@ -114,6 +162,16 @@
editor.focus(); editor.focus();
}); });
// Remove any autosaved text when we hit save or cancel
$("#gollum-editor-submit, #gollum-editor-cancel").click(function() {
var storageKey = 'gollum_autorecover_' + window.location;
localStorage.removeItem(storageKey);
// Clear subpage editor values too, if they exist
['header', 'footer', 'sidebar'].forEach(function(i) {
localStorage.removeItem(storageKey + '_' + i);
});
});
debug('GollumEditor loading'); debug('GollumEditor loading');
if ( EditorHas.baseEditorMarkup() ) { if ( EditorHas.baseEditorMarkup() ) {
@@ -241,6 +299,7 @@
var ext = file.name.split('.').pop().toLowerCase() var ext = file.name.split('.').pop().toLowerCase()
var image_ext = ['jpg', 'jpeg', 'tif', 'tiff', 'png', 'gif', 'svg', 'bmp'] var image_ext = ['jpg', 'jpeg', 'tif', 'tiff', 'png', 'gif', 'svg', 'bmp']
// Link directly to image files // Link directly to image files
uploadDest = uploadDest.replace(/%20/g, ' ');
if ((image_ext.indexOf(ext) > -1)) { if ((image_ext.indexOf(ext) > -1)) {
var text = '[[/' + uploadDest + '/' + file.name + ']]'; var text = '[[/' + uploadDest + '/' + file.name + ']]';
} else { } else {
@@ -23,7 +23,7 @@
// For Gollum link tags // For Gollum link tags
var GollumTagStart = { var GollumTagStart = {
token: "support.function", token: "support.function",
regex: "\\[\\[.*\\]\\]", regex: "\\[\\[[^\\]]*\\]\\]",
next: 'start' next: 'start'
}; };
@@ -105,7 +105,7 @@ function flashNotice(type, notice, button_label, button_function, button_type) {
} }
html = '<p><div id="gollum-flash" class="flash flash-' + type +'"><button class="flash-close js-flash-close" type="button" onclick="parentNode.remove()"><%=rocticon('x')%></button>' + notice + nested_button_html + '</div></p>'; html = '<p><div id="gollum-flash" class="flash flash-' + type +'"><button class="flash-close js-flash-close" type="button" onclick="parentNode.remove()"><%=rocticon('x')%></button>' + notice + nested_button_html + '</div></p>';
$('#gollum-flash').remove(); $('#gollum-flash').remove();
$('#wiki-content h1').before(html); $('#wiki-content').before(html);
if (type == 'success') { setTimeout(function() {$('#gollum-flash').fadeOut();}, 5000); } if (type == 'success') { setTimeout(function() {$('#gollum-flash').fadeOut();}, 5000); }
} }
@@ -345,7 +345,8 @@ $(document).ready(function() {
var formData = new FormData($('#gollum-editor-form').get(0)); var formData = new FormData($('#gollum-editor-form').get(0));
var paths = window.location.pathname.split('/'); var paths = window.location.pathname.split('/');
var sectionAnchor = window.location.hash.substr(1); var sectionAnchor = window.location.hash.substr(1);
formData.append('page', paths[ paths.length - 1 ] || '') formData.append('page', paths[ paths.length - 1 ] || '');
$.ajax({ $.ajax({
url: routePath('preview'), url: routePath('preview'),
data: formData, data: formData,
@@ -486,12 +487,13 @@ $(document).ready(function() {
} }
numSelected = numSelected + 1; numSelected = numSelected + 1;
}); });
if (numSelected == maxSelected) { if (numSelected < 1) {
$('#version-form input:not(:checked)').prop('disabled', true);
$('.history button.action-compare-revision').prop('disabled', false);
} else if (numSelected < maxSelected) {
$('#version-form input').prop('disabled', false);
$('.history button.action-compare-revision').prop('disabled', true); $('.history button.action-compare-revision').prop('disabled', true);
} else if (numSelected < maxSelected) {
$('.history button.action-compare-revision').prop('disabled', false);
$('#version-form input').prop('disabled', false);
} else {
$('#version-form input:not(:checked)').prop('disabled', true);
} }
}; };
+26
View File
@@ -0,0 +1,26 @@
<div id="wiki-wrapper" class="compare">
<div id="head">
<h1 class="py-4">{{message}}</h1>
{{author}} commited {{authored_date}}
<span class="px-2 float-right">commit <code>{{version}}</code></span>
</div>
<div id="compare-content">
{{#files}}
<div class="Box data highlight my-3">
<div class="Box-header Box--condensed Box-header--gray">
<code>{{path}}</code>
</div>
<table>
{{#lines}}
<tr>
<td class="line_numbers">{{ldln}}</td>
<td class="line_numbers">{{rdln}}</td>
<td><div class="{{class}} pl-2">{{line}}</div></td>
</tr>
{{/lines}}
</table>
</div>
{{/files}}
</div>
</div>
+5
View File
@@ -96,6 +96,10 @@
</p> </p>
</div> </div>
</div> </div>
</div>
<div id="gollum-autorecover-msg" class="flash" hidden>
Autosaved text is available. Click the button to restore it.
<button id="gollum-autorecover-button" class="btn btn-sm primary flash-action">Restore Text</button>
</div> </div>
<textarea id="gollum-editor-body" class="form-control" <textarea id="gollum-editor-body" class="form-control"
data-markup-lang="{{format}}" name="content" class="mousetrap">{{content}}</textarea> data-markup-lang="{{format}}" name="content" class="mousetrap">{{content}}</textarea>
@@ -147,3 +151,4 @@
</fieldset> </fieldset>
</form> </form>
</div> </div>
<div id="gollum-saved-msg" class="position-fixed bottom-0 left-0"></div>
+5 -2
View File
@@ -7,7 +7,7 @@
{{>pagination}} {{>pagination}}
<form name="selection-form" id="selection-form" method="post" action="{{compare_path}}/{{escaped_url_path}}"></form> <form name="selection-form" id="selection-form" method="get" action="{{compare_path}}/{{escaped_url_path}}"></form>
<div id="page-history-list" class="Box Box--condensed flex-auto"> <div id="page-history-list" class="Box Box--condensed flex-auto">
<form id="version-form"> <form id="version-form">
@@ -18,7 +18,10 @@
<span class="float-left col-2" id="user-icons">{{>author_template}}</span> <span class="float-left col-2" id="user-icons">{{>author_template}}</span>
<span class="flex-auto col-1 text-gray-light">{{date}}</span> <span class="flex-auto col-1 text-gray-light">{{date}}</span>
<span class="flex-auto col-5">{{message}}</span> <span class="flex-auto col-5">{{message}}</span>
<span class="pl-4 float-right">[<a href="{{base_url}}/{{filename}}/{{id}}" title="View commit">{{id7}}</a>]</span> <span class="pl-4 float-right">
<a href="{{href}}" class="btn btn-outline text-mono">{{id7}}</a>
<a href="{{href_page}}" title="Browse the page at this point in the history" class="btn btn-outline">{{#octicon}}code{{/octicon}}</a>
</span>
</li> </li>
{{/versions}} {{/versions}}
</ul> </ul>
+7 -5
View File
@@ -8,9 +8,9 @@
<div id="wiki-history"> <div id="wiki-history">
<div class="Box flex-auto"> <ul class="Box flex-auto">
{{#versions}} {{#versions}}
<div class="Box-row Box-row--hover-gray border-top d-flex flex-items-center"> <li class="Box-row Box-row--hover-gray border-top d-flex flex-items-center">
<span class="float-left col-2" id="user-icons">{{>author_template}}</span> <span class="float-left col-2" id="user-icons">{{>author_template}}</span>
<span class="flex-auto col-1 text-gray-light">{{date}}</span> <span class="flex-auto col-1 text-gray-light">{{date}}</span>
<span class="flex-auto col-7">{{message}}<br/> <span class="flex-auto col-7">{{message}}<br/>
@@ -18,10 +18,12 @@
<span class="flex-auto col-2">{{#renamed}}{{renamed}} -> {{/renamed}}<a href="{{link}}">{{file}}</a></span><br/> <span class="flex-auto col-2">{{#renamed}}{{renamed}} -> {{/renamed}}<a href="{{link}}">{{file}}</a></span><br/>
{{/files}} {{/files}}
</span> </span>
<span class="pl-4 float-right">[{{id7}}]</span> <span class="pl-4 float-right">
</div> <a href="{{href}}" class="btn btn-outline text-mono">{{id7}}</a>
</span>
</li>
{{/versions}} {{/versions}}
</div> </ul>
</div> </div>
+4 -4
View File
@@ -8,7 +8,7 @@
{{#sprockets_stylesheet_tag}}app{{/sprockets_stylesheet_tag}} {{#sprockets_stylesheet_tag}}app{{/sprockets_stylesheet_tag}}
{{#sprockets_stylesheet_tag}}print print{{/sprockets_stylesheet_tag}} {{#sprockets_stylesheet_tag}}print print{{/sprockets_stylesheet_tag}}
{{#css}}<link rel="stylesheet" type="text/css" href="{{custom_path}}/custom.css" media="all">{{/css}} {{#css}}<link rel="stylesheet" type="text/css" href="{{custom_css}}" media="all">{{/css}}
{{#noindex}}<meta name="robots" content="noindex, nofollow" />{{/noindex}} {{#noindex}}<meta name="robots" content="noindex, nofollow" />{{/noindex}}
@@ -49,11 +49,11 @@
}; };
</script> </script>
{{#mathjax_config}} {{#mathjax_config}}
<script type="text/javascript" src="{{base_url}}/{{mathjax_config}}"></script> <script type="text/javascript" src="{{mathjax_config_path}}"></script>
{{/mathjax_config}} {{/mathjax_config}}
<script defer src="{{base_path}}/gollum/assets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script defer src="{{mathjax_js}}"></script>
{{/mathjax}} {{/mathjax}}
{{#js}}<script type="text/javascript" src="{{custom_path}}/custom.js"></script>{{/js}} {{#js}}<script type="text/javascript" src="{{custom_js}}"></script>{{/js}}
<title>{{title}}</title> <title>{{title}}</title>
</head> </head>
+4 -4
View File
@@ -2,7 +2,7 @@
<div class="TableObject"> <div class="TableObject">
<div class="TableObject-item"> <div class="TableObject-item">
<a class="btn" href="{{base_url}}/">Home</a> <a class="btn" id="minibutton-home" href="{{page_route}}">Home</a>
</div> </div>
@@ -11,13 +11,13 @@
</div> </div>
<div class="TableObject-item"> <div class="TableObject-item">
{{#overview}}<a class="btn" href="{{overview_path}}">Overview</a>{{/overview}} {{#overview}}<a class="btn" id="minibutton-overview" href="{{overview_path}}">Overview</a>{{/overview}}
{{#latest_changes}}<a class="btn" href="{{latest_changes_path}}">Latest Changes</a>{{/latest_changes}} {{#latest_changes}}<a class="btn" id="minibutton-latest-changes" href="{{latest_changes_path}}">Latest Changes</a>{{/latest_changes}}
</div> </div>
{{#history}} {{#history}}
<div class="TableObject-item pl-1"> <div class="TableObject-item pl-1">
<a class="btn" href="{{history_path}}/{{escaped_url_path}}">Page History</a> <a class="btn" id="minibutton-history" href="{{history_path}}/{{escaped_url_path}}">Page History</a>
</div> </div>
{{/history}} {{/history}}
+2 -2
View File
@@ -16,9 +16,9 @@
{{#files_folders}} {{#files_folders}}
<li class="Box-row"> <li class="Box-row">
<span class="pr-2">{{{icon}}}</span> <span class="pr-2">{{{icon}}}</span>
<span><a href={{url}}>{{name}}</a></span> <span><a href="{{url}}">{{name}}</a></span>
{{#allow_editing}} {{#allow_editing}}
{{#is_file}}<button class="btn btn-sm float-right delete-file" data-file-path={{name}} data-confirm="Are you sure you want to delete {{name}}?">{{#octicon}}trashcan{{/octicon}}</button>{{/is_file}} {{#is_file}}<button class="btn btn-sm float-right delete-file" data-file-path="{{url}}" data-confirm="Are you sure you want to delete {{name}}?">{{#octicon}}trashcan{{/octicon}}</button>{{/is_file}}
{{/allow_editing}} {{/allow_editing}}
</li> </li>
{{/files_folders}} {{/files_folders}}
+2 -3
View File
@@ -13,9 +13,8 @@
<div class="Box-header border-bottom p-0"></div> <div class="Box-header border-bottom p-0"></div>
{{#results}} {{#results}}
<li class="Box-row Box-row--gray"> <li class="Box-row Box-row--gray">
<span class="Counter Counter--gray tooltipped tooltipped-w" aria-label="{{filename_count}} hits in filename - {{count}} hits in content">{{filename_count}} - {{count}}</span>&nbsp; <span class="Counter Counter--gray tooltipped tooltipped-w" aria-label="{{filename_count}} hits in filename - {{count}} hits in content">{{filename_count}} - {{count}}</span>&nbsp;
<span class="text-bold"><a href="{{href}}">{{name}}</a></span>
<span class="text-bold"><a href="{{base_url}}/{{name}}">{{name}}</a></span>
<button class="btn-link tooltipped tooltipped-w float-right toggle-context" aria-label="Show all {{count}} hits in this page">{{#octicon}}search{{/octicon}}</button> <button class="btn-link tooltipped tooltipped-w float-right toggle-context" aria-label="Show all {{count}} hits in this page">{{#octicon}}search{{/octicon}}</button>
</li> </li>
+1 -1
View File
@@ -36,7 +36,7 @@
</div> </div>
</div> </div>
{{/has_footer}} {{/has_footer}}
</div>
</div> </div>
+38
View File
@@ -0,0 +1,38 @@
require_relative 'compare.rb'
module Precious
module Views
class Commit < Compare
attr_reader :version
def title
"Changes in #{@version[0..6]}: #{message}"
end
def author
@commit.author.name
end
def authored_date
@commit.authored_date
end
def message
@commit.message
end
def files
files = @diff.split(%r{^diff --git a/.+ b/.+$}).reject(&:empty?)
files.map do |diff|
matched = diff.match(%r{(?<=^--- a/).+$})
matched = diff.match(%r{(?<=^\+\+\+ b/).+$}) if matched.nil?
{
path: matched[0],
lines: lines(diff)
}
end
end
end
end
end
+3 -3
View File
@@ -17,9 +17,9 @@ module Precious
@versions[1][0..6] @versions[1][0..6]
end end
def lines def lines(diff = @diff)
lines = [] lines = []
lines_to_parse = @diff.split("\n")[4..-1] lines_to_parse = diff.split("\n")[4..-1]
# If the diff is of a rename, the diff header will be one line longer than normal because it will contain a line starting with '+++' to indicate the 'new' filename. # If the diff is of a rename, the diff header will be one line longer than normal because it will contain a line starting with '+++' to indicate the 'new' filename.
# Make sure to skip that header line if it is present. # Make sure to skip that header line if it is present.
lines_to_parse = lines_to_parse[1..-1] if lines_to_parse[0].start_with?('+++') lines_to_parse = lines_to_parse[1..-1] if lines_to_parse[0].start_with?('+++')
@@ -28,7 +28,7 @@ module Precious
:class => line_class(line), :class => line_class(line),
:ldln => left_diff_line_number(line), :ldln => left_diff_line_number(line),
:rdln => right_diff_line_number(line) } :rdln => right_diff_line_number(line) }
end if @diff end if diff
lines lines
end end
-4
View File
@@ -15,9 +15,5 @@ module Precious
def id def id
@page.sha @page.sha
end end
def full_url_path
::File.join(@base_url, escaped_url_path)
end
end end
end end
+10 -3
View File
@@ -39,7 +39,7 @@ module Precious
route_path = "#{prefix}/#{path}" route_path = "#{prefix}/#{path}"
@@route_methods[name.to_s] = route_path @@route_methods[name.to_s] = route_path
define_method :"#{name.to_s}_path" do define_method :"#{name.to_s}_path" do
"#{base_url}/#{route_path}".gsub(/\/{2,}/, '/') # remove double slashes page_route(route_path)
end end
end end
end end
@@ -53,8 +53,15 @@ module Precious
end end
end end
def page_route(page) def page_route(page = nil)
"#{base_url}/#{page}".gsub(/\/{2,}/, '/') # remove double slashes clean_url("/#{@base_url}", page)
end
def clean_url(*url)
url.compact!
return nil if url.empty?
::File.join(*url).gsub(%r{/{2,}}, '/')
end end
end end
+4 -1
View File
@@ -17,15 +17,18 @@ module Precious
i = @versions.size + 1 i = @versions.size + 1
@versions.map do |v| @versions.map do |v|
i -= 1 i -= 1
filename = path_for_version(v.tracked_pathname)
{ :id => v.id, { :id => v.id,
:id7 => v.id[0..6], :id7 => v.id[0..6],
:href => page_route("gollum/commit/#{v.id}"),
:href_page => page_route("#{filename}/#{v.id}"),
:num => i, :num => i,
:selected => @page.version.id == v.id, :selected => @page.version.id == v.id,
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name, :author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message, :message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
:date => v.authored_date.strftime("%B %d, %Y"), :date => v.authored_date.strftime("%B %d, %Y"),
:user_icon => self.user_icon_code(v.author.email), :user_icon => self.user_icon_code(v.author.email),
:filename => path_for_version(v.tracked_pathname), :filename => filename,
:date_full => v.authored_date, :date_full => v.authored_date,
} }
end end
+1
View File
@@ -16,6 +16,7 @@ module Precious
i -= 1 i -= 1
{ :id => v.id, { :id => v.id,
:id7 => v.id[0..6], :id7 => v.id[0..6],
:href => page_route("gollum/commit/#{v.id}"),
:num => i, :num => i,
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name, :author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message, :message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
+17 -1
View File
@@ -31,7 +31,23 @@ module Precious
end end
def custom_path def custom_path
"#{@base_url}" @base_url
end
def custom_css
clean_url(custom_path, "custom.css")
end
def custom_js
clean_url(custom_path, "custom.js")
end
def mathjax_config_path
page_route(@mathjax_config)
end
def mathjax_js
page_route("gollum/assets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML")
end end
def css # custom css def css # custom css
+1 -1
View File
@@ -52,7 +52,7 @@ module Precious
folder_url = "#{overview_path}/#{folder_path}/" folder_url = "#{overview_path}/#{folder_path}/"
files_and_folders << {name: folder_name, icon: rocticon('file-directory'), type: 'dir', url: folder_url, is_file: false} files_and_folders << {name: folder_name, icon: rocticon('file-directory'), type: 'dir', url: folder_url, is_file: false}
elsif result_path != '.gitkeep' elsif result_path != '.gitkeep'
file_url = "#{@base_url}/#{result.escaped_url_path}" file_url = page_route(result.escaped_url_path)
files_and_folders << {name: result.filename, icon: rocticon('file'), type: 'file', url: file_url, is_file: true} files_and_folders << {name: result.filename, icon: rocticon('file'), type: 'file', url: file_url, is_file: true}
end end
end end
+4
View File
@@ -169,6 +169,10 @@ module Precious
@navbar @navbar
end end
def full_url_path
page_route(@page.escaped_url_path)
end
# Access to embedded metadata. # Access to embedded metadata.
# #
# Returns Hash. # Returns Hash.
+2 -1
View File
@@ -5,7 +5,7 @@ module Precious
include Pagination include Pagination
def results def results
@results.sort do |a, b| sorted = @results.sort do |a, b|
if b.nil? if b.nil?
b_filename_count = 0 b_filename_count = 0
b_count = 0 b_count = 0
@@ -15,6 +15,7 @@ module Precious
end end
[a[:filename_count], a[:count]] <=> [b_filename_count, b_count] [a[:filename_count], a[:count]] <=> [b_filename_count, b_count]
end.reverse.slice((@page_num - 1) * @max_count, @max_count) end.reverse.slice((@page_num - 1) * @max_count, @max_count)
sorted.each {|x| x[:href] = page_route(x[:name])}
end end
def query_string def query_string
+88 -9
View File
@@ -478,15 +478,6 @@ EOF
assert last_response.ok? assert last_response.ok?
assert last_response.body.include?('Samewise Gamgee</h1>') assert last_response.body.include?('Samewise Gamgee</h1>')
end end
test "previews content on the first page of an empty wiki" do
@path = cloned_testpath("examples/empty.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {})
post "/gollum/preview", :content => 'abc', :format => 'markdown'
assert last_response.ok?
end
test 'throws an error when comparing two identical revisions for a page' do test 'throws an error when comparing two identical revisions for a page' do
get '/gollum/compare/A.md/fc66539528eb96f21b2bbdbf557788fe8a1196ac...fc66539528eb96f21b2bbdbf557788fe8a1196ac' get '/gollum/compare/A.md/fc66539528eb96f21b2bbdbf557788fe8a1196ac...fc66539528eb96f21b2bbdbf557788fe8a1196ac'
@@ -656,6 +647,14 @@ EOF
assert_match /meta name="robots" content="noindex, nofollow"/, last_response.body assert_match /meta name="robots" content="noindex, nofollow"/, last_response.body
end end
test 'history/NO-EXIST redirects to Home' do
get '/gollum/history/NO-EXIST'
follow_redirect!
assert_equal last_request.fullpath, '/'
# redirect again from / to /Home
assert_equal last_response.status, 302
end
def app def app
Precious::App Precious::App
end end
@@ -898,3 +897,83 @@ context "Frontend with page-file-dir" do
Precious::App Precious::App
end end
end end
context "Frontend with empty repo" do
include Rack::Test::Methods
setup do
@path = cloned_testpath("examples/empty.git")
@wiki = Gollum::Wiki.new(@path)
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {allow_editing: true})
end
teardown do
FileUtils.rm_rf(@path)
end
def app
Precious::App
end
test 'previews content on the first page of an empty wiki' do
post '/gollum/preview', :content => 'abc', :format => 'markdown'
assert last_response.ok?
end
test 'wiki redirects to create page with newly initialized repo' do
get '/Home'
follow_redirect!
assert_equal '/gollum/create/Home', last_request.fullpath
assert last_response.ok?
end
end
context 'Frontend with base path' do
include Rack::Test::Methods
setup do
@path = cloned_testpath("examples/lotr.git")
@wiki = Gollum::Wiki.new(@path)
@base_path = 'wiki'
Precious::App.set(:gollum_path, @path)
Precious::App.set(:wiki_options, {base_path: @base_path, mathjax: true})
end
teardown do
FileUtils.rm_rf(@path)
end
test 'page with base path' do
get '/wiki/Home'
assert last_response.ok?
end
test 'base path mathjax assets' do
get '/wiki/Home'
assert last_response.ok?
assert last_response.body.include?('<script defer src="/wiki/gollum/assets/mathjax/MathJax.js')
end
test 'compare view' do
get '/wiki/gollum/compare/Bilbo-Baggins.md?versions[]=f25eccd98e9b667f9e22946f3e2f945378b8a72d&versions[]=5bc1aaec6149e854078f1d0f8b71933bbc6c2e43'
follow_redirect!
assert last_response.ok?
assert_equal '/wiki/gollum/compare/Bilbo-Baggins.md/5bc1aaec6149e854078f1d0f8b71933bbc6c2e43...f25eccd98e9b667f9e22946f3e2f945378b8a72d', last_request.fullpath
get '/wiki/gollum/compare/Bilbo-Baggins.md?versions[]=f25eccd98e9b667f9e22946f3e2f945378b8a72d'
follow_redirect!
assert last_response.ok?
assert_equal '/wiki/gollum/compare/Bilbo-Baggins.md/b0d108328459e44fff4a76cd19b10ddc34adce4b...f25eccd98e9b667f9e22946f3e2f945378b8a72d', last_request.fullpath
get '/wiki/gollum/compare/Bilbo-Baggins.md'
follow_redirect!
assert last_response.ok?
assert_equal '/wiki/gollum/history/Bilbo-Baggins.md', last_request.fullpath
end
def app
Precious::MapGollum.new(@base_path)
end
end
+33 -18
View File
@@ -23,7 +23,26 @@ waa
[[Subsub/Zaa.md]] [[Subsub/Zaa.md]]
EOF EOF
script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags')) def load_script(**args)
settings = {
:run_silent => true,
:no_dry_run => true,
:prefer_relative => true,
:hyphenate => false,
:page_file_dir => nil,
}.merge(args)
settings.each do |const, val|
const_name = const.to_s.upcase
Object.const_set(const_name, val) unless Object.const_defined?(const_name) && Object.const_get(const_name) == val
end
script_path = File.expand_path(File.join(File.dirname(__FILE__), '../', 'bin', 'gollum-migrate-tags'))
Dir.chdir(@path) do
load script_path
end
end
unless ENV['TRAVIS'] unless ENV['TRAVIS']
@@ -35,33 +54,29 @@ unless ENV['TRAVIS']
end end
test 'repair broken links' do test 'repair broken links' do
PREFER_RELATIVE = true load_script
RUN_SILENT = true
NO_DRY_RUN = true
HYPHENATE = false
Dir.chdir(@path) do
load script_path
end
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r') f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
assert_equal result, f.read assert_equal result, f.read
end end
test 'change spaced filenames to hyphenated filenames' do test 'change spaced filenames to hyphenated filenames' do
RUN_SILENT = true load_script(hyphenate: true)
NO_DRY_RUN = true
PREFER_RELATIVE = true
HYPHENATE = true
Dir.chdir(@path) do
load script_path
end
f = ::File.new(::File.join(@path, 'Home.textile'), 'r') f = ::File.new(::File.join(@path, 'Home.textile'), 'r')
output = f.read output = f.read
assert_equal true, output.include?('[[Bilbo-Baggins.md]]') assert_equal true, output.include?('[[Bilbo-Baggins.md]]')
assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]') assert_equal true, output.include?('[[evil|Mordor/Eye-Of-Sauron.md]]')
end end
test 'migration with page file dir' do
load_script(page_file_dir: 'Subdir')
f = ::File.new(::File.join(@path, 'Subdir/Foo.md'), 'r')
output = f.read
assert_equal true, output.include?('[[Subsub/Zaa.md]]')
assert_equal true, output.include?('[[Samwi]]')
end
teardown do teardown do
FileUtils.rm_rf(@path) FileUtils.rm_rf(@path)