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'
|
||||
gem 'gollum-rjgit_adapter', :git => 'https://github.com/repotag/gollum-lib_rjgit_adapter' # For development purposes
|
||||
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
|
||||
|
||||
source 'https://rubygems.org'
|
||||
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 'kramdown', '~> 1.17.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 'useragent', '~> 0.16.2'
|
||||
s.add_dependency 'gemojione', '~> 3.2'
|
||||
|
||||
+341
-336
@@ -1,6 +1,7 @@
|
||||
# ~*~ encoding: utf-8 ~*~
|
||||
require 'cgi'
|
||||
require 'sinatra'
|
||||
require 'sinatra/namespace'
|
||||
require 'gollum-lib'
|
||||
require 'mustache/sinatra'
|
||||
require 'stringex'
|
||||
@@ -47,11 +48,12 @@ end
|
||||
# }
|
||||
#
|
||||
# See the wiki.rb file for more details on wiki options
|
||||
|
||||
module Precious
|
||||
class App < Sinatra::Base
|
||||
register Mustache::Sinatra
|
||||
register Sinatra::Namespace
|
||||
include Precious::Helpers
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
|
||||
set :sprockets, ::Precious::Assets.sprockets(dir)
|
||||
@@ -97,6 +99,7 @@ module Precious
|
||||
|
||||
Sprockets::Helpers.configure do |config|
|
||||
config.environment = settings.sprockets
|
||||
config.environment.context_class.class_variable_set(:@@base_url, @base_url)
|
||||
config.prefix = "#{@base_url}/#{Precious::Assets::ASSET_URL}"
|
||||
config.digest = @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))
|
||||
end
|
||||
|
||||
get '/assets/*' 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
|
||||
namespace '/gollum' do
|
||||
|
||||
get '/last-commit-info' do
|
||||
content_type :json
|
||||
if page = wiki_page(params[:path]).page
|
||||
version = page.last_version
|
||||
{:author => version.author.name, :date => version.authored_date}.to_json
|
||||
end
|
||||
end
|
||||
|
||||
get '/emoji/:name' do
|
||||
begin
|
||||
[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
|
||||
get '/assets/*' 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
|
||||
|
||||
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
|
||||
get '/last-commit-info' do
|
||||
content_type :json
|
||||
if page = wiki_page(params[:path]).page
|
||||
version = page.last_version
|
||||
{:author => version.author.name, :date => version.authored_date}.to_json
|
||||
end
|
||||
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)
|
||||
get '/emoji/:name' do
|
||||
begin
|
||||
[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
|
||||
|
||||
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
|
||||
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
|
||||
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}")
|
||||
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
|
||||
|
||||
redirect to('/')
|
||||
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 }
|
||||
|
||||
get '/create/*' do
|
||||
forbid unless @allow_editing
|
||||
if settings.wiki_options[:template_page] then
|
||||
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."
|
||||
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
|
||||
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
|
||||
unless page_dir.empty?
|
||||
# --page-file-dir docs
|
||||
# /docs/Home should be created in /Home
|
||||
# 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
|
||||
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
|
||||
mustache :create
|
||||
|
||||
redirect to('/')
|
||||
end
|
||||
end
|
||||
|
||||
post '/create' do
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path]) || ''
|
||||
format = params[:format].intern
|
||||
wiki = wiki_new
|
||||
|
||||
path.gsub!(/^\//, '')
|
||||
|
||||
begin
|
||||
wiki.write_page(name, format, params[:content], commit_message, path)
|
||||
get '/create/*' do
|
||||
forbid unless @allow_editing
|
||||
if settings.wiki_options[:template_page] then
|
||||
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."
|
||||
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
|
||||
redirect to("/#{clean_url(::File.join(encodeURIComponent(page_dir), encodeURIComponent(path), encodeURIComponent(wiki.page_file_name(name, format))))}")
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
mustache :error
|
||||
unless page_dir.empty?
|
||||
# --page-file-dir docs
|
||||
# /docs/Home should be created in /Home
|
||||
# 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
|
||||
|
||||
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]
|
||||
post '/create' do
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path]) || ''
|
||||
format = params[:format].intern
|
||||
wiki = wiki_new
|
||||
|
||||
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."
|
||||
path.gsub!(/^\//, '')
|
||||
|
||||
begin
|
||||
wiki.write_page(name, format, params[:content], commit_message, path)
|
||||
|
||||
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))))}")
|
||||
rescue Gollum::DuplicatePageError => e
|
||||
@message = "Duplicate page: #{e.message}"
|
||||
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
|
||||
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("/")
|
||||
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
|
||||
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]
|
||||
)
|
||||
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
|
||||
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
|
||||
file_path = params[:captures][0]
|
||||
version = params[:captures][1]
|
||||
@@ -468,32 +499,6 @@ module Precious
|
||||
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
|
||||
show_page_or_file(params[:splat].first)
|
||||
end
|
||||
@@ -525,7 +530,7 @@ module Precious
|
||||
else
|
||||
if @allow_editing
|
||||
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
|
||||
@message = "The requested page does not exist."
|
||||
status 404
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Precious
|
||||
module Assets
|
||||
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__)))
|
||||
env = Sprockets::Environment.new
|
||||
@@ -12,6 +12,13 @@ module Precious
|
||||
|
||||
env.js_compressor = :uglify
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,4 +28,4 @@
|
||||
//= require ace-1.3.1/ext-textarea.js
|
||||
//= require ace-1.3.1/ext-themelist.js
|
||||
//= require ace-1.3.1/ext-whitespace.js
|
||||
//= require jquery.resize
|
||||
//= require jquery.resize
|
||||
+1
-1
@@ -209,7 +209,7 @@
|
||||
formData.append('file', file);
|
||||
|
||||
$.ajax({
|
||||
url: baseUrl + '/uploadFile',
|
||||
url: '<%= upload_file_path %>',
|
||||
data: formData,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
+11
-7
@@ -47,7 +47,7 @@ $(document).ready(function() {
|
||||
$('#delete-link').click( function(e) {
|
||||
var ok = confirm($(this).data('confirm'));
|
||||
if ( ok ) {
|
||||
var loc = baseUrl + '/delete/' + pageFullPath;
|
||||
var loc = '<%= delete_path %>/' + pageFullPath;
|
||||
window.location = loc;
|
||||
}
|
||||
// Don't navigate on cancel.
|
||||
@@ -162,7 +162,7 @@ $(document).ready(function() {
|
||||
{
|
||||
type: 'file',
|
||||
context: 'Your uploaded file will be accessible at<br>/'+uploadDest+'/[filename]',
|
||||
action: baseUrl + '/uploadFile'
|
||||
action: '<%= upload_file_path %>'
|
||||
}
|
||||
],
|
||||
OK: function( res ) {
|
||||
@@ -226,10 +226,14 @@ $(document).ready(function() {
|
||||
// In the pages view, pageFullPath isn't defined.
|
||||
// The new button will still expect a value however.
|
||||
// So we try to figure one out from window.location
|
||||
path = baseUrl == '' ? window.location.pathname.substr(1)
|
||||
: window.location.pathname.substr(baseUrl.length + 1);
|
||||
path = window.location.pathname.substr(1)
|
||||
// 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 /
|
||||
path = path.replace(/\/$/,'')
|
||||
}
|
||||
@@ -260,7 +264,7 @@ $(document).ready(function() {
|
||||
for( var i=0; i < name_parts.length; 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 ) {
|
||||
$("#page-info-toggle").click ( function () {
|
||||
$.ajax({
|
||||
url: '/last-commit-info',
|
||||
url: '<%= last_commit_info_path %>',
|
||||
data: {path: $("#page-info-toggle").data('pagepath')},
|
||||
success: function ( data ) {
|
||||
$("#last-edit").html('Last edited by <b>' + data.author + '</b>, ' + data.date);
|
||||
@@ -325,7 +325,7 @@ a {
|
||||
|
||||
@include alt-box-model;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* @control title */
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
{{#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>
|
||||
{{/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>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -25,11 +25,11 @@
|
||||
|
||||
{{#show_revert}}
|
||||
<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>
|
||||
{{#allow_editing}}
|
||||
<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>
|
||||
</form>
|
||||
</li>
|
||||
@@ -53,7 +53,7 @@
|
||||
</div>
|
||||
<div id="footer">
|
||||
<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>
|
||||
{{#show_revert}}
|
||||
{{#allow_editing}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<ul class="actions">
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
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>
|
||||
</ul>
|
||||
</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}}">
|
||||
{{#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_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}}
|
||||
<fieldset id="gollum-editor-fields">
|
||||
{{#is_create_page}}
|
||||
@@ -147,7 +147,7 @@
|
||||
<span class="jaws"><br></span>
|
||||
<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="{{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>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<li class="minibutton"><a href="{{base_url}}/{{escaped_url_path}}"
|
||||
class="action-view-page">View Page</a></li>
|
||||
{{#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>
|
||||
{{/allow_editing}}
|
||||
</ul>
|
||||
@@ -21,7 +21,7 @@
|
||||
</ul>
|
||||
|
||||
<form name="compare-versions" id="version-form" method="post"
|
||||
action="{{base_url}}/compare/{{escaped_url_path}}">
|
||||
action="{{compare_path}}/{{escaped_url_path}}">
|
||||
<fieldset>
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<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}}"/>
|
||||
<span class="username">{{author}}</span>
|
||||
</a>
|
||||
@@ -5,13 +5,13 @@
|
||||
<meta name="MobileOptimized" content="width">
|
||||
<meta name="HandheldFriendly" content="true">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
{{#stylesheet_tag_mustache}}app media: :all{{/stylesheet_tag_mustache}}
|
||||
{{#stylesheet_tag_mustache}}print media: :print{{/stylesheet_tag_mustache}}
|
||||
{{#sprockets_stylesheet_tag}}app{{/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}}
|
||||
{{#noindex}}<meta name="robots" content="noindex, nofollow" />{{/noindex}}
|
||||
|
||||
<!--[if lte IE 8]>
|
||||
{{#stylesheet_tag_mustache}}ie7 media: :all{{/stylesheet_tag_mustache}}
|
||||
{{#sprockets_stylesheet_tag}}ie7{{/sprockets_stylesheet_tag}}
|
||||
<![endif]-->
|
||||
|
||||
<script>
|
||||
@@ -21,9 +21,9 @@
|
||||
var pageFullPath = '{{url_path}}';
|
||||
{{/page}}
|
||||
</script>
|
||||
{{#javascript_tag_mustache}}app{{/javascript_tag_mustache}}
|
||||
{{#sprockets_javascript_tag}}app{{/sprockets_javascript_tag}}
|
||||
{{#use_identicon}}
|
||||
{{#javascript_tag_mustache}}identicon_canvas{{/javascript_tag_mustache}}
|
||||
{{#sprockets_javascript_tag}}identicon_canvas{{/sprockets_javascript_tag}}
|
||||
{{/use_identicon}}
|
||||
{{#mathjax}}
|
||||
{{^mathjax_config}}
|
||||
|
||||
@@ -14,7 +14,7 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
</li>
|
||||
<li class="minibutton"><a href="{{base_url}}/"
|
||||
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>
|
||||
{{#allow_editing}}
|
||||
<li class="minibutton jaws">
|
||||
@@ -34,13 +34,13 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
{{/allow_editing}}
|
||||
{{#allow_editing}}
|
||||
{{#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>
|
||||
{{/editable}}
|
||||
{{/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>
|
||||
<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>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -91,7 +91,7 @@ Mousetrap.bind(['e'], function( e ) {
|
||||
</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="message"/>
|
||||
</form>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<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">
|
||||
<input type="text" name="q" id="search-query" value="Search…" autocomplete="off">
|
||||
<a href="#" id="search-submit" title="Search this wiki">
|
||||
|
||||
+50
-18
@@ -2,31 +2,63 @@ require 'yaml'
|
||||
|
||||
module Precious
|
||||
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
|
||||
def self.included(base)
|
||||
|
||||
def helper_proc_with_options(method)
|
||||
Proc.new do |args|
|
||||
def sprockets_stylesheet_tag
|
||||
lambda do |args|
|
||||
args = args.split(' ')
|
||||
if args.size > 1 then
|
||||
options = args[1..-1].join(' ')
|
||||
options = YAML.safe_load("---\n#{options}\n", [Symbol])
|
||||
end
|
||||
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
|
||||
|
||||
['stylesheet_path','javascript_path', 'image_path'].each do |method|
|
||||
define_method :"#{method}_mustache" do
|
||||
Proc.new {|args| send(method.to_sym, args)}
|
||||
name = args[0]
|
||||
options = {:media => :all}
|
||||
options[:media] = :print if args[1] == 'print'
|
||||
send(:stylesheet_tag, name, options)
|
||||
end
|
||||
end
|
||||
|
||||
['stylesheet_tag','javascript_tag'].each do |method|
|
||||
define_method :"#{method}_mustache" do
|
||||
helper_proc_with_options(method.to_sym)
|
||||
def sprockets_javascript_tag
|
||||
lambda do |name|
|
||||
send(:javascript_tag, name)
|
||||
end
|
||||
end
|
||||
|
||||
def sprockets_image_path
|
||||
lambda do |args|
|
||||
send(:image_path, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,6 +6,8 @@ module Precious
|
||||
include Rack::Utils
|
||||
include Sprockets::Helpers
|
||||
include Precious::Views::SprocketsHelpers
|
||||
include Precious::Views::RouteHelpers
|
||||
|
||||
alias_method :h, :escape_html
|
||||
|
||||
attr_reader :name, :path
|
||||
|
||||
@@ -49,7 +49,7 @@ module Precious
|
||||
# result contains a folder
|
||||
folder = result_path.split('/').first
|
||||
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)
|
||||
elsif result_path != ".gitkeep"
|
||||
|
||||
@@ -17,7 +17,7 @@ context "Precious::Views::Editing" do
|
||||
|
||||
test "creating page is blocked" do
|
||||
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'
|
||||
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 /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"
|
||||
|
||||
get '/history/A'
|
||||
get '/gollum/history/A'
|
||||
|
||||
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 /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 /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"
|
||||
|
||||
get '/history/A'
|
||||
get '/gollum/history/A'
|
||||
|
||||
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 /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, '',
|
||||
{ :name => user1, :email => user1 });
|
||||
|
||||
get "/last-commit-info", :path => page1
|
||||
get "/gollum/last-commit-info", :path => page1
|
||||
assert_match /\"author\":\"user1\"/, last_response.body
|
||||
end
|
||||
|
||||
test "edits page" do
|
||||
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'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -93,7 +93,7 @@ context "Frontend" do
|
||||
|
||||
test "edit page with empty message" do
|
||||
page_1 = @wiki.page('A')
|
||||
post "/edit/A", :content => 'abc', :page => 'A',
|
||||
post "/gollum/edit/A", :content => 'abc', :page => 'A',
|
||||
:format => page_1.format
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -107,7 +107,7 @@ context "Frontend" do
|
||||
|
||||
test "edit page with slash" do
|
||||
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'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -120,7 +120,7 @@ context "Frontend" do
|
||||
foot_1 = page_1.footer
|
||||
side_1 = page_1.sidebar
|
||||
|
||||
post "/edit/A", :header => 'header',
|
||||
post "/gollum/edit/A", :header => 'header',
|
||||
:footer => 'footer', :page => "A", :sidebar => 'sidebar', :message => 'def'
|
||||
follow_redirect!
|
||||
assert_equal "/A.md", last_request.fullpath
|
||||
@@ -147,7 +147,7 @@ context "Frontend" do
|
||||
|
||||
test "renames page" do
|
||||
page_1 = @wiki.page("B")
|
||||
post "/rename/B", :rename => "/C", :message => 'def'
|
||||
post "/gollum/rename/B", :rename => "/C", :message => 'def'
|
||||
|
||||
follow_redirect!
|
||||
assert_equal '/C.md', last_request.fullpath
|
||||
@@ -163,21 +163,21 @@ context "Frontend" do
|
||||
|
||||
test "renames page catches invalid page" do
|
||||
# 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_equal last_response.status, 500
|
||||
end
|
||||
|
||||
test "rename page catches empty target" do
|
||||
# Empty rename target
|
||||
post "/rename/B", :rename => "", :message => 'def'
|
||||
post "/gollum/rename/B", :rename => "", :message => 'def'
|
||||
assert !last_response.ok?
|
||||
assert_equal last_response.status, 500
|
||||
end
|
||||
|
||||
test "rename page catches non-existent target" do
|
||||
# Non-existent rename target
|
||||
post "/rename/B", :message => 'def'
|
||||
post "/gollum/rename/B", :message => 'def'
|
||||
assert !last_response.ok?
|
||||
assert_equal last_response.status, 500
|
||||
end
|
||||
@@ -186,7 +186,7 @@ context "Frontend" do
|
||||
test "renames page in subdirectory" do
|
||||
page_1 = @wiki.paged("H", "G")
|
||||
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!
|
||||
assert_equal '/I/C.md', last_request.fullpath
|
||||
@@ -203,7 +203,7 @@ context "Frontend" do
|
||||
test "renames page relative in subdirectory" do
|
||||
page_1 = @wiki.paged("H", "G")
|
||||
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!
|
||||
assert_equal '/G/K/C.md', last_request.fullpath
|
||||
@@ -219,7 +219,7 @@ context "Frontend" do
|
||||
|
||||
|
||||
test "creates page" do
|
||||
post "/create", :content => 'abc', :page => "D",
|
||||
post "/gollum/create", :content => 'abc', :page => "D",
|
||||
:format => 'markdown', :message => 'def'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -230,7 +230,7 @@ context "Frontend" do
|
||||
end
|
||||
|
||||
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'
|
||||
assert_equal 'http://example.org/Title%20with%20spaces.md', last_response.headers['Location']
|
||||
get "/Title%20with%20spaces"
|
||||
@@ -241,7 +241,7 @@ context "Frontend" do
|
||||
name = "E"
|
||||
get "/#{name}"
|
||||
follow_redirect!
|
||||
assert_equal "/create/#{name}", last_request.fullpath
|
||||
assert_equal "/gollum/create/#{name}", last_request.fullpath
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
@@ -249,12 +249,12 @@ context "Frontend" do
|
||||
get "/foo/"
|
||||
|
||||
follow_redirect!
|
||||
assert_equal "/create/foo/Home", last_request.fullpath
|
||||
assert_equal "/gollum/create/foo/Home", last_request.fullpath
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
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'
|
||||
|
||||
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
|
||||
name = "E"
|
||||
get "/edit/#{name}"
|
||||
get "/gollum/edit/#{name}"
|
||||
follow_redirect!
|
||||
assert_equal "/create/#{name}", last_request.fullpath
|
||||
assert_equal "/gollum/create/#{name}", last_request.fullpath
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
test "create redirects to page if already exists" do
|
||||
name = "A.md"
|
||||
get "/create/#{name}"
|
||||
get "/gollum/create/#{name}"
|
||||
follow_redirect!
|
||||
assert_equal "/#{name}", last_request.fullpath
|
||||
assert last_response.ok?
|
||||
@@ -282,7 +282,7 @@ context "Frontend" do
|
||||
test "create sets the correct path for a relative path subdirectory" do
|
||||
dir = "foodir"
|
||||
name = "#{dir}/bar"
|
||||
get "/create/#{name}"
|
||||
get "/gollum/create/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
end
|
||||
@@ -290,21 +290,21 @@ context "Frontend" do
|
||||
test "create with template succeed if template exists" do
|
||||
Precious::App.set(:wiki_options, { :template_page => true })
|
||||
page='_Template'
|
||||
post '/create', :content => 'fake template', :page => page,
|
||||
post '/gollum/create', :content => 'fake template', :page => page,
|
||||
:path => '/', :format => 'markdown', :message => ''
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
#puts last_response
|
||||
@wiki.clear_cache
|
||||
get "/create/TT"
|
||||
get "/gollum/create/TT"
|
||||
assert last_response.ok?
|
||||
get '/delete/_Template'
|
||||
get '/gollum/delete/_Template'
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
|
||||
test "create with template succeed if template doesn't exist" do
|
||||
Precious::App.set(:wiki_options, { :template_page => true })
|
||||
get "/create/TT"
|
||||
get "/gollum/create/TT"
|
||||
assert last_response.ok?
|
||||
Precious::App.set(:wiki_options, { :template_page => false })
|
||||
end
|
||||
@@ -313,7 +313,7 @@ context "Frontend" do
|
||||
Precious::App.set(:wiki_options, { :page_file_dir => "foo" })
|
||||
dir = "bardir"
|
||||
name = "#{dir}/baz"
|
||||
get "/create/foo/#{name}"
|
||||
get "/gollum/create/foo/#{name}"
|
||||
assert_match(/\/#{dir}/, last_response.body)
|
||||
assert_no_match(/[^\/]#{dir}/, last_response.body)
|
||||
# reset page_file_dir
|
||||
@@ -324,7 +324,7 @@ context "Frontend" do
|
||||
# post '/edit' fails. post '/edit/' works.
|
||||
page = 'not-real-page'
|
||||
path = '/'
|
||||
post '/edit/', :content => 'edit_msg',
|
||||
post '/gollum/edit/', :content => 'edit_msg',
|
||||
:page => page, :path => path, :message => ''
|
||||
page_e = @wiki.paged(page, path)
|
||||
assert_equal nil, page_e
|
||||
@@ -334,7 +334,7 @@ context "Frontend" do
|
||||
page = 'c-d-e'
|
||||
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 => ''
|
||||
page_c = @wiki.paged(page, path)
|
||||
assert_equal 'create_msg', page_c.raw_data
|
||||
@@ -343,7 +343,7 @@ context "Frontend" do
|
||||
@wiki.clear_cache
|
||||
|
||||
# post '/edit' fails. post '/edit/' works.
|
||||
post '/edit/', :content => 'edit_msg',
|
||||
post '/gollum/edit/', :content => 'edit_msg',
|
||||
:page => page, :path => path, :message => ''
|
||||
page_e = @wiki.paged(page, path)
|
||||
assert_equal 'edit_msg', page_e.raw_data
|
||||
@@ -362,7 +362,7 @@ context "Frontend" do
|
||||
|
||||
test "guards against creation of existing page" do
|
||||
name = "A"
|
||||
post "/create", :content => 'abc', :page => name,
|
||||
post "/gollum/create", :content => 'abc', :page => name,
|
||||
:format => 'markdown', :message => 'def'
|
||||
|
||||
assert last_response.ok?
|
||||
@@ -374,12 +374,12 @@ context "Frontend" do
|
||||
|
||||
test "delete a page" do
|
||||
name = "deleteme"
|
||||
post "/create", :content => 'abc', :page => name,
|
||||
post "/gollum/create", :content => 'abc', :page => name,
|
||||
:format => 'markdown', :message => 'foo'
|
||||
page = @wiki.page(name)
|
||||
assert_equal 'abc', page.raw_data
|
||||
|
||||
get '/delete/' + name
|
||||
get '/gollum/delete/' + name
|
||||
|
||||
@wiki.clear_cache
|
||||
page = @wiki.page(name)
|
||||
@@ -387,7 +387,7 @@ context "Frontend" do
|
||||
end
|
||||
|
||||
test "previews content" do
|
||||
post "/preview", :content => 'abc', :format => 'markdown'
|
||||
post "/gollum/preview", :content => 'abc', :format => 'markdown'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
@@ -396,7 +396,7 @@ context "Frontend" do
|
||||
@wiki = Gollum::Wiki.new(@path)
|
||||
Precious::App.set(:gollum_path, @path)
|
||||
Precious::App.set(:wiki_options, {})
|
||||
post "/preview", :content => 'abc', :format => 'markdown'
|
||||
post "/gollum/preview", :content => 'abc', :format => 'markdown'
|
||||
assert last_response.ok?
|
||||
end
|
||||
|
||||
@@ -469,7 +469,7 @@ context "Frontend" do
|
||||
gollum_author = { :name => 'ghi', :email => 'jkl' }
|
||||
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!
|
||||
assert last_response.ok?
|
||||
|
||||
@@ -510,21 +510,21 @@ context "Frontend" do
|
||||
|
||||
['create', 'edit'].each do |route|
|
||||
['.css', '.js'].each do |ext|
|
||||
get "/#{route}/custom#{ext}"
|
||||
assert_equal 403, last_response.status, "get /#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||
get "/gollum/#{route}/custom#{ext}"
|
||||
assert_equal 403, last_response.status, "get /gollum/#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
['deleteFile', 'rename', 'edit', 'create'].each do |route|
|
||||
['.css', '.js'].each do |ext|
|
||||
post "/#{route}/custom#{ext}"
|
||||
assert_equal 403, last_response.status, "post /#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||
post "/gollum/#{route}/custom#{ext}"
|
||||
assert_equal 403, last_response.status, "post /gollum/#{route}/custom#{ext} -- #{last_response.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
['.css', '.js'].each do |ext|
|
||||
post "/revert/custom#{ext}/02796b1450691f90db5d6dc6a816a4980ce80d07/2f6485c2702c7c8b9b6613672337ffa7d933ddcf"
|
||||
assert_equal 403, last_response.status, "post /revert/custom#{ext} -- #{last_response.inspect}"
|
||||
post "/gollum/revert/custom#{ext}/02796b1450691f90db5d6dc6a816a4980ce80d07/2f6485c2702c7c8b9b6613672337ffa7d933ddcf"
|
||||
assert_equal 403, last_response.status, "post /gollum/revert/custom#{ext} -- #{last_response.inspect}"
|
||||
end
|
||||
|
||||
Precious::App.set(:wiki_options, { :js => nil })
|
||||
@@ -544,15 +544,15 @@ context "Frontend" do
|
||||
end
|
||||
|
||||
test "show edit page with header and footer and sidebar of multibyte" do
|
||||
post "/create",
|
||||
post "/gollum/create",
|
||||
:content => 'りんご',
|
||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
||||
|
||||
post "/edit/Multibyte",
|
||||
post "/gollum/edit/Multibyte",
|
||||
:content => 'りんご', :header => 'みかん', :footer => 'バナナ', :sidebar => 'スイカ',
|
||||
:page => 'Multibyte', :format => :markdown, :message => 'mesg'
|
||||
|
||||
get "edit/Multibyte"
|
||||
get "/gollum/edit/Multibyte"
|
||||
|
||||
assert last_response.ok?
|
||||
assert_match /りんご/, last_response.body
|
||||
@@ -620,7 +620,7 @@ context "Frontend with lotr" do
|
||||
#
|
||||
|
||||
test "/pages" do
|
||||
get "/pages"
|
||||
get "/gollum/pages"
|
||||
assert last_response.ok?
|
||||
|
||||
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"
|
||||
end
|
||||
|
||||
test "/pages/Mordor/" do
|
||||
get "/pages/Mordor/"
|
||||
test "/gollum/pages/Mordor/" do
|
||||
get "/gollum/pages/Mordor/"
|
||||
assert last_response.ok?, "/pages/Mordor/ did not respond ok"
|
||||
|
||||
body = last_response.body
|
||||
@@ -658,7 +658,7 @@ context "Frontend with lotr" do
|
||||
test "create pages within sub-directories using base path" do
|
||||
Precious::App.set(:wiki_options, { :base_path => 'wiki' })
|
||||
page = 'path'
|
||||
post "/create", :content => '123', :page => page,
|
||||
post "/gollum/create", :content => '123', :page => page,
|
||||
:path => 'Mordor', :format => 'markdown', :message => 'oooh, scary'
|
||||
# should be wiki/Mordor/path
|
||||
assert_equal 'http://example.org/Mordor/' + page + '.md', last_response.headers['Location']
|
||||
@@ -670,7 +670,7 @@ context "Frontend with lotr" do
|
||||
end
|
||||
|
||||
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'
|
||||
assert_equal 'http://example.org/wiki/Mordor/base.md', last_response.headers['Location']
|
||||
get "/wiki/Mordor/base"
|
||||
@@ -680,13 +680,13 @@ context "Frontend with lotr" 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'
|
||||
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||
get "/Mordor/Orc"
|
||||
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'
|
||||
assert_equal 'http://example.org/Mordor/Uruk%20Hai.md', last_response.headers['Location']
|
||||
get "/Mordor/Uruk%20Hai"
|
||||
@@ -694,12 +694,12 @@ context "Frontend with lotr" do
|
||||
end
|
||||
|
||||
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'
|
||||
|
||||
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'
|
||||
assert_equal 'http://example.org/Mordor/Orc.md', last_response.headers['Location']
|
||||
|
||||
@@ -721,14 +721,14 @@ context "Frontend with lotr" do
|
||||
end
|
||||
|
||||
test "existing emoji" do
|
||||
get "/emoji/heart"
|
||||
get "/gollum/emoji/heart"
|
||||
assert_equal 200, last_response.status
|
||||
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]
|
||||
end
|
||||
|
||||
test "missing emoji" do
|
||||
get "/emoji/oggy_was_here"
|
||||
get "/gollum/emoji/oggy_was_here"
|
||||
assert_equal 404, last_response.status
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ context "Precious::Views::LatestChanges" do
|
||||
end
|
||||
|
||||
test "displays_latest_changes" do
|
||||
get('/latest_changes')
|
||||
get('/gollum/latest_changes')
|
||||
body = last_response.body
|
||||
|
||||
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", "")
|
||||
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)
|
||||
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
|
||||
|
||||
test "files_folders from subdir" do
|
||||
@@ -54,7 +54,7 @@ context "Precious::Views::Pages" do
|
||||
@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")]
|
||||
@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
|
||||
|
||||
test "base url" do
|
||||
@@ -63,6 +63,6 @@ context "Precious::Views::Pages" do
|
||||
@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")]
|
||||
@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
|
||||
|
||||
@@ -37,7 +37,7 @@ context "Frontend Unicode support" do
|
||||
end
|
||||
|
||||
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'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -48,7 +48,7 @@ context "Frontend Unicode support" do
|
||||
end
|
||||
|
||||
test "heavy use 1" do
|
||||
post "/create", :content => '한글 text', :page => "PG",
|
||||
post "/gollum/create", :content => '한글 text', :page => "PG",
|
||||
:format => 'markdown', :message => 'def'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -57,7 +57,7 @@ context "Frontend Unicode support" do
|
||||
page = @wiki.page('PG')
|
||||
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!
|
||||
assert last_response.ok?
|
||||
|
||||
@@ -68,7 +68,7 @@ context "Frontend Unicode support" do
|
||||
end
|
||||
|
||||
test "heavy use 2" do
|
||||
post "/create", :content => '한글 text', :page => "k",
|
||||
post "/gollum/create", :content => '한글 text', :page => "k",
|
||||
:format => 'markdown', :message => 'def'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
@@ -78,7 +78,7 @@ context "Frontend Unicode support" do
|
||||
page = @wiki.page('k')
|
||||
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'
|
||||
follow_redirect!
|
||||
assert last_response.ok?
|
||||
|
||||
Reference in New Issue
Block a user