Namespace (#1328)
* CSS to SCSS * Use sprockets * Use Sprockets helpers * Fix gollum.editor.js error when changing language * Add keybinding files required by ace and some ace ext files that are required or might be useful. * Move app paths to /gollum namespace, add route helpers for view templates * Use path helper for links in page view * Use path helper methods in javascript assets * Refactored sprockets helpers for mustache * Remove debugging
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
if RUBY_PLATFORM == 'java'
|
if RUBY_PLATFORM == 'java'
|
||||||
gem 'gollum-rjgit_adapter', :git => 'https://github.com/repotag/gollum-lib_rjgit_adapter' # For development purposes
|
gem 'gollum-rjgit_adapter', :git => 'https://github.com/repotag/gollum-lib_rjgit_adapter' # For development purposes
|
||||||
gem 'warbler'
|
gem 'warbler'
|
||||||
@@ -7,6 +9,5 @@ end
|
|||||||
|
|
||||||
gem 'gollum-lib', :git => 'https://github.com/gollum/gollum-lib.git', :branch => 'gollum-lib-5.x' # For development purposes
|
gem 'gollum-lib', :git => 'https://github.com/gollum/gollum-lib.git', :branch => 'gollum-lib-5.x' # For development purposes
|
||||||
|
|
||||||
source 'https://rubygems.org'
|
|
||||||
gemspec
|
gemspec
|
||||||
gem 'rake', '~> 11.2'
|
gem 'rake', '~> 11.2'
|
||||||
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|||||||
s.add_dependency 'gollum-lib', '~> 5.0.a'
|
s.add_dependency 'gollum-lib', '~> 5.0.a'
|
||||||
s.add_dependency 'kramdown', '~> 1.17.0'
|
s.add_dependency 'kramdown', '~> 1.17.0'
|
||||||
s.add_dependency 'sinatra', '~> 2.0'
|
s.add_dependency 'sinatra', '~> 2.0'
|
||||||
|
s.add_dependency 'sinatra-contrib', '~> 2.0'
|
||||||
s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0']
|
s.add_dependency 'mustache', ['>= 0.99.5', '< 1.0.0']
|
||||||
s.add_dependency 'useragent', '~> 0.16.2'
|
s.add_dependency 'useragent', '~> 0.16.2'
|
||||||
s.add_dependency 'gemojione', '~> 3.2'
|
s.add_dependency 'gemojione', '~> 3.2'
|
||||||
|
|||||||
+341
-336
@@ -1,6 +1,7 @@
|
|||||||
# ~*~ encoding: utf-8 ~*~
|
# ~*~ encoding: utf-8 ~*~
|
||||||
require 'cgi'
|
require 'cgi'
|
||||||
require 'sinatra'
|
require 'sinatra'
|
||||||
|
require 'sinatra/namespace'
|
||||||
require 'gollum-lib'
|
require 'gollum-lib'
|
||||||
require 'mustache/sinatra'
|
require 'mustache/sinatra'
|
||||||
require 'stringex'
|
require 'stringex'
|
||||||
@@ -47,11 +48,12 @@ end
|
|||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
# 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
|
||||||
class App < Sinatra::Base
|
class App < Sinatra::Base
|
||||||
register Mustache::Sinatra
|
register Mustache::Sinatra
|
||||||
|
register Sinatra::Namespace
|
||||||
include Precious::Helpers
|
include Precious::Helpers
|
||||||
|
|
||||||
dir = File.dirname(File.expand_path(__FILE__))
|
dir = File.dirname(File.expand_path(__FILE__))
|
||||||
|
|
||||||
set :sprockets, ::Precious::Assets.sprockets(dir)
|
set :sprockets, ::Precious::Assets.sprockets(dir)
|
||||||
@@ -97,6 +99,7 @@ module Precious
|
|||||||
|
|
||||||
Sprockets::Helpers.configure do |config|
|
Sprockets::Helpers.configure do |config|
|
||||||
config.environment = settings.sprockets
|
config.environment = settings.sprockets
|
||||||
|
config.environment.context_class.class_variable_set(:@@base_url, @base_url)
|
||||||
config.prefix = "#{@base_url}/#{Precious::Assets::ASSET_URL}"
|
config.prefix = "#{@base_url}/#{Precious::Assets::ASSET_URL}"
|
||||||
config.digest = @use_static_assets
|
config.digest = @use_static_assets
|
||||||
if @use_static_assets
|
if @use_static_assets
|
||||||
@@ -110,344 +113,372 @@ module Precious
|
|||||||
redirect clean_url(::File.join(@base_url, @page_dir, wiki_new.index_page))
|
redirect clean_url(::File.join(@base_url, @page_dir, wiki_new.index_page))
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/assets/*' do
|
namespace '/gollum' do
|
||||||
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
|
|
||||||
if @use_static_assets
|
|
||||||
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
|
|
||||||
not_found_msg = "Not found."
|
|
||||||
not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]}
|
|
||||||
Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env)
|
|
||||||
else
|
|
||||||
settings.sprockets.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/last-commit-info' do
|
get '/assets/*' do
|
||||||
content_type :json
|
env['PATH_INFO'].sub!("/#{Precious::Assets::ASSET_URL}", '')
|
||||||
if page = wiki_page(params[:path]).page
|
if @use_static_assets
|
||||||
version = page.last_version
|
env['PATH_INFO'].sub!(Sprockets::Helpers.prefix, '') if @base_url
|
||||||
{:author => version.author.name, :date => version.authored_date}.to_json
|
not_found_msg = "Not found."
|
||||||
end
|
not_found = Proc.new {[404, {'Content-Type' => 'text/html', 'Content-Length' => not_found_msg.length.to_s}, [not_found_msg]]}
|
||||||
end
|
Rack::Static.new(not_found, {:root => @static_assets_path, :urls => ['']}).call(env)
|
||||||
|
else
|
||||||
get '/emoji/:name' do
|
settings.sprockets.call(env)
|
||||||
begin
|
end
|
||||||
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
|
|
||||||
rescue ArgumentError
|
|
||||||
not_found
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/data/*' do
|
|
||||||
if page = wiki_page(params[:splat].first).page
|
|
||||||
page.raw_data
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
get %r{/(edit|create)/custom\.(js|css)} do
|
|
||||||
forbid('Changing this resource is not allowed.')
|
|
||||||
end
|
|
||||||
|
|
||||||
post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do
|
|
||||||
forbid('Changing this resource is not allowed.')
|
|
||||||
end
|
|
||||||
|
|
||||||
post %r{/revert/custom\.(js|css)/.*/.*} do
|
|
||||||
forbid('Changing this resource is not allowed.')
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/edit/*' do
|
|
||||||
forbid unless @allow_editing
|
|
||||||
wikip = wiki_page(params[:splat].first)
|
|
||||||
@name = join_page_name(wikip.name, wikip.ext)
|
|
||||||
@path = wikip.path
|
|
||||||
@upload_dest = find_upload_dest(@path)
|
|
||||||
|
|
||||||
wiki = wikip.wiki
|
|
||||||
@allow_uploads = wiki.allow_uploads
|
|
||||||
if page = wikip.page
|
|
||||||
@page = page
|
|
||||||
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
|
||||||
@content = page.text_data
|
|
||||||
mustache :edit
|
|
||||||
else
|
|
||||||
redirect to("/create/#{encodeURIComponent(@name)}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
post '/uploadFile' do
|
|
||||||
wiki = wiki_new
|
|
||||||
|
|
||||||
unless wiki.allow_uploads
|
|
||||||
@message = "File uploads are disabled"
|
|
||||||
mustache :error
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:file]
|
get '/last-commit-info' do
|
||||||
fullname = params[:file][:filename]
|
content_type :json
|
||||||
tempfile = params[:file][:tempfile]
|
if page = wiki_page(params[:path]).page
|
||||||
end
|
version = page.last_version
|
||||||
halt 500 unless tempfile.is_a? Tempfile
|
{:author => version.author.name, :date => version.authored_date}.to_json
|
||||||
|
end
|
||||||
# Remove page file dir prefix from upload path if necessary -- committer handles this itself
|
|
||||||
dir = wiki.per_page_uploads ? params[:upload_dest] : ::File.join([wiki.page_file_dir, 'uploads'].compact)
|
|
||||||
ext = ::File.extname(fullname)
|
|
||||||
format = ext.split('.').last || 'txt'
|
|
||||||
filename = ::File.basename(fullname, ext)
|
|
||||||
contents = ::File.read(tempfile)
|
|
||||||
reponame = "#{filename}.#{format}"
|
|
||||||
|
|
||||||
head = wiki.repo.head
|
|
||||||
|
|
||||||
options = {
|
|
||||||
:message => "Uploaded file to #{dir}/#{reponame}",
|
|
||||||
:parent => wiki.repo.head.commit,
|
|
||||||
}
|
|
||||||
author = session['gollum.author']
|
|
||||||
unless author.nil?
|
|
||||||
options.merge! author
|
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
get '/emoji/:name' do
|
||||||
committer = Gollum::Committer.new(wiki, options)
|
begin
|
||||||
committer.add_to_index(dir, filename, format, contents)
|
[200, {'Content-Type' => 'image/png'}, emoji(params['name'])]
|
||||||
committer.after_commit do |committer, sha|
|
rescue ArgumentError
|
||||||
wiki.clear_cache
|
not_found
|
||||||
committer.update_working_dir(dir, filename, format)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/data/*' do
|
||||||
|
if page = wiki_page(params[:splat].first).page
|
||||||
|
page.raw_data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get %r{/(edit|create)/custom\.(js|css)} do
|
||||||
|
forbid('Changing this resource is not allowed.')
|
||||||
|
end
|
||||||
|
|
||||||
|
post %r{/(deleteFile|rename|edit|create)/custom\.(js|css)} do
|
||||||
|
forbid('Changing this resource is not allowed.')
|
||||||
|
end
|
||||||
|
|
||||||
|
post %r{/revert/custom\.(js|css)/.*/.*} do
|
||||||
|
forbid('Changing this resource is not allowed.')
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/edit/*' do
|
||||||
|
forbid unless @allow_editing
|
||||||
|
wikip = wiki_page(params[:splat].first)
|
||||||
|
@name = join_page_name(wikip.name, wikip.ext)
|
||||||
|
@path = wikip.path
|
||||||
|
@upload_dest = find_upload_dest(@path)
|
||||||
|
|
||||||
|
wiki = wikip.wiki
|
||||||
|
@allow_uploads = wiki.allow_uploads
|
||||||
|
if page = wikip.page
|
||||||
|
@page = page
|
||||||
|
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
||||||
|
@content = page.text_data
|
||||||
|
mustache :edit
|
||||||
|
else
|
||||||
|
redirect_to("/create/#{encodeURIComponent(@name)}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/uploadFile' do
|
||||||
|
wiki = wiki_new
|
||||||
|
|
||||||
|
unless wiki.allow_uploads
|
||||||
|
@message = "File uploads are disabled"
|
||||||
|
mustache :error
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if params[:file]
|
||||||
|
fullname = params[:file][:filename]
|
||||||
|
tempfile = params[:file][:tempfile]
|
||||||
|
end
|
||||||
|
halt 500 unless tempfile.is_a? Tempfile
|
||||||
|
|
||||||
|
# Remove page file dir prefix from upload path if necessary -- committer handles this itself
|
||||||
|
dir = wiki.per_page_uploads ? params[:upload_dest] : ::File.join([wiki.page_file_dir, 'uploads'].compact)
|
||||||
|
ext = ::File.extname(fullname)
|
||||||
|
format = ext.split('.').last || 'txt'
|
||||||
|
filename = ::File.basename(fullname, ext)
|
||||||
|
contents = ::File.read(tempfile)
|
||||||
|
reponame = "#{filename}.#{format}"
|
||||||
|
|
||||||
|
head = wiki.repo.head
|
||||||
|
|
||||||
|
options = {
|
||||||
|
:message => "Uploaded file to #{dir}/#{reponame}",
|
||||||
|
:parent => wiki.repo.head.commit,
|
||||||
|
}
|
||||||
|
author = session['gollum.author']
|
||||||
|
unless author.nil?
|
||||||
|
options.merge! author
|
||||||
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
committer = Gollum::Committer.new(wiki, options)
|
||||||
|
committer.add_to_index(dir, filename, format, contents)
|
||||||
|
committer.after_commit do |committer, sha|
|
||||||
|
wiki.clear_cache
|
||||||
|
committer.update_working_dir(dir, filename, format)
|
||||||
|
end
|
||||||
|
committer.commit
|
||||||
|
redirect to(request.referer)
|
||||||
|
rescue Gollum::DuplicatePageError => e
|
||||||
|
@message = "Duplicate page: #{e.message}"
|
||||||
|
mustache :error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/deleteFile/*' do
|
||||||
|
forbid unless @allow_editing
|
||||||
|
wiki = wiki_new
|
||||||
|
filepath = params[:splat].first
|
||||||
|
unless filepath.nil?
|
||||||
|
commit = commit_message
|
||||||
|
commit[:message] = "Deleted #{filepath}"
|
||||||
|
wiki.delete_file(filepath, commit)
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to('/pages')
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/rename/*' do
|
||||||
|
wikip = wiki_page(params[:splat].first)
|
||||||
|
halt 500 if wikip.nil?
|
||||||
|
wiki = wikip.wiki
|
||||||
|
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||||
|
rename = params[:rename]
|
||||||
|
halt 500 if page.nil?
|
||||||
|
halt 500 if rename.nil? or rename.empty?
|
||||||
|
|
||||||
|
# Fixup the rename if it is a relative path
|
||||||
|
# In 1.8.7 rename[0] != rename[0..0]
|
||||||
|
if rename[0..0] != '/'
|
||||||
|
source_dir = ::File.dirname(page.path)
|
||||||
|
source_dir = '' if source_dir == '.'
|
||||||
|
(target_dir, target_name) = ::File.split(rename)
|
||||||
|
target_dir = target_dir == '' ? source_dir : "#{source_dir}/#{target_dir}"
|
||||||
|
rename = "#{target_dir}/#{target_name}"
|
||||||
|
end
|
||||||
|
|
||||||
|
committer = Gollum::Committer.new(wiki, commit_message)
|
||||||
|
commit = { :committer => committer }
|
||||||
|
|
||||||
|
success = wiki.rename_page(page, rename, commit)
|
||||||
|
if !success
|
||||||
|
# This occurs on NOOPs, for example renaming A => A
|
||||||
|
redirect to("/#{page.escaped_url_path}")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
committer.commit
|
committer.commit
|
||||||
redirect to(request.referer)
|
|
||||||
rescue Gollum::DuplicatePageError => e
|
|
||||||
@message = "Duplicate page: #{e.message}"
|
|
||||||
mustache :error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
post '/deleteFile/*' do
|
wikip = wiki_page(rename)
|
||||||
forbid unless @allow_editing
|
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
||||||
wiki = wiki_new
|
return if page.nil?
|
||||||
filepath = params[:splat].first
|
|
||||||
unless filepath.nil?
|
|
||||||
commit = commit_message
|
|
||||||
commit[:message] = "Deleted #{filepath}"
|
|
||||||
wiki.delete_file(filepath, commit)
|
|
||||||
end
|
|
||||||
|
|
||||||
redirect to('/pages')
|
|
||||||
end
|
|
||||||
|
|
||||||
post '/rename/*' do
|
|
||||||
wikip = wiki_page(params[:splat].first)
|
|
||||||
halt 500 if wikip.nil?
|
|
||||||
wiki = wikip.wiki
|
|
||||||
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
|
||||||
rename = params[:rename]
|
|
||||||
halt 500 if page.nil?
|
|
||||||
halt 500 if rename.nil? or rename.empty?
|
|
||||||
|
|
||||||
# Fixup the rename if it is a relative path
|
|
||||||
# In 1.8.7 rename[0] != rename[0..0]
|
|
||||||
if rename[0..0] != '/'
|
|
||||||
source_dir = ::File.dirname(page.path)
|
|
||||||
source_dir = '' if source_dir == '.'
|
|
||||||
(target_dir, target_name) = ::File.split(rename)
|
|
||||||
target_dir = target_dir == '' ? source_dir : "#{source_dir}/#{target_dir}"
|
|
||||||
rename = "#{target_dir}/#{target_name}"
|
|
||||||
end
|
|
||||||
|
|
||||||
committer = Gollum::Committer.new(wiki, commit_message)
|
|
||||||
commit = { :committer => committer }
|
|
||||||
|
|
||||||
success = wiki.rename_page(page, rename, commit)
|
|
||||||
if !success
|
|
||||||
# This occurs on NOOPs, for example renaming A => A
|
|
||||||
redirect to("/#{page.escaped_url_path}")
|
redirect to("/#{page.escaped_url_path}")
|
||||||
return
|
|
||||||
end
|
|
||||||
committer.commit
|
|
||||||
|
|
||||||
wikip = wiki_page(rename)
|
|
||||||
page = wiki.paged(join_page_name(wikip.name, wikip.ext), wikip.path, exact = true)
|
|
||||||
return if page.nil?
|
|
||||||
redirect to("/#{page.escaped_url_path}")
|
|
||||||
end
|
|
||||||
|
|
||||||
post '/edit/*' do
|
|
||||||
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
|
||||||
page_name = CGI.unescape(params[:page])
|
|
||||||
wiki = wiki_new
|
|
||||||
page = wiki.paged(page_name, path, exact = true)
|
|
||||||
return if page.nil?
|
|
||||||
committer = Gollum::Committer.new(wiki, commit_message)
|
|
||||||
commit = { :committer => committer }
|
|
||||||
|
|
||||||
update_wiki_page(wiki, page, params[:content], commit, page.name, params[:format])
|
|
||||||
update_wiki_page(wiki, page.header, params[:header], commit) if params[:header]
|
|
||||||
update_wiki_page(wiki, page.footer, params[:footer], commit) if params[:footer]
|
|
||||||
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
|
||||||
committer.commit
|
|
||||||
|
|
||||||
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/delete/*' do
|
|
||||||
forbid unless @allow_editing
|
|
||||||
wikip = wiki_page(params[:splat].first)
|
|
||||||
name = join_page_name(wikip.name, wikip.ext)
|
|
||||||
wiki = wikip.wiki
|
|
||||||
page = wikip.page
|
|
||||||
unless page.nil?
|
|
||||||
commit = commit_message
|
|
||||||
commit[:message] = "Destroyed #{name} (#{page.format})"
|
|
||||||
wiki.delete_page(page, commit)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect to('/')
|
post '/edit/*' do
|
||||||
end
|
path = "/#{clean_url(sanitize_empty_params(params[:path]))}"
|
||||||
|
page_name = CGI.unescape(params[:page])
|
||||||
|
wiki = wiki_new
|
||||||
|
page = wiki.paged(page_name, path, exact = true)
|
||||||
|
return if page.nil?
|
||||||
|
committer = Gollum::Committer.new(wiki, commit_message)
|
||||||
|
commit = { :committer => committer }
|
||||||
|
|
||||||
get '/create/*' do
|
update_wiki_page(wiki, page, params[:content], commit, page.name, params[:format])
|
||||||
forbid unless @allow_editing
|
update_wiki_page(wiki, page.header, params[:header], commit) if params[:header]
|
||||||
if settings.wiki_options[:template_page] then
|
update_wiki_page(wiki, page.footer, params[:footer], commit) if params[:footer]
|
||||||
temppage = wiki_page("/_Template")
|
update_wiki_page(wiki, page.sidebar, params[:sidebar], commit) if params[:sidebar]
|
||||||
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed."
|
committer.commit
|
||||||
|
|
||||||
|
redirect to("/#{page.escaped_url_path}") unless page.nil?
|
||||||
end
|
end
|
||||||
wikip = wiki_page(params[:splat].first)
|
|
||||||
@name = wikip.name.to_url
|
|
||||||
@ext = wikip.ext
|
|
||||||
@path = wikip.path
|
|
||||||
@allow_uploads = wikip.wiki.allow_uploads
|
|
||||||
@upload_dest = find_upload_dest(@path)
|
|
||||||
|
|
||||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
get '/delete/*' do
|
||||||
unless page_dir.empty?
|
forbid unless @allow_editing
|
||||||
# --page-file-dir docs
|
wikip = wiki_page(params[:splat].first)
|
||||||
# /docs/Home should be created in /Home
|
name = join_page_name(wikip.name, wikip.ext)
|
||||||
# not /docs/Home because write_page will append /docs
|
wiki = wikip.wiki
|
||||||
@path = @path.sub(page_dir, '/') if @path.start_with? page_dir
|
page = wikip.page
|
||||||
end
|
unless page.nil?
|
||||||
@path = clean_path(@path)
|
commit = commit_message
|
||||||
|
commit[:message] = "Destroyed #{name} (#{page.format})"
|
||||||
page = wikip.page
|
wiki.delete_page(page, commit)
|
||||||
if page
|
|
||||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
|
||||||
redirect to("/#{clean_url(::File.join(page_dir, page.escaped_url_path))}")
|
|
||||||
else
|
|
||||||
unless Gollum::Page.format_for("#{@name}#{@ext}")
|
|
||||||
@name = "#{@name}#{@ext}"
|
|
||||||
@ext = nil
|
|
||||||
end
|
end
|
||||||
mustache :create
|
|
||||||
|
redirect to('/')
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
post '/create' do
|
get '/create/*' do
|
||||||
name = params[:page].to_url
|
forbid unless @allow_editing
|
||||||
path = sanitize_empty_params(params[:path]) || ''
|
if settings.wiki_options[:template_page] then
|
||||||
format = params[:format].intern
|
temppage = wiki_page("/_Template")
|
||||||
wiki = wiki_new
|
@template_page = (temppage.page != nil) ? temppage.page.raw_data : "Template page option is set, but no /_Template page is present or committed."
|
||||||
|
end
|
||||||
path.gsub!(/^\//, '')
|
wikip = wiki_page(params[:splat].first)
|
||||||
|
@name = wikip.name.to_url
|
||||||
begin
|
@ext = wikip.ext
|
||||||
wiki.write_page(name, format, params[:content], commit_message, path)
|
@path = wikip.path
|
||||||
|
@allow_uploads = wikip.wiki.allow_uploads
|
||||||
|
@upload_dest = find_upload_dest(@path)
|
||||||
|
|
||||||
page_dir = settings.wiki_options[:page_file_dir].to_s
|
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||||
redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}")
|
unless page_dir.empty?
|
||||||
rescue Gollum::DuplicatePageError => e
|
# --page-file-dir docs
|
||||||
@message = "Duplicate page: #{e.message}"
|
# /docs/Home should be created in /Home
|
||||||
mustache :error
|
# not /docs/Home because write_page will append /docs
|
||||||
|
@path = @path.sub(page_dir, '/') if @path.start_with? page_dir
|
||||||
|
end
|
||||||
|
@path = clean_path(@path)
|
||||||
|
|
||||||
|
page = wikip.page
|
||||||
|
if page
|
||||||
|
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||||
|
redirect to("/#{clean_url(::File.join(page_dir, page.escaped_url_path))}")
|
||||||
|
else
|
||||||
|
unless Gollum::Page.format_for("#{@name}#{@ext}")
|
||||||
|
@name = "#{@name}#{@ext}"
|
||||||
|
@ext = nil
|
||||||
|
end
|
||||||
|
mustache :create
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
post '/revert/*/:sha1/:sha2' do
|
post '/create' do
|
||||||
wikip = wiki_page(params[:splat].first)
|
name = params[:page].to_url
|
||||||
@path = wikip.path
|
path = sanitize_empty_params(params[:path]) || ''
|
||||||
@name = join_page_name(wikip.name, wikip.ext)
|
format = params[:format].intern
|
||||||
wiki = wikip.wiki
|
wiki = wiki_new
|
||||||
@page = wiki.paged(@name, @path)
|
|
||||||
sha1 = params[:sha1]
|
|
||||||
sha2 = params[:sha2]
|
|
||||||
|
|
||||||
commit = commit_message
|
path.gsub!(/^\//, '')
|
||||||
commit[:message] = "Revert commit #{sha1.chars.take(7).join}"
|
|
||||||
if wiki.revert_page(@page, sha1, sha2, commit)
|
begin
|
||||||
redirect to("/#{@page.escaped_url_path}")
|
wiki.write_page(name, format, params[:content], commit_message, path)
|
||||||
else
|
|
||||||
sha2, sha1 = sha1, "#{sha1}^" if !sha2
|
page_dir = settings.wiki_options[:page_file_dir].to_s
|
||||||
@versions = [sha1, sha2]
|
redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}")
|
||||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
rescue Gollum::DuplicatePageError => e
|
||||||
@diff = diffs.first
|
@message = "Duplicate page: #{e.message}"
|
||||||
@message = "The patch does not apply."
|
mustache :error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/revert/*/:sha1/:sha2' do
|
||||||
|
wikip = wiki_page(params[:splat].first)
|
||||||
|
@path = wikip.path
|
||||||
|
@name = join_page_name(wikip.name, wikip.ext)
|
||||||
|
wiki = wikip.wiki
|
||||||
|
@page = wiki.paged(@name, @path)
|
||||||
|
sha1 = params[:sha1]
|
||||||
|
sha2 = params[:sha2]
|
||||||
|
|
||||||
|
commit = commit_message
|
||||||
|
commit[:message] = "Revert commit #{sha1.chars.take(7).join}"
|
||||||
|
if wiki.revert_page(@page, sha1, sha2, commit)
|
||||||
|
redirect to("/#{@page.escaped_url_path}")
|
||||||
|
else
|
||||||
|
sha2, sha1 = sha1, "#{sha1}^" if !sha2
|
||||||
|
@versions = [sha1, sha2]
|
||||||
|
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||||
|
@diff = diffs.first
|
||||||
|
@message = "The patch does not apply."
|
||||||
|
mustache :compare
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/preview' do
|
||||||
|
wiki = wiki_new
|
||||||
|
@name = params[:page] || "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
|
||||||
|
@h1_title = wiki.h1_title
|
||||||
|
@editable = false
|
||||||
|
@bar_side = wiki.bar_side
|
||||||
|
@allow_uploads = wiki.allow_uploads
|
||||||
|
mustache :page
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/history/*' do
|
||||||
|
@page = wiki_page(params[:splat].first).page
|
||||||
|
@page_num = [params[:page].to_i, 1].max
|
||||||
|
unless @page.nil?
|
||||||
|
@versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true))
|
||||||
|
mustache :history
|
||||||
|
else
|
||||||
|
redirect to("/")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get '/latest_changes' do
|
||||||
|
@wiki = wiki_new
|
||||||
|
max_count = settings.wiki_options.fetch(:latest_changes_count, 10)
|
||||||
|
@versions = @wiki.latest_changes({:max_count => max_count})
|
||||||
|
mustache :latest_changes
|
||||||
|
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{
|
||||||
|
/compare/ # match any URL beginning with /compare/
|
||||||
|
(.+) # extract the full path (including any directories)
|
||||||
|
/ # match the final slash
|
||||||
|
([^.]+) # match the first SHA1
|
||||||
|
\.{2,3} # match .. or ...
|
||||||
|
(.+) # match the second SHA1
|
||||||
|
}x do |path, start_version, end_version|
|
||||||
|
wikip = wiki_page(path)
|
||||||
|
@path = wikip.path
|
||||||
|
@name = join_page_name(wikip.name, wikip.ext)
|
||||||
|
@versions = [start_version, end_version]
|
||||||
|
wiki = wikip.wiki
|
||||||
|
@page = wikip.page
|
||||||
|
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||||
|
@diff = diffs.first
|
||||||
mustache :compare
|
mustache :compare
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
post '/preview' do
|
get '/search' do
|
||||||
wiki = wiki_new
|
@query = params[:q] || ''
|
||||||
@name = params[:page] || "Preview"
|
wiki = wiki_new
|
||||||
@page = wiki.preview_page(@name, params[:content], params[:format])
|
# Sort wiki search results by count (desc) and then by name (asc)
|
||||||
@content = @page.formatted_data
|
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
||||||
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
@name = @query
|
||||||
@mathjax = wiki.mathjax
|
mustache :search
|
||||||
@h1_title = wiki.h1_title
|
|
||||||
@editable = false
|
|
||||||
@bar_side = wiki.bar_side
|
|
||||||
@allow_uploads = wiki.allow_uploads
|
|
||||||
mustache :page
|
|
||||||
end
|
|
||||||
|
|
||||||
get '/history/*' do
|
|
||||||
@page = wiki_page(params[:splat].first).page
|
|
||||||
@page_num = [params[:page].to_i, 1].max
|
|
||||||
unless @page.nil?
|
|
||||||
@versions = @page.versions(:page => @page_num, :follow => settings.wiki_options.fetch(:follow_renames, ::Gollum::GIT_ADAPTER == 'rjgit' ? false : true))
|
|
||||||
mustache :history
|
|
||||||
else
|
|
||||||
redirect to("/")
|
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
get '/latest_changes' do
|
get %r{
|
||||||
@wiki = wiki_new
|
/pages # match any URL beginning with /pages
|
||||||
max_count = settings.wiki_options.fetch(:latest_changes_count, 10)
|
(?: # begin an optional non-capturing group
|
||||||
@versions = @wiki.latest_changes({:max_count => max_count})
|
/(.+) # capture any path after the "/pages" excluding the leading slash
|
||||||
mustache :latest_changes
|
)? # end the optional non-capturing group
|
||||||
end
|
}x do |path|
|
||||||
|
@path = extract_path(path) if path
|
||||||
post '/compare/*' do
|
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
||||||
@file = encodeURIComponent(params[:splat].first)
|
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
||||||
@versions = params[:versions] || []
|
@results = wiki.pages
|
||||||
if @versions.size < 2
|
@results += wiki.files
|
||||||
redirect to("/history/#{@file}")
|
@results = @results.sort_by { |p| p.name.downcase } # Sort Results alphabetically, fixes 922
|
||||||
else
|
@ref = wiki.ref
|
||||||
redirect to("/compare/%s/%s...%s" % [
|
mustache :pages
|
||||||
@file,
|
|
||||||
@versions.last,
|
|
||||||
@versions.first]
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get %r{
|
|
||||||
/compare/ # match any URL beginning with /compare/
|
|
||||||
(.+) # extract the full path (including any directories)
|
|
||||||
/ # match the final slash
|
|
||||||
([^.]+) # match the first SHA1
|
|
||||||
\.{2,3} # match .. or ...
|
|
||||||
(.+) # match the second SHA1
|
|
||||||
}x do |path, start_version, end_version|
|
|
||||||
wikip = wiki_page(path)
|
|
||||||
@path = wikip.path
|
|
||||||
@name = join_page_name(wikip.name, wikip.ext)
|
|
||||||
@versions = [start_version, end_version]
|
|
||||||
wiki = wikip.wiki
|
|
||||||
@page = wikip.page
|
|
||||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
|
||||||
@diff = diffs.first
|
|
||||||
mustache :compare
|
|
||||||
end
|
|
||||||
|
|
||||||
get %r{/(.+?)/([0-9a-f]{40})} do
|
get %r{/(.+?)/([0-9a-f]{40})} do
|
||||||
file_path = params[:captures][0]
|
file_path = params[:captures][0]
|
||||||
version = params[:captures][1]
|
version = params[:captures][1]
|
||||||
@@ -468,32 +499,6 @@ module Precious
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/search' do
|
|
||||||
@query = params[:q] || ''
|
|
||||||
wiki = wiki_new
|
|
||||||
# Sort wiki search results by count (desc) and then by name (asc)
|
|
||||||
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
|
||||||
@name = @query
|
|
||||||
mustache :search
|
|
||||||
end
|
|
||||||
|
|
||||||
get %r{
|
|
||||||
/pages # match any URL beginning with /pages
|
|
||||||
(?: # begin an optional non-capturing group
|
|
||||||
/(.+) # capture any path after the "/pages" excluding the leading slash
|
|
||||||
)? # end the optional non-capturing group
|
|
||||||
}x do |path|
|
|
||||||
@path = extract_path(path) if path
|
|
||||||
wiki_options = settings.wiki_options.merge({ :page_file_dir => @path })
|
|
||||||
wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options)
|
|
||||||
@results = wiki.pages
|
|
||||||
@results += wiki.files
|
|
||||||
@results = @results.sort_by { |p| p.name.downcase } # Sort Results alphabetically, fixes 922
|
|
||||||
@ref = wiki.ref
|
|
||||||
mustache :pages
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
get '/*' do
|
get '/*' do
|
||||||
show_page_or_file(params[:splat].first)
|
show_page_or_file(params[:splat].first)
|
||||||
end
|
end
|
||||||
@@ -525,7 +530,7 @@ module Precious
|
|||||||
else
|
else
|
||||||
if @allow_editing
|
if @allow_editing
|
||||||
page_path = [path, join_page_name(name, ext)].compact.join('/')
|
page_path = [path, join_page_name(name, ext)].compact.join('/')
|
||||||
redirect to("/create/#{clean_url(encodeURIComponent(page_path))}")
|
redirect to("/gollum/create/#{clean_url(encodeURIComponent(page_path))}")
|
||||||
else
|
else
|
||||||
@message = "The requested page does not exist."
|
@message = "The requested page does not exist."
|
||||||
status 404
|
status 404
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Precious
|
module Precious
|
||||||
module Assets
|
module Assets
|
||||||
MANIFEST = %w(app.js app.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
|
MANIFEST = %w(app.js app.css fileview.css ie7.css print.css *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2)
|
||||||
ASSET_URL = '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
|
||||||
@@ -12,6 +12,13 @@ module Precious
|
|||||||
|
|
||||||
env.js_compressor = :uglify
|
env.js_compressor = :uglify
|
||||||
env.css_compressor = :scss
|
env.css_compressor = :scss
|
||||||
|
|
||||||
|
env.context_class.class_eval do
|
||||||
|
def base_url
|
||||||
|
self.class.class_variable_get(:@@base_url)
|
||||||
|
end
|
||||||
|
include ::Precious::Views::RouteHelpers
|
||||||
|
end
|
||||||
env
|
env
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -209,7 +209,7 @@
|
|||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: baseUrl + '/uploadFile',
|
url: '<%= upload_file_path %>',
|
||||||
data: formData,
|
data: formData,
|
||||||
cache: false,
|
cache: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
+11
-7
@@ -47,7 +47,7 @@ $(document).ready(function() {
|
|||||||
$('#delete-link').click( function(e) {
|
$('#delete-link').click( function(e) {
|
||||||
var ok = confirm($(this).data('confirm'));
|
var ok = confirm($(this).data('confirm'));
|
||||||
if ( ok ) {
|
if ( ok ) {
|
||||||
var loc = baseUrl + '/delete/' + pageFullPath;
|
var loc = '<%= delete_path %>/' + pageFullPath;
|
||||||
window.location = loc;
|
window.location = loc;
|
||||||
}
|
}
|
||||||
// Don't navigate on cancel.
|
// Don't navigate on cancel.
|
||||||
@@ -162,7 +162,7 @@ $(document).ready(function() {
|
|||||||
{
|
{
|
||||||
type: 'file',
|
type: 'file',
|
||||||
context: 'Your uploaded file will be accessible at<br>/'+uploadDest+'/[filename]',
|
context: 'Your uploaded file will be accessible at<br>/'+uploadDest+'/[filename]',
|
||||||
action: baseUrl + '/uploadFile'
|
action: '<%= upload_file_path %>'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
OK: function( res ) {
|
OK: function( res ) {
|
||||||
@@ -226,10 +226,14 @@ $(document).ready(function() {
|
|||||||
// In the pages view, pageFullPath isn't defined.
|
// In the pages view, pageFullPath isn't defined.
|
||||||
// The new button will still expect a value however.
|
// The new button will still expect a value however.
|
||||||
// So we try to figure one out from window.location
|
// So we try to figure one out from window.location
|
||||||
path = baseUrl == '' ? window.location.pathname.substr(1)
|
path = window.location.pathname.substr(1)
|
||||||
: window.location.pathname.substr(baseUrl.length + 1);
|
|
||||||
// Remove the page viewer part of the url.
|
// Remove the page viewer part of the url.
|
||||||
path = path.replace(/^pages\/?/,'')
|
<%
|
||||||
|
pages_path_uri = pages_path
|
||||||
|
pages_path_uri = pages_path_uri[1..-1] if pages_path_uri[0] == '/'
|
||||||
|
pages_path_uri = pages_path_uri.gsub('/','\/')
|
||||||
|
%>
|
||||||
|
path = path.replace(/^<%= pages_path_uri %>\/?/,'')
|
||||||
// For consistency remove the trailing /
|
// For consistency remove the trailing /
|
||||||
path = path.replace(/\/$/,'')
|
path = path.replace(/\/$/,'')
|
||||||
}
|
}
|
||||||
@@ -260,7 +264,7 @@ $(document).ready(function() {
|
|||||||
for( var i=0; i < name_parts.length; i++ ){
|
for( var i=0; i < name_parts.length; i++ ){
|
||||||
name_encoded.push(encodeURIComponent(name_parts[i]));
|
name_encoded.push(encodeURIComponent(name_parts[i]));
|
||||||
}
|
}
|
||||||
window.location = baseUrl + name_encoded.join('/');
|
window.location = '<%= create_path %>' + name_encoded.join('/');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -315,7 +319,7 @@ $(document).ready(function() {
|
|||||||
if( $("#last-edit").length ) {
|
if( $("#last-edit").length ) {
|
||||||
$("#page-info-toggle").click ( function () {
|
$("#page-info-toggle").click ( function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/last-commit-info',
|
url: '<%= last_commit_info_path %>',
|
||||||
data: {path: $("#page-info-toggle").data('pagepath')},
|
data: {path: $("#page-info-toggle").data('pagepath')},
|
||||||
success: function ( data ) {
|
success: function ( data ) {
|
||||||
$("#last-edit").html('Last edited by <b>' + data.author + '</b>, ' + data.date);
|
$("#last-edit").html('Last edited by <b>' + data.author + '</b>, ' + data.date);
|
||||||
@@ -9,10 +9,10 @@
|
|||||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||||
class="action-view-page">View Page</a></li>
|
class="action-view-page">View Page</a></li>
|
||||||
{{#allow_editing}}
|
{{#allow_editing}}
|
||||||
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{edit_path}}/{{escaped_url_path}}"
|
||||||
class="action-edit-page">Edit Page</a></li>
|
class="action-edit-page">Edit Page</a></li>
|
||||||
{{/allow_editing}}
|
{{/allow_editing}}
|
||||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||||
class="action-page-history">Page History</a></li>
|
class="action-page-history">Page History</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -25,11 +25,11 @@
|
|||||||
|
|
||||||
{{#show_revert}}
|
{{#show_revert}}
|
||||||
<ul class="actions">
|
<ul class="actions">
|
||||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||||
class="action-page-history">Back to Page History</a></li>
|
class="action-page-history">Back to Page History</a></li>
|
||||||
{{#allow_editing}}
|
{{#allow_editing}}
|
||||||
<li class="minibutton">
|
<li class="minibutton">
|
||||||
<form name="gollum-revert" action="{{base_url}}/revert/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form">
|
<form name="gollum-revert" action="{{revert_path}}/{{escaped_url_path}}/{{before}}/{{after}}" method="post" id="gollum-revert-form">
|
||||||
<a href="#" class="gollum-revert-button">Revert Changes</a>
|
<a href="#" class="gollum-revert-button">Revert Changes</a>
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="footer">
|
<div id="footer">
|
||||||
<ul class="actions">
|
<ul class="actions">
|
||||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||||
class="action-page-history">Back to Page History</a></li>
|
class="action-page-history">Back to Page History</a></li>
|
||||||
{{#show_revert}}
|
{{#show_revert}}
|
||||||
{{#allow_editing}}
|
{{#allow_editing}}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<ul class="actions">
|
<ul class="actions">
|
||||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||||
class="action-view-page">View Page</a></li>
|
class="action-view-page">View Page</a></li>
|
||||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||||
class="action-page-history">Page History</a></li>
|
class="action-page-history">Page History</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<div id="gollum-editor" data-escaped-name="{{escaped_name}}" class="{{#is_create_page}}create{{/is_create_page}}{{#is_edit_page}}edit{{/is_edit_page}} {{#allow_uploads}}uploads-allowed{{/allow_uploads}}">
|
<div id="gollum-editor" data-escaped-name="{{escaped_name}}" class="{{#is_create_page}}create{{/is_create_page}}{{#is_edit_page}}edit{{/is_edit_page}} {{#allow_uploads}}uploads-allowed{{/allow_uploads}}">
|
||||||
{{#is_create_page}}
|
{{#is_create_page}}
|
||||||
<form name="gollum-editor" action="{{base_url}}/create" method="post">
|
<form name="gollum-editor" action="{{create_path}}" method="post">
|
||||||
{{/is_create_page}}
|
{{/is_create_page}}
|
||||||
{{#is_edit_page}}
|
{{#is_edit_page}}
|
||||||
<form name="gollum-editor" action="{{base_url}}/edit/{{escaped_name}}" method="post">
|
<form name="gollum-editor" action="{{edit_path}}/{{escaped_name}}" method="post">
|
||||||
{{/is_edit_page}}
|
{{/is_edit_page}}
|
||||||
<fieldset id="gollum-editor-fields">
|
<fieldset id="gollum-editor-fields">
|
||||||
{{#is_create_page}}
|
{{#is_create_page}}
|
||||||
@@ -147,7 +147,7 @@
|
|||||||
<span class="jaws"><br></span>
|
<span class="jaws"><br></span>
|
||||||
<input type="submit" id="gollum-editor-submit" value="Save" title="Save current changes">
|
<input type="submit" id="gollum-editor-submit" value="Save" title="Save current changes">
|
||||||
<a href="" id="gollum-editor-cancel" class="minibutton" title="Cancel editing" onClick="window.history.back()">Cancel</a>
|
<a href="" id="gollum-editor-cancel" class="minibutton" title="Cancel editing" onClick="window.history.back()">Cancel</a>
|
||||||
<a href="{{base_url}}/preview" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
<a href="{{preview_path}}" id="gollum-editor-preview" class="minibutton" title="Preview this Page">Preview</a>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||||
class="action-view-page">View Page</a></li>
|
class="action-view-page">View Page</a></li>
|
||||||
{{#allow_editing}}
|
{{#allow_editing}}
|
||||||
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{edit_path}}/{{escaped_url_path}}"
|
||||||
class="action-edit-page">Edit Page</a></li>
|
class="action-edit-page">Edit Page</a></li>
|
||||||
{{/allow_editing}}
|
{{/allow_editing}}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<form name="compare-versions" id="version-form" method="post"
|
<form name="compare-versions" id="version-form" method="post"
|
||||||
action="{{base_url}}/compare/{{escaped_url_path}}">
|
action="{{compare_path}}/{{escaped_url_path}}">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<a href="javascript:void(0)">
|
<a href="javascript:void(0)">
|
||||||
<img src="{{#image_path_mustache}}man_24.png{{/image_path_mustache}}" alt="avatar: {{author}}"
|
<img src="{{#sprockets_image_path}}man_24.png{{/sprockets_image_path}}" alt="avatar: {{author}}"
|
||||||
class="mini-gravatar identicon" data-identicon="{{identicon}}"/>
|
class="mini-gravatar identicon" data-identicon="{{identicon}}"/>
|
||||||
<span class="username">{{author}}</span>
|
<span class="username">{{author}}</span>
|
||||||
</a>
|
</a>
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
<meta name="MobileOptimized" content="width">
|
<meta name="MobileOptimized" content="width">
|
||||||
<meta name="HandheldFriendly" content="true">
|
<meta name="HandheldFriendly" content="true">
|
||||||
<meta name="viewport" content="width=device-width">
|
<meta name="viewport" content="width=device-width">
|
||||||
{{#stylesheet_tag_mustache}}app media: :all{{/stylesheet_tag_mustache}}
|
{{#sprockets_stylesheet_tag}}app{{/sprockets_stylesheet_tag}}
|
||||||
{{#stylesheet_tag_mustache}}print media: :print{{/stylesheet_tag_mustache}}
|
{{#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_path}}/custom.css" media="all">{{/css}}
|
||||||
{{#noindex}}<meta name="robots" content="noindex, nofollow" />{{/noindex}}
|
{{#noindex}}<meta name="robots" content="noindex, nofollow" />{{/noindex}}
|
||||||
|
|
||||||
<!--[if lte IE 8]>
|
<!--[if lte IE 8]>
|
||||||
{{#stylesheet_tag_mustache}}ie7 media: :all{{/stylesheet_tag_mustache}}
|
{{#sprockets_stylesheet_tag}}ie7{{/sprockets_stylesheet_tag}}
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
var pageFullPath = '{{url_path}}';
|
var pageFullPath = '{{url_path}}';
|
||||||
{{/page}}
|
{{/page}}
|
||||||
</script>
|
</script>
|
||||||
{{#javascript_tag_mustache}}app{{/javascript_tag_mustache}}
|
{{#sprockets_javascript_tag}}app{{/sprockets_javascript_tag}}
|
||||||
{{#use_identicon}}
|
{{#use_identicon}}
|
||||||
{{#javascript_tag_mustache}}identicon_canvas{{/javascript_tag_mustache}}
|
{{#sprockets_javascript_tag}}identicon_canvas{{/sprockets_javascript_tag}}
|
||||||
{{/use_identicon}}
|
{{/use_identicon}}
|
||||||
{{#mathjax}}
|
{{#mathjax}}
|
||||||
{{^mathjax_config}}
|
{{^mathjax_config}}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Mousetrap.bind(['e'], function( e ) {
|
|||||||
</li>
|
</li>
|
||||||
<li class="minibutton"><a href="{{base_url}}/"
|
<li class="minibutton"><a href="{{base_url}}/"
|
||||||
class="action-home-page">Home</a></li>
|
class="action-home-page">Home</a></li>
|
||||||
<li class="minibutton"><a href="{{base_url}}/pages"
|
<li class="minibutton"><a href="{{pages_path}}"
|
||||||
class="action-all-pages">Overview</a></li>
|
class="action-all-pages">Overview</a></li>
|
||||||
{{#allow_editing}}
|
{{#allow_editing}}
|
||||||
<li class="minibutton jaws">
|
<li class="minibutton jaws">
|
||||||
@@ -34,13 +34,13 @@ Mousetrap.bind(['e'], function( e ) {
|
|||||||
{{/allow_editing}}
|
{{/allow_editing}}
|
||||||
{{#allow_editing}}
|
{{#allow_editing}}
|
||||||
{{#editable}}
|
{{#editable}}
|
||||||
<li class="minibutton"><a href="{{base_url}}/edit/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{edit_path}}/{{escaped_url_path}}"
|
||||||
class="action-edit-page">Edit</a></li>
|
class="action-edit-page">Edit</a></li>
|
||||||
{{/editable}}
|
{{/editable}}
|
||||||
{{/allow_editing}}
|
{{/allow_editing}}
|
||||||
<li class="minibutton"><a href="{{base_url}}/history/{{escaped_url_path}}"
|
<li class="minibutton"><a href="{{history_path}}/{{escaped_url_path}}"
|
||||||
class="action-page-history">History</a></li>
|
class="action-page-history">History</a></li>
|
||||||
<li class="minibutton"><a href="{{base_url}}/latest_changes"
|
<li class="minibutton"><a href="{{latest_changes_path}}"
|
||||||
class="action-page-history">Latest Changes</a></li>
|
class="action-page-history">Latest Changes</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -91,7 +91,7 @@ Mousetrap.bind(['e'], function( e ) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form name="rename" method="POST" action="{{base_url}}/rename/{{escaped_url_path}}">
|
<form name="rename" method="POST" action="{{rename_path}}/{{escaped_url_path}}">
|
||||||
<input type="hidden" name="rename"/>
|
<input type="hidden" name="rename"/>
|
||||||
<input type="hidden" name="message"/>
|
<input type="hidden" name="message"/>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<div id="searchbar">
|
<div id="searchbar">
|
||||||
<form action="{{base_url}}/search" method="get" id="search-form">
|
<form action="{{search_path}}" method="get" id="search-form">
|
||||||
<div id="searchbar-fauxtext">
|
<div id="searchbar-fauxtext">
|
||||||
<input type="text" name="q" id="search-query" value="Search…" autocomplete="off">
|
<input type="text" name="q" id="search-query" value="Search…" autocomplete="off">
|
||||||
<a href="#" id="search-submit" title="Search this wiki">
|
<a href="#" id="search-submit" title="Search this wiki">
|
||||||
|
|||||||
+47
-15
@@ -2,31 +2,63 @@ require 'yaml'
|
|||||||
|
|
||||||
module Precious
|
module Precious
|
||||||
module Views
|
module Views
|
||||||
|
module RouteHelpers
|
||||||
|
ROUTES = {
|
||||||
|
'gollum' => {
|
||||||
|
last_commit_info: 'last-commit-info',
|
||||||
|
latest_changes: 'latest_changes',
|
||||||
|
upload_file: 'uploadFile',
|
||||||
|
create: 'create',
|
||||||
|
delete: 'delete',
|
||||||
|
edit: 'edit',
|
||||||
|
pages: 'pages',
|
||||||
|
history: 'history',
|
||||||
|
rename: 'rename',
|
||||||
|
preview: 'preview',
|
||||||
|
compare: 'compare',
|
||||||
|
search: 'search'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def self.parse_routes(routes, prefix = '')
|
||||||
|
routes.each do |name, path|
|
||||||
|
if path.respond_to?(:keys)
|
||||||
|
self.parse_routes(path, "#{prefix}/#{name}")
|
||||||
|
else
|
||||||
|
define_method :"#{name.to_s}_path" do
|
||||||
|
"#{base_url}/#{prefix}/#{path}".gsub(/\/{2,}/, '/') # remove double slashes
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.included(base)
|
||||||
|
self.parse_routes(ROUTES)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module SprocketsHelpers
|
module SprocketsHelpers
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
|
|
||||||
def helper_proc_with_options(method)
|
def sprockets_stylesheet_tag
|
||||||
Proc.new do |args|
|
lambda do |args|
|
||||||
args = args.split(' ')
|
args = args.split(' ')
|
||||||
if args.size > 1 then
|
name = args[0]
|
||||||
options = args[1..-1].join(' ')
|
options = {:media => :all}
|
||||||
options = YAML.safe_load("---\n#{options}\n", [Symbol])
|
options[:media] = :print if args[1] == 'print'
|
||||||
end
|
send(:stylesheet_tag, name, options)
|
||||||
options = options.respond_to?(:to_h) ? options.to_h : {}
|
|
||||||
options = options.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
|
||||||
send(method, args[0], options)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
['stylesheet_path','javascript_path', 'image_path'].each do |method|
|
def sprockets_javascript_tag
|
||||||
define_method :"#{method}_mustache" do
|
lambda do |name|
|
||||||
Proc.new {|args| send(method.to_sym, args)}
|
send(:javascript_tag, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
['stylesheet_tag','javascript_tag'].each do |method|
|
def sprockets_image_path
|
||||||
define_method :"#{method}_mustache" do
|
lambda do |args|
|
||||||
helper_proc_with_options(method.to_sym)
|
send(:image_path, name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ module Precious
|
|||||||
include Rack::Utils
|
include Rack::Utils
|
||||||
include Sprockets::Helpers
|
include Sprockets::Helpers
|
||||||
include Precious::Views::SprocketsHelpers
|
include Precious::Views::SprocketsHelpers
|
||||||
|
include Precious::Views::RouteHelpers
|
||||||
|
|
||||||
alias_method :h, :escape_html
|
alias_method :h, :escape_html
|
||||||
|
|
||||||
attr_reader :name, :path
|
attr_reader :name, :path
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ module Precious
|
|||||||
# result contains a folder
|
# result contains a folder
|
||||||
folder = result_path.split('/').first
|
folder = result_path.split('/').first
|
||||||
folder_path = @path ? "#{@path}/#{folder}" : folder
|
folder_path = @path ? "#{@path}/#{folder}" : folder
|
||||||
folder_link = %{<li><a href="#{@base_url}/pages/#{folder_path}/" class="folder">#{folder}</a></li>}
|
folder_link = %{<li><a href="#{pages_path}/#{folder_path}/" class="folder">#{folder}</a></li>}
|
||||||
|
|
||||||
folders[folder] = folder_link unless folders.key?(folder)
|
folders[folder] = folder_link unless folders.key?(folder)
|
||||||
elsif result_path != ".gitkeep"
|
elsif result_path != ".gitkeep"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ context "Precious::Views::Editing" do
|
|||||||
|
|
||||||
test "creating page is blocked" do
|
test "creating page is blocked" do
|
||||||
Precious::App.set(:wiki_options, { allow_editing: false})
|
Precious::App.set(:wiki_options, { allow_editing: false})
|
||||||
post "/create", :content => 'abc', :page => "D",
|
post "/gollum/create", :content => 'abc', :page => "D",
|
||||||
:format => 'markdown', :message => 'def'
|
:format => 'markdown', :message => 'def'
|
||||||
assert !last_response.ok?
|
assert !last_response.ok?
|
||||||
|
|
||||||
@@ -36,15 +36,15 @@ context "Precious::Views::Editing" do
|
|||||||
assert_match /Rename/, last_response.body, "'Rename' link is blocked in page template"
|
assert_match /Rename/, last_response.body, "'Rename' link is blocked in page template"
|
||||||
assert_match /Edit/, last_response.body, "'Edit' link is blocked in page template"
|
assert_match /Edit/, last_response.body, "'Edit' link is blocked in page template"
|
||||||
|
|
||||||
get '/pages'
|
get '/gollum/pages'
|
||||||
|
|
||||||
assert_match /New/, last_response.body, "'New' link is blocked in pages template"
|
assert_match /New/, last_response.body, "'New' link is blocked in pages template"
|
||||||
|
|
||||||
get '/history/A'
|
get '/gollum/history/A'
|
||||||
|
|
||||||
assert_match /Edit/, last_response.body, "'Edit' link is blocked in history template"
|
assert_match /Edit/, last_response.body, "'Edit' link is blocked in history template"
|
||||||
|
|
||||||
get '/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
||||||
|
|
||||||
assert_match /Edit Page/, last_response.body, "'Edit Page' link is blocked in compare template"
|
assert_match /Edit Page/, last_response.body, "'Edit Page' link is blocked in compare template"
|
||||||
assert_match /Revert Changes/, last_response.body, "'Revert Changes' link is blocked in compare template"
|
assert_match /Revert Changes/, last_response.body, "'Revert Changes' link is blocked in compare template"
|
||||||
@@ -60,15 +60,15 @@ context "Precious::Views::Editing" do
|
|||||||
assert_no_match /Rename/, last_response.body, "'Rename' link not blocked in page template"
|
assert_no_match /Rename/, last_response.body, "'Rename' link not blocked in page template"
|
||||||
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in page template"
|
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in page template"
|
||||||
|
|
||||||
get '/pages'
|
get '/gollum/pages'
|
||||||
|
|
||||||
assert_no_match /New/, last_response.body, "'New' link not blocked in pages template"
|
assert_no_match /New/, last_response.body, "'New' link not blocked in pages template"
|
||||||
|
|
||||||
get '/history/A'
|
get '/gollum/history/A'
|
||||||
|
|
||||||
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in history template"
|
assert_no_match /Edit/, last_response.body, "'Edit' link not blocked in history template"
|
||||||
|
|
||||||
get '/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
get '/gollum/compare/A/fc66539528eb96f21b2bbdbf557788fe8a1196ac..b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f'
|
||||||
|
|
||||||
assert_no_match /Edit Page/, last_response.body, "'Edit Page' link not blocked in compare template"
|
assert_no_match /Edit Page/, last_response.body, "'Edit Page' link not blocked in compare template"
|
||||||
assert_no_match /Revert Changes/, last_response.body, "'Revert Changes' link not blocked in compare template"
|
assert_no_match /Revert Changes/, last_response.body, "'Revert Changes' link not blocked in compare template"
|
||||||
|
|||||||
+54
-54
@@ -73,13 +73,13 @@ context "Frontend" do
|
|||||||
@wiki.write_page(page1, :markdown, '',
|
@wiki.write_page(page1, :markdown, '',
|
||||||
{ :name => user1, :email => user1 });
|
{ :name => user1, :email => user1 });
|
||||||
|
|
||||||
get "/last-commit-info", :path => page1
|
get "/gollum/last-commit-info", :path => page1
|
||||||
assert_match /\"author\":\"user1\"/, last_response.body
|
assert_match /\"author\":\"user1\"/, last_response.body
|
||||||
end
|
end
|
||||||
|
|
||||||
test "edits page" do
|
test "edits page" do
|
||||||
page_1 = @wiki.page('A')
|
page_1 = @wiki.page('A')
|
||||||
post "/edit/A", :content => 'abc', :page => 'A',
|
post "/gollum/edit/A", :content => 'abc', :page => 'A',
|
||||||
:format => page_1.format, :message => 'def'
|
:format => page_1.format, :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -93,7 +93,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "edit page with empty message" do
|
test "edit page with empty message" do
|
||||||
page_1 = @wiki.page('A')
|
page_1 = @wiki.page('A')
|
||||||
post "/edit/A", :content => 'abc', :page => 'A',
|
post "/gollum/edit/A", :content => 'abc', :page => 'A',
|
||||||
:format => page_1.format
|
:format => page_1.format
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -107,7 +107,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "edit page with slash" do
|
test "edit page with slash" do
|
||||||
page_1 = @wiki.page('A')
|
page_1 = @wiki.page('A')
|
||||||
post "/edit/A", :content => 'abc', :page => 'A', :path => '/////',
|
post "/gollum/edit/A", :content => 'abc', :page => 'A', :path => '/////',
|
||||||
:format => page_1.format, :message => 'def'
|
:format => page_1.format, :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -120,7 +120,7 @@ context "Frontend" do
|
|||||||
foot_1 = page_1.footer
|
foot_1 = page_1.footer
|
||||||
side_1 = page_1.sidebar
|
side_1 = page_1.sidebar
|
||||||
|
|
||||||
post "/edit/A", :header => 'header',
|
post "/gollum/edit/A", :header => 'header',
|
||||||
:footer => 'footer', :page => "A", :sidebar => 'sidebar', :message => 'def'
|
:footer => 'footer', :page => "A", :sidebar => 'sidebar', :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal "/A.md", last_request.fullpath
|
assert_equal "/A.md", last_request.fullpath
|
||||||
@@ -147,7 +147,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "renames page" do
|
test "renames page" do
|
||||||
page_1 = @wiki.page("B")
|
page_1 = @wiki.page("B")
|
||||||
post "/rename/B", :rename => "/C", :message => 'def'
|
post "/gollum/rename/B", :rename => "/C", :message => 'def'
|
||||||
|
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal '/C.md', last_request.fullpath
|
assert_equal '/C.md', last_request.fullpath
|
||||||
@@ -163,21 +163,21 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "renames page catches invalid page" do
|
test "renames page catches invalid page" do
|
||||||
# No such page
|
# No such page
|
||||||
post "/rename/no-such-file-here", :rename => "/C", :message => 'def'
|
post "/gollum/rename/no-such-file-here", :rename => "/C", :message => 'def'
|
||||||
assert !last_response.ok?
|
assert !last_response.ok?
|
||||||
assert_equal last_response.status, 500
|
assert_equal last_response.status, 500
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rename page catches empty target" do
|
test "rename page catches empty target" do
|
||||||
# Empty rename target
|
# Empty rename target
|
||||||
post "/rename/B", :rename => "", :message => 'def'
|
post "/gollum/rename/B", :rename => "", :message => 'def'
|
||||||
assert !last_response.ok?
|
assert !last_response.ok?
|
||||||
assert_equal last_response.status, 500
|
assert_equal last_response.status, 500
|
||||||
end
|
end
|
||||||
|
|
||||||
test "rename page catches non-existent target" do
|
test "rename page catches non-existent target" do
|
||||||
# Non-existent rename target
|
# Non-existent rename target
|
||||||
post "/rename/B", :message => 'def'
|
post "/gollum/rename/B", :message => 'def'
|
||||||
assert !last_response.ok?
|
assert !last_response.ok?
|
||||||
assert_equal last_response.status, 500
|
assert_equal last_response.status, 500
|
||||||
end
|
end
|
||||||
@@ -186,7 +186,7 @@ context "Frontend" do
|
|||||||
test "renames page in subdirectory" do
|
test "renames page in subdirectory" do
|
||||||
page_1 = @wiki.paged("H", "G")
|
page_1 = @wiki.paged("H", "G")
|
||||||
assert_not_equal page_1, nil
|
assert_not_equal page_1, nil
|
||||||
post "/rename/G/H", :rename => "/I/C", :message => 'def'
|
post "/gollum/rename/G/H", :rename => "/I/C", :message => 'def'
|
||||||
|
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal '/I/C.md', last_request.fullpath
|
assert_equal '/I/C.md', last_request.fullpath
|
||||||
@@ -203,7 +203,7 @@ context "Frontend" do
|
|||||||
test "renames page relative in subdirectory" do
|
test "renames page relative in subdirectory" do
|
||||||
page_1 = @wiki.paged("H", "G")
|
page_1 = @wiki.paged("H", "G")
|
||||||
assert_not_equal page_1, nil
|
assert_not_equal page_1, nil
|
||||||
post "/rename/G/H", :rename => "K/C", :message => 'def'
|
post "/gollum/rename/G/H", :rename => "K/C", :message => 'def'
|
||||||
|
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal '/G/K/C.md', last_request.fullpath
|
assert_equal '/G/K/C.md', last_request.fullpath
|
||||||
@@ -219,7 +219,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
|
|
||||||
test "creates page" do
|
test "creates page" do
|
||||||
post "/create", :content => 'abc', :page => "D",
|
post "/gollum/create", :content => 'abc', :page => "D",
|
||||||
:format => 'markdown', :message => 'def'
|
:format => 'markdown', :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -230,7 +230,7 @@ context "Frontend" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "creates pages with escaped characters in title" do
|
test "creates pages with escaped characters in title" do
|
||||||
post "/create", :content => 'abc', :page => 'Title with spaces',
|
post "/gollum/create", :content => 'abc', :page => 'Title with spaces',
|
||||||
:format => 'markdown', :message => 'foo'
|
:format => 'markdown', :message => 'foo'
|
||||||
assert_equal 'http://example.org/Title%20with%20spaces.md', last_response.headers['Location']
|
assert_equal 'http://example.org/Title%20with%20spaces.md', last_response.headers['Location']
|
||||||
get "/Title%20with%20spaces"
|
get "/Title%20with%20spaces"
|
||||||
@@ -241,7 +241,7 @@ context "Frontend" do
|
|||||||
name = "E"
|
name = "E"
|
||||||
get "/#{name}"
|
get "/#{name}"
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal "/create/#{name}", last_request.fullpath
|
assert_equal "/gollum/create/#{name}", last_request.fullpath
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -249,12 +249,12 @@ context "Frontend" do
|
|||||||
get "/foo/"
|
get "/foo/"
|
||||||
|
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal "/create/foo/Home", last_request.fullpath
|
assert_equal "/gollum/create/foo/Home", last_request.fullpath
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "accessing redirectory redirects to index page" do
|
test "accessing redirectory redirects to index page" do
|
||||||
post "/create", :content => 'abc', :page => 'Home', :path => '/foo/',
|
post "/gollum/create", :content => 'abc', :page => 'Home', :path => '/foo/',
|
||||||
:format => 'markdown', :message => 'foo'
|
:format => 'markdown', :message => 'foo'
|
||||||
|
|
||||||
assert_equal "http://example.org/foo/Home.md", last_response.headers['Location']
|
assert_equal "http://example.org/foo/Home.md", last_response.headers['Location']
|
||||||
@@ -265,15 +265,15 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "edit redirects to create on non-existant page" do
|
test "edit redirects to create on non-existant page" do
|
||||||
name = "E"
|
name = "E"
|
||||||
get "/edit/#{name}"
|
get "/gollum/edit/#{name}"
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal "/create/#{name}", last_request.fullpath
|
assert_equal "/gollum/create/#{name}", last_request.fullpath
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create redirects to page if already exists" do
|
test "create redirects to page if already exists" do
|
||||||
name = "A.md"
|
name = "A.md"
|
||||||
get "/create/#{name}"
|
get "/gollum/create/#{name}"
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert_equal "/#{name}", last_request.fullpath
|
assert_equal "/#{name}", last_request.fullpath
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -282,7 +282,7 @@ context "Frontend" do
|
|||||||
test "create sets the correct path for a relative path subdirectory" do
|
test "create sets the correct path for a relative path subdirectory" do
|
||||||
dir = "foodir"
|
dir = "foodir"
|
||||||
name = "#{dir}/bar"
|
name = "#{dir}/bar"
|
||||||
get "/create/#{name}"
|
get "/gollum/create/#{name}"
|
||||||
assert_match(/\/#{dir}/, last_response.body)
|
assert_match(/\/#{dir}/, last_response.body)
|
||||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||||
end
|
end
|
||||||
@@ -290,21 +290,21 @@ context "Frontend" do
|
|||||||
test "create with template succeed if template exists" do
|
test "create with template succeed if template exists" do
|
||||||
Precious::App.set(:wiki_options, { :template_page => true })
|
Precious::App.set(:wiki_options, { :template_page => true })
|
||||||
page='_Template'
|
page='_Template'
|
||||||
post '/create', :content => 'fake template', :page => page,
|
post '/gollum/create', :content => 'fake template', :page => page,
|
||||||
:path => '/', :format => 'markdown', :message => ''
|
:path => '/', :format => 'markdown', :message => ''
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
#puts last_response
|
#puts last_response
|
||||||
@wiki.clear_cache
|
@wiki.clear_cache
|
||||||
get "/create/TT"
|
get "/gollum/create/TT"
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
get '/delete/_Template'
|
get '/gollum/delete/_Template'
|
||||||
Precious::App.set(:wiki_options, { :template_page => false })
|
Precious::App.set(:wiki_options, { :template_page => false })
|
||||||
end
|
end
|
||||||
|
|
||||||
test "create with template succeed if template doesn't exist" do
|
test "create with template succeed if template doesn't exist" do
|
||||||
Precious::App.set(:wiki_options, { :template_page => true })
|
Precious::App.set(:wiki_options, { :template_page => true })
|
||||||
get "/create/TT"
|
get "/gollum/create/TT"
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
Precious::App.set(:wiki_options, { :template_page => false })
|
Precious::App.set(:wiki_options, { :template_page => false })
|
||||||
end
|
end
|
||||||
@@ -313,7 +313,7 @@ context "Frontend" do
|
|||||||
Precious::App.set(:wiki_options, { :page_file_dir => "foo" })
|
Precious::App.set(:wiki_options, { :page_file_dir => "foo" })
|
||||||
dir = "bardir"
|
dir = "bardir"
|
||||||
name = "#{dir}/baz"
|
name = "#{dir}/baz"
|
||||||
get "/create/foo/#{name}"
|
get "/gollum/create/foo/#{name}"
|
||||||
assert_match(/\/#{dir}/, last_response.body)
|
assert_match(/\/#{dir}/, last_response.body)
|
||||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||||
# reset page_file_dir
|
# reset page_file_dir
|
||||||
@@ -324,7 +324,7 @@ context "Frontend" do
|
|||||||
# post '/edit' fails. post '/edit/' works.
|
# post '/edit' fails. post '/edit/' works.
|
||||||
page = 'not-real-page'
|
page = 'not-real-page'
|
||||||
path = '/'
|
path = '/'
|
||||||
post '/edit/', :content => 'edit_msg',
|
post '/gollum/edit/', :content => 'edit_msg',
|
||||||
:page => page, :path => path, :message => ''
|
:page => page, :path => path, :message => ''
|
||||||
page_e = @wiki.paged(page, path)
|
page_e = @wiki.paged(page, path)
|
||||||
assert_equal nil, page_e
|
assert_equal nil, page_e
|
||||||
@@ -334,7 +334,7 @@ context "Frontend" do
|
|||||||
page = 'c-d-e'
|
page = 'c-d-e'
|
||||||
path = 'a/b/' # path must end with /
|
path = 'a/b/' # path must end with /
|
||||||
|
|
||||||
post '/create', :content => 'create_msg', :page => page,
|
post '/gollum/create', :content => 'create_msg', :page => page,
|
||||||
:path => path, :format => 'markdown', :message => ''
|
:path => path, :format => 'markdown', :message => ''
|
||||||
page_c = @wiki.paged(page, path)
|
page_c = @wiki.paged(page, path)
|
||||||
assert_equal 'create_msg', page_c.raw_data
|
assert_equal 'create_msg', page_c.raw_data
|
||||||
@@ -343,7 +343,7 @@ context "Frontend" do
|
|||||||
@wiki.clear_cache
|
@wiki.clear_cache
|
||||||
|
|
||||||
# post '/edit' fails. post '/edit/' works.
|
# post '/edit' fails. post '/edit/' works.
|
||||||
post '/edit/', :content => 'edit_msg',
|
post '/gollum/edit/', :content => 'edit_msg',
|
||||||
:page => page, :path => path, :message => ''
|
:page => page, :path => path, :message => ''
|
||||||
page_e = @wiki.paged(page, path)
|
page_e = @wiki.paged(page, path)
|
||||||
assert_equal 'edit_msg', page_e.raw_data
|
assert_equal 'edit_msg', page_e.raw_data
|
||||||
@@ -362,7 +362,7 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "guards against creation of existing page" do
|
test "guards against creation of existing page" do
|
||||||
name = "A"
|
name = "A"
|
||||||
post "/create", :content => 'abc', :page => name,
|
post "/gollum/create", :content => 'abc', :page => name,
|
||||||
:format => 'markdown', :message => 'def'
|
:format => 'markdown', :message => 'def'
|
||||||
|
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -374,12 +374,12 @@ context "Frontend" do
|
|||||||
|
|
||||||
test "delete a page" do
|
test "delete a page" do
|
||||||
name = "deleteme"
|
name = "deleteme"
|
||||||
post "/create", :content => 'abc', :page => name,
|
post "/gollum/create", :content => 'abc', :page => name,
|
||||||
:format => 'markdown', :message => 'foo'
|
:format => 'markdown', :message => 'foo'
|
||||||
page = @wiki.page(name)
|
page = @wiki.page(name)
|
||||||
assert_equal 'abc', page.raw_data
|
assert_equal 'abc', page.raw_data
|
||||||
|
|
||||||
get '/delete/' + name
|
get '/gollum/delete/' + name
|
||||||
|
|
||||||
@wiki.clear_cache
|
@wiki.clear_cache
|
||||||
page = @wiki.page(name)
|
page = @wiki.page(name)
|
||||||
@@ -387,7 +387,7 @@ context "Frontend" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "previews content" do
|
test "previews content" do
|
||||||
post "/preview", :content => 'abc', :format => 'markdown'
|
post "/gollum/preview", :content => 'abc', :format => 'markdown'
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ context "Frontend" do
|
|||||||
@wiki = Gollum::Wiki.new(@path)
|
@wiki = Gollum::Wiki.new(@path)
|
||||||
Precious::App.set(:gollum_path, @path)
|
Precious::App.set(:gollum_path, @path)
|
||||||
Precious::App.set(:wiki_options, {})
|
Precious::App.set(:wiki_options, {})
|
||||||
post "/preview", :content => 'abc', :format => 'markdown'
|
post "/gollum/preview", :content => 'abc', :format => 'markdown'
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -469,7 +469,7 @@ context "Frontend" do
|
|||||||
gollum_author = { :name => 'ghi', :email => 'jkl' }
|
gollum_author = { :name => 'ghi', :email => 'jkl' }
|
||||||
session = { 'gollum.author' => gollum_author }
|
session = { 'gollum.author' => gollum_author }
|
||||||
|
|
||||||
post "/edit/A", { :content => 'abc', :page => 'A', :format => page1.format, :message => 'def' }, { 'rack.session' => session }
|
post "/gollum/edit/A", { :content => 'abc', :page => 'A', :format => page1.format, :message => 'def' }, { 'rack.session' => session }
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
|
|
||||||
@@ -510,21 +510,21 @@ context "Frontend" do
|
|||||||
|
|
||||||
['create', 'edit'].each do |route|
|
['create', 'edit'].each do |route|
|
||||||
['.css', '.js'].each do |ext|
|
['.css', '.js'].each do |ext|
|
||||||
get "/#{route}/custom#{ext}"
|
get "/gollum/#{route}/custom#{ext}"
|
||||||
assert_equal 403, last_response.status, "get /#{route}/custom#{ext} -- #{last_response.inspect}"
|
assert_equal 403, last_response.status, "get /gollum/#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
['deleteFile', 'rename', 'edit', 'create'].each do |route|
|
['deleteFile', 'rename', 'edit', 'create'].each do |route|
|
||||||
['.css', '.js'].each do |ext|
|
['.css', '.js'].each do |ext|
|
||||||
post "/#{route}/custom#{ext}"
|
post "/gollum/#{route}/custom#{ext}"
|
||||||
assert_equal 403, last_response.status, "post /#{route}/custom#{ext} -- #{last_response.inspect}"
|
assert_equal 403, last_response.status, "post /gollum/#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
['.css', '.js'].each do |ext|
|
['.css', '.js'].each do |ext|
|
||||||
post "/revert/custom#{ext}/02796b1450691f90db5d6dc6a816a4980ce80d07/2f6485c2702c7c8b9b6613672337ffa7d933ddcf"
|
post "/gollum/revert/custom#{ext}/02796b1450691f90db5d6dc6a816a4980ce80d07/2f6485c2702c7c8b9b6613672337ffa7d933ddcf"
|
||||||
assert_equal 403, last_response.status, "post /revert/custom#{ext} -- #{last_response.inspect}"
|
assert_equal 403, last_response.status, "post /gollum/revert/custom#{ext} -- #{last_response.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
Precious::App.set(:wiki_options, { :js => nil })
|
Precious::App.set(:wiki_options, { :js => nil })
|
||||||
@@ -544,15 +544,15 @@ context "Frontend" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "show edit page with header and footer and sidebar of multibyte" do
|
test "show edit page with header and footer and sidebar of multibyte" do
|
||||||
post "/create",
|
post "/gollum/create",
|
||||||
:content => 'りんご',
|
:content => 'りんご',
|
||||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
||||||
|
|
||||||
post "/edit/Multibyte",
|
post "/gollum/edit/Multibyte",
|
||||||
:content => 'りんご', :header => 'みかん', :footer => 'バナナ', :sidebar => 'スイカ',
|
:content => 'りんご', :header => 'みかん', :footer => 'バナナ', :sidebar => 'スイカ',
|
||||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
||||||
|
|
||||||
get "edit/Multibyte"
|
get "/gollum/edit/Multibyte"
|
||||||
|
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
assert_match /りんご/, last_response.body
|
assert_match /りんご/, last_response.body
|
||||||
@@ -620,7 +620,7 @@ context "Frontend with lotr" do
|
|||||||
#
|
#
|
||||||
|
|
||||||
test "/pages" do
|
test "/pages" do
|
||||||
get "/pages"
|
get "/gollum/pages"
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
|
|
||||||
body = last_response.body
|
body = last_response.body
|
||||||
@@ -633,8 +633,8 @@ context "Frontend with lotr" do
|
|||||||
assert !body.match(/(Zamin).+(roast\-mutton)/m), "/pages should be sorted alphabetically"
|
assert !body.match(/(Zamin).+(roast\-mutton)/m), "/pages should be sorted alphabetically"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "/pages/Mordor/" do
|
test "/gollum/pages/Mordor/" do
|
||||||
get "/pages/Mordor/"
|
get "/gollum/pages/Mordor/"
|
||||||
assert last_response.ok?, "/pages/Mordor/ did not respond ok"
|
assert last_response.ok?, "/pages/Mordor/ did not respond ok"
|
||||||
|
|
||||||
body = last_response.body
|
body = last_response.body
|
||||||
@@ -658,7 +658,7 @@ context "Frontend with lotr" do
|
|||||||
test "create pages within sub-directories using base path" do
|
test "create pages within sub-directories using base path" do
|
||||||
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
|
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
|
||||||
page = 'path'
|
page = 'path'
|
||||||
post "/create", :content => '123', :page => page,
|
post "/gollum/create", :content => '123', :page => page,
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
# should be wiki/Mordor/path
|
# should be wiki/Mordor/path
|
||||||
assert_equal 'http://example.org/Mordor/' + page + '.md', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/' + page + '.md', last_response.headers['Location']
|
||||||
@@ -670,7 +670,7 @@ context "Frontend with lotr" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "create pages within sub-directories using page file dir" do
|
test "create pages within sub-directories using page file dir" do
|
||||||
post "/create", :content => 'one two', :page => 'base',
|
post "/gollum/create", :content => 'one two', :page => 'base',
|
||||||
:path => 'wiki/Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'wiki/Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
assert_equal 'http://example.org/wiki/Mordor/base.md', last_response.headers['Location']
|
assert_equal 'http://example.org/wiki/Mordor/base.md', last_response.headers['Location']
|
||||||
get "/wiki/Mordor/base"
|
get "/wiki/Mordor/base"
|
||||||
@@ -680,13 +680,13 @@ context "Frontend with lotr" do
|
|||||||
|
|
||||||
|
|
||||||
test "create pages within sub-directories" do
|
test "create pages within sub-directories" do
|
||||||
post "/create", :content => 'big smelly creatures', :page => 'Orc',
|
post "/gollum/create", :content => 'big smelly creatures', :page => 'Orc',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||||
get "/Mordor/Orc"
|
get "/Mordor/Orc"
|
||||||
assert_match /big smelly creatures/, last_response.body
|
assert_match /big smelly creatures/, last_response.body
|
||||||
|
|
||||||
post "/create", :content => 'really big smelly creatures', :page => 'Uruk Hai',
|
post "/gollum/create", :content => 'really big smelly creatures', :page => 'Uruk Hai',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, very scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, very scary'
|
||||||
assert_equal 'http://example.org/Mordor/Uruk%20Hai.md', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Uruk%20Hai.md', last_response.headers['Location']
|
||||||
get "/Mordor/Uruk%20Hai"
|
get "/Mordor/Uruk%20Hai"
|
||||||
@@ -694,12 +694,12 @@ context "Frontend with lotr" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "edit pages within sub-directories" do
|
test "edit pages within sub-directories" do
|
||||||
post "/create", :content => 'big smelly creatures', :page => 'Orc',
|
post "/gollum/create", :content => 'big smelly creatures', :page => 'Orc',
|
||||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||||
|
|
||||||
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||||
|
|
||||||
post "/edit/Mordor/Orc", :content => 'not so big smelly creatures',
|
post "/gollum/edit/Mordor/Orc", :content => 'not so big smelly creatures',
|
||||||
:page => 'Orc', :path => 'Mordor', :message => 'minor edit'
|
:page => 'Orc', :path => 'Mordor', :message => 'minor edit'
|
||||||
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||||
|
|
||||||
@@ -721,14 +721,14 @@ context "Frontend with lotr" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "existing emoji" do
|
test "existing emoji" do
|
||||||
get "/emoji/heart"
|
get "/gollum/emoji/heart"
|
||||||
assert_equal 200, last_response.status
|
assert_equal 200, last_response.status
|
||||||
assert_equal 'image/png', last_response.headers['Content-Type']
|
assert_equal 'image/png', last_response.headers['Content-Type']
|
||||||
assert_equal [137, 80, 78, 71, 13, 10, 26, 10], last_response.body.each_byte.to_a[0..7]
|
assert_equal [137, 80, 78, 71, 13, 10, 26, 10], last_response.body.each_byte.to_a[0..7]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "missing emoji" do
|
test "missing emoji" do
|
||||||
get "/emoji/oggy_was_here"
|
get "/gollum/emoji/oggy_was_here"
|
||||||
assert_equal 404, last_response.status
|
assert_equal 404, last_response.status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ context "Precious::Views::LatestChanges" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "displays_latest_changes" do
|
test "displays_latest_changes" do
|
||||||
get('/latest_changes')
|
get('/gollum/latest_changes')
|
||||||
body = last_response.body
|
body = last_response.body
|
||||||
|
|
||||||
assert body.include?('<span class="username">Charles Pence</span>'), "/latest_changes should include the Author Charles Pence"
|
assert body.include?('<span class="username">Charles Pence</span>'), "/latest_changes should include the Author Charles Pence"
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ context "Precious::Views::Pages" do
|
|||||||
@page.instance_variable_set("@base_url", "")
|
@page.instance_variable_set("@base_url", "")
|
||||||
results = [FakePageResult.new("Gondor/Bromir.md"), FakePageResult.new("Hobbit.md"), FakePageResult.new("Home.md"), FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakePageResult.new("Mordor/todo.md"), FakePageResult.new("Rivendell/Elrond.md"), FakePageResult.new("My-Precious.md"), FakePageResult.new("Zamin.md"), FakePageResult.new("Samwise-Gamgee.md"), FakePageResult.new("roast-mutton.md"), FakePageResult.new("Bilbo-Baggins.md")]
|
results = [FakePageResult.new("Gondor/Bromir.md"), FakePageResult.new("Hobbit.md"), FakePageResult.new("Home.md"), FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakePageResult.new("Mordor/todo.md"), FakePageResult.new("Rivendell/Elrond.md"), FakePageResult.new("My-Precious.md"), FakePageResult.new("Zamin.md"), FakePageResult.new("Samwise-Gamgee.md"), FakePageResult.new("roast-mutton.md"), FakePageResult.new("Bilbo-Baggins.md")]
|
||||||
@page.instance_variable_set("@results", results)
|
@page.instance_variable_set("@results", results)
|
||||||
assert_equal %{<li><a href="/pages/Gondor/" class="folder">Gondor</a></li>\n<li><a href="/pages/Mordor/" class="folder">Mordor</a></li>\n<li><a href="/pages/Rivendell/" class="folder">Rivendell</a></li>\n<li><a href="/Bilbo-Baggins" class="page">Bilbo Baggins</a></li>\n<li><a href="/Hobbit" class="page">Hobbit</a></li>\n<li><a href="/Home" class="page">Home</a></li>\n<li><a href="/My-Precious" class="page">My Precious</a></li>\n<li><a href="/roast-mutton" class="page">roast mutton</a></li>\n<li><a href="/Samwise-Gamgee" class="page">Samwise Gamgee</a></li>\n<li><a href="/Zamin" class="page">Zamin</a></li>}, @page.files_folders
|
assert_equal %{<li><a href="/gollum/pages/Gondor/" class="folder">Gondor</a></li>\n<li><a href="/gollum/pages/Mordor/" class="folder">Mordor</a></li>\n<li><a href="/gollum/pages/Rivendell/" class="folder">Rivendell</a></li>\n<li><a href="/Bilbo-Baggins" class="page">Bilbo Baggins</a></li>\n<li><a href="/Hobbit" class="page">Hobbit</a></li>\n<li><a href="/Home" class="page">Home</a></li>\n<li><a href="/My-Precious" class="page">My Precious</a></li>\n<li><a href="/roast-mutton" class="page">roast mutton</a></li>\n<li><a href="/Samwise-Gamgee" class="page">Samwise Gamgee</a></li>\n<li><a href="/Zamin" class="page">Zamin</a></li>}, @page.files_folders
|
||||||
end
|
end
|
||||||
|
|
||||||
test "files_folders from subdir" do
|
test "files_folders from subdir" do
|
||||||
@@ -54,7 +54,7 @@ context "Precious::Views::Pages" do
|
|||||||
@page.instance_variable_set("@base_url", "")
|
@page.instance_variable_set("@base_url", "")
|
||||||
results = [FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakeFileResult.new("Mordor/Aragorn.pdf"), FakePageResult.new("Mordor/Orc/Saruman.md"), FakeFileResult.new("Mordor/.gitkeep")]
|
results = [FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakeFileResult.new("Mordor/Aragorn.pdf"), FakePageResult.new("Mordor/Orc/Saruman.md"), FakeFileResult.new("Mordor/.gitkeep")]
|
||||||
@page.instance_variable_set("@results", results)
|
@page.instance_variable_set("@results", results)
|
||||||
assert_equal %{<li><a href="/pages/Mordor/Orc/" class="folder">Orc</a></li>\n<li><a href="/Mordor/Aragorn.pdf" class="file">Aragorn.pdf</a></li>\n<li><a href="/Mordor/Eye-Of-Sauron" class="page">Eye Of Sauron</a></li>}, @page.files_folders
|
assert_equal %{<li><a href="/gollum/pages/Mordor/Orc/" class="folder">Orc</a></li>\n<li><a href="/Mordor/Aragorn.pdf" class="file">Aragorn.pdf</a></li>\n<li><a href="/Mordor/Eye-Of-Sauron" class="page">Eye Of Sauron</a></li>}, @page.files_folders
|
||||||
end
|
end
|
||||||
|
|
||||||
test "base url" do
|
test "base url" do
|
||||||
@@ -63,6 +63,6 @@ context "Precious::Views::Pages" do
|
|||||||
@page.instance_variable_set("@base_url", "/wiki")
|
@page.instance_variable_set("@base_url", "/wiki")
|
||||||
results = [FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakeFileResult.new("Mordor/Aragorn.pdf"), FakePageResult.new("Mordor/Orc/Saruman.md"), FakePageResult.new("Mordor/.gitkeep")]
|
results = [FakePageResult.new("Mordor/Eye-Of-Sauron.md"), FakeFileResult.new("Mordor/Aragorn.pdf"), FakePageResult.new("Mordor/Orc/Saruman.md"), FakePageResult.new("Mordor/.gitkeep")]
|
||||||
@page.instance_variable_set("@results", results)
|
@page.instance_variable_set("@results", results)
|
||||||
assert_equal %{<li><a href="/wiki/pages/Mordor/Orc/" class="folder">Orc</a></li>\n<li><a href="/wiki/Mordor/Aragorn.pdf" class="file">Aragorn.pdf</a></li>\n<li><a href="/wiki/Mordor/Eye-Of-Sauron" class="page">Eye Of Sauron</a></li>}, @page.files_folders
|
assert_equal %{<li><a href="/wiki/gollum/pages/Mordor/Orc/" class="folder">Orc</a></li>\n<li><a href="/wiki/Mordor/Aragorn.pdf" class="file">Aragorn.pdf</a></li>\n<li><a href="/wiki/Mordor/Eye-Of-Sauron" class="page">Eye Of Sauron</a></li>}, @page.files_folders
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ context "Frontend Unicode support" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "creates korean page which contains korean content" do
|
test "creates korean page which contains korean content" do
|
||||||
post "/create", :content => '한글 text', :page => "k",
|
post "/gollum/create", :content => '한글 text', :page => "k",
|
||||||
:format => 'markdown', :message => 'def'
|
:format => 'markdown', :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -48,7 +48,7 @@ context "Frontend Unicode support" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "heavy use 1" do
|
test "heavy use 1" do
|
||||||
post "/create", :content => '한글 text', :page => "PG",
|
post "/gollum/create", :content => '한글 text', :page => "PG",
|
||||||
:format => 'markdown', :message => 'def'
|
:format => 'markdown', :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -57,7 +57,7 @@ context "Frontend Unicode support" do
|
|||||||
page = @wiki.page('PG')
|
page = @wiki.page('PG')
|
||||||
assert_equal '다른 text', utf8(page.raw_data)
|
assert_equal '다른 text', utf8(page.raw_data)
|
||||||
|
|
||||||
post '/edit/PG', :page => 'PG', :content => '바뀐 text', :message => 'ghi'
|
post '/gollum/edit/PG', :page => 'PG', :content => '바뀐 text', :message => 'ghi'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ context "Frontend Unicode support" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "heavy use 2" do
|
test "heavy use 2" do
|
||||||
post "/create", :content => '한글 text', :page => "k",
|
post "/gollum/create", :content => '한글 text', :page => "k",
|
||||||
:format => 'markdown', :message => 'def'
|
:format => 'markdown', :message => 'def'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
@@ -78,7 +78,7 @@ context "Frontend Unicode support" do
|
|||||||
page = @wiki.page('k')
|
page = @wiki.page('k')
|
||||||
assert_equal '다른 text', utf8(page.raw_data)
|
assert_equal '다른 text', utf8(page.raw_data)
|
||||||
|
|
||||||
post '/edit/' + CGI.escape('한글'), :page => 'k', :content => '바뀐 text',
|
post '/gollum/edit/' + CGI.escape('한글'), :page => 'k', :content => '바뀐 text',
|
||||||
:format => 'markdown', :message => 'ghi'
|
:format => 'markdown', :message => 'ghi'
|
||||||
follow_redirect!
|
follow_redirect!
|
||||||
assert last_response.ok?
|
assert last_response.ok?
|
||||||
|
|||||||
Reference in New Issue
Block a user