Format code
This commit is contained in:
+11
-9
@@ -17,10 +17,10 @@ require 'optparse'
|
||||
require 'rubygems'
|
||||
require 'gollum'
|
||||
|
||||
exec = {}
|
||||
options = { 'port' => 4567, 'bind' => '0.0.0.0' }
|
||||
exec = {}
|
||||
options = { 'port' => 4567, 'bind' => '0.0.0.0' }
|
||||
wiki_options = {
|
||||
:live_preview => false,
|
||||
:live_preview => false,
|
||||
:allow_uploads => false,
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ opts = OptionParser.new do |opts|
|
||||
end
|
||||
|
||||
opts.on("--allow-uploads [MODE]", [:dir, :page], "Allows file uploads. Modes: dir (default, store all uploads in the same directory), page (store each upload at the same location as the page).") do |mode|
|
||||
wiki_options[:allow_uploads] = true
|
||||
wiki_options[:allow_uploads] = true
|
||||
wiki_options[:per_page_uploads] = true if mode == :page
|
||||
end
|
||||
|
||||
@@ -120,8 +120,8 @@ end
|
||||
|
||||
# --gollum-path wins over ARGV[0]
|
||||
gollum_path = wiki_options[:gollum_path] ?
|
||||
wiki_options[:gollum_path] :
|
||||
ARGV[0] || Dir.pwd
|
||||
wiki_options[:gollum_path] :
|
||||
ARGV[0] || Dir.pwd
|
||||
|
||||
if options['irb']
|
||||
require 'irb'
|
||||
@@ -151,7 +151,9 @@ if options['irb']
|
||||
begin
|
||||
require 'gollum-lib'
|
||||
wiki = Gollum::Wiki.new(gollum_path, wiki_options)
|
||||
if !wiki.exist? then raise Gollum::InvalidGitRepositoryError end
|
||||
if !wiki.exist? then
|
||||
raise Gollum::InvalidGitRepositoryError
|
||||
end
|
||||
puts "Loaded Gollum wiki at #{File.expand_path(gollum_path).inspect}."
|
||||
puts
|
||||
puts %( page = wiki.page('page-name'))
|
||||
@@ -193,7 +195,7 @@ else
|
||||
def initialize base_path
|
||||
@mg = Rack::Builder.new do
|
||||
map '/' do
|
||||
run Proc.new { [ 302, {'Location'=> "/#{base_path}" }, [] ] }
|
||||
run Proc.new { [302, { 'Location' => "/#{base_path}" }, []] }
|
||||
end
|
||||
|
||||
map "/#{base_path}" do
|
||||
@@ -209,4 +211,4 @@ else
|
||||
# Rack::Handler does not work with Ctrl + C. Use Rack::Server instead.
|
||||
Rack::Server.new(:app => MapGollum.new(base_path), :Port => options['port'], :Host => options['bind']).start
|
||||
end
|
||||
end
|
||||
end
|
||||
+3
-2
@@ -13,7 +13,7 @@ require File.expand_path('../gollum/uri_encode_component', __FILE__)
|
||||
|
||||
# Set ruby to UTF-8 mode
|
||||
# This is required for Ruby 1.8.7 which gollum still supports.
|
||||
$KCODE = 'U' if RUBY_VERSION[0,3] == '1.8'
|
||||
$KCODE = 'U' if RUBY_VERSION[0, 3] == '1.8'
|
||||
|
||||
module Gollum
|
||||
VERSION = '3.0.0'
|
||||
@@ -22,7 +22,8 @@ module Gollum
|
||||
::File.expand_path('gollum/public', ::File.dirname(__FILE__))
|
||||
end
|
||||
|
||||
class Error < StandardError; end
|
||||
class Error < StandardError;
|
||||
end
|
||||
|
||||
class DuplicatePageError < Error
|
||||
attr_accessor :dir
|
||||
|
||||
+100
-100
@@ -43,7 +43,7 @@ module Precious
|
||||
register Mustache::Sinatra
|
||||
include Precious::Helpers
|
||||
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
dir = File.dirname(File.expand_path(__FILE__))
|
||||
|
||||
# Detect unsupported browsers.
|
||||
Browser = Struct.new(:browser, :version)
|
||||
@@ -56,23 +56,23 @@ module Precious
|
||||
|
||||
def supported_useragent?(user_agent)
|
||||
ua = UserAgent.parse(user_agent)
|
||||
@@min_ua.detect {|min| ua >= min }
|
||||
@@min_ua.detect { |min| ua >= min }
|
||||
end
|
||||
|
||||
# We want to serve public assets for now
|
||||
set :public_folder, "#{dir}/public/gollum"
|
||||
set :static, true
|
||||
set :static, true
|
||||
set :default_markup, :markdown
|
||||
|
||||
set :mustache, {
|
||||
# Tell mustache where the Views constant lives
|
||||
:namespace => Precious,
|
||||
# Tell mustache where the Views constant lives
|
||||
:namespace => Precious,
|
||||
|
||||
# Mustache templates live here
|
||||
:templates => "#{dir}/templates",
|
||||
# Mustache templates live here
|
||||
:templates => "#{dir}/templates",
|
||||
|
||||
# Tell mustache where the views are
|
||||
:views => "#{dir}/views"
|
||||
# Tell mustache where the views are
|
||||
:views => "#{dir}/views"
|
||||
}
|
||||
|
||||
# Sinatra error handling
|
||||
@@ -90,7 +90,7 @@ module Precious
|
||||
# above will detect base_path when it's used with map in a config.ru
|
||||
settings.wiki_options.merge!({ :base_path => @base_url })
|
||||
@css = settings.wiki_options[:css]
|
||||
@js = settings.wiki_options[:js]
|
||||
@js = settings.wiki_options[:js]
|
||||
end
|
||||
|
||||
get '/' do
|
||||
@@ -139,9 +139,9 @@ module Precious
|
||||
end
|
||||
redirect to(live_preview_url)
|
||||
else
|
||||
@page = page
|
||||
@page = page
|
||||
@page.version = wiki.repo.log(wiki.ref, @page.path).first
|
||||
@content = page.text_data
|
||||
@content = page.text_data
|
||||
mustache :edit
|
||||
end
|
||||
else
|
||||
@@ -163,9 +163,9 @@ module Precious
|
||||
tempfile = params[:file][:tempfile]
|
||||
end
|
||||
|
||||
dir = wiki.per_page_uploads ? params[:upload_dest] : 'uploads'
|
||||
ext = ::File.extname(fullname)
|
||||
format = ext.split('.').last || 'txt'
|
||||
dir = wiki.per_page_uploads ? params[:upload_dest] : 'uploads'
|
||||
ext = ::File.extname(fullname)
|
||||
format = ext.split('.').last || 'txt'
|
||||
filename = ::File.basename(fullname, ext)
|
||||
contents = ::File.read(tempfile)
|
||||
reponame = filename + '.' + format
|
||||
@@ -173,10 +173,10 @@ module Precious
|
||||
head = wiki.repo.head
|
||||
|
||||
options = {
|
||||
:message => "Uploaded file to #{dir}/#{reponame}",
|
||||
:parent => wiki.repo.head.commit,
|
||||
:message => "Uploaded file to #{dir}/#{reponame}",
|
||||
:parent => wiki.repo.head.commit,
|
||||
}
|
||||
author = session['gollum.author']
|
||||
author = session['gollum.author']
|
||||
unless author.nil?
|
||||
options.merge! author
|
||||
end
|
||||
@@ -197,37 +197,37 @@ module Precious
|
||||
end
|
||||
|
||||
post '/rename/*' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
halt 500 if wikip.nil?
|
||||
wiki = wikip.wiki
|
||||
page = wiki.paged(wikip.name, wikip.path, exact = true)
|
||||
rename = params[:rename]
|
||||
wiki = wikip.wiki
|
||||
page = wiki.paged(wikip.name, 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 == '.'
|
||||
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}"
|
||||
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}
|
||||
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
|
||||
# This occurs on NOOPs, for example renaming A => A
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
return
|
||||
end
|
||||
committer.commit
|
||||
|
||||
wikip = wiki_page(rename)
|
||||
page = wiki.paged(wikip.name, wikip.path, exact = true)
|
||||
page = wiki.paged(wikip.name, wikip.path, exact = true)
|
||||
return if page.nil?
|
||||
redirect to("/#{page.escaped_url_path}")
|
||||
end
|
||||
@@ -239,11 +239,11 @@ module Precious
|
||||
page = wiki.paged(page_name, path, exact = true)
|
||||
return if page.nil?
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = {:committer => committer}
|
||||
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.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
|
||||
|
||||
@@ -252,9 +252,9 @@ module Precious
|
||||
|
||||
get '/delete/*' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
page = wikip.page
|
||||
unless page.nil?
|
||||
wiki.delete_page(page, { :message => "Destroyed #{name} (#{page.format})" })
|
||||
end
|
||||
@@ -286,10 +286,10 @@ module Precious
|
||||
end
|
||||
|
||||
post '/create' do
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path]) || ''
|
||||
format = params[:format].intern
|
||||
wiki = wiki_new
|
||||
name = params[:page].to_url
|
||||
path = sanitize_empty_params(params[:path]) || ''
|
||||
format = params[:format].intern
|
||||
wiki = wiki_new
|
||||
|
||||
path.gsub!(/^\//, '')
|
||||
|
||||
@@ -305,15 +305,15 @@ module Precious
|
||||
end
|
||||
|
||||
post '/revert/*/:sha1/:sha2' do
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
@page = wiki.paged(@name,@path)
|
||||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
wikip = wiki_page(params[:splat].first)
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
@page = wiki.paged(@name, @path)
|
||||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
|
||||
commit = commit_message
|
||||
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}")
|
||||
@@ -328,23 +328,23 @@ module Precious
|
||||
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
|
||||
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
|
||||
@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
|
||||
@page = wiki_page(params[:splat].first).page
|
||||
@page_num = [params[:page].to_i, 1].max
|
||||
unless @page.nil?
|
||||
@versions = @page.versions :page => @page_num
|
||||
@versions = @page.versions :page => @page_num
|
||||
mustache :history
|
||||
else
|
||||
redirect to("/")
|
||||
@@ -358,10 +358,10 @@ module Precious
|
||||
redirect to("/history/#{@file}")
|
||||
else
|
||||
redirect to("/compare/%s/%s...%s" % [
|
||||
@file,
|
||||
@versions.last,
|
||||
@versions.first]
|
||||
)
|
||||
@file,
|
||||
@versions.last,
|
||||
@versions.first]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -373,14 +373,14 @@ module Precious
|
||||
\.{2,3} # match .. or ...
|
||||
(.+) # match the second SHA1
|
||||
}x do |path, start_version, end_version|
|
||||
wikip = wiki_page(path)
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
@versions = [start_version, end_version]
|
||||
wiki = wikip.wiki
|
||||
@page = wikip.page
|
||||
diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path)
|
||||
@diff = diffs.first
|
||||
wikip = wiki_page(path)
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
@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
|
||||
|
||||
@@ -391,8 +391,8 @@ module Precious
|
||||
name = wikip.name
|
||||
path = wikip.path
|
||||
if page = wikip.page
|
||||
@page = page
|
||||
@name = name
|
||||
@page = page
|
||||
@name = name
|
||||
@content = page.formatted_data
|
||||
@version = version
|
||||
mustache :page
|
||||
@@ -402,11 +402,11 @@ module Precious
|
||||
end
|
||||
|
||||
get '/search' do
|
||||
@query = params[:q]
|
||||
wiki = wiki_new
|
||||
@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
|
||||
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
||||
@name = @query
|
||||
mustache :search
|
||||
end
|
||||
|
||||
@@ -426,16 +426,16 @@ module Precious
|
||||
end
|
||||
|
||||
get '/fileview' do
|
||||
wiki = wiki_new
|
||||
options = settings.wiki_options
|
||||
content = wiki.pages
|
||||
wiki = wiki_new
|
||||
options = settings.wiki_options
|
||||
content = wiki.pages
|
||||
# if showing all files include wiki.files
|
||||
content += wiki.files if options[:show_all]
|
||||
content += wiki.files if options[:show_all]
|
||||
|
||||
# must pass wiki_options to FileView
|
||||
# --show-all and --collapse-tree can be set.
|
||||
@results = Gollum::FileView.new(content, options).render_files
|
||||
@ref = wiki.ref
|
||||
@ref = wiki.ref
|
||||
mustache :file_view, { :layout => false }
|
||||
end
|
||||
|
||||
@@ -450,21 +450,21 @@ module Precious
|
||||
path = extract_path(fullpath) || '/'
|
||||
|
||||
if page = wiki.paged(name, path, exact = true)
|
||||
@page = page
|
||||
@name = name
|
||||
@content = page.formatted_data
|
||||
@upload_dest = settings.wiki_options[:allow_uploads] ?
|
||||
(settings.wiki_options[:per_page_uploads] ?
|
||||
"#{path}/#{@name}".sub(/^\/\//, '') : 'uploads'
|
||||
) : ''
|
||||
@page = page
|
||||
@name = name
|
||||
@content = page.formatted_data
|
||||
@upload_dest = settings.wiki_options[:allow_uploads] ?
|
||||
(settings.wiki_options[:per_page_uploads] ?
|
||||
"#{path}/#{@name}".sub(/^\/\//, '') : 'uploads'
|
||||
) : ''
|
||||
|
||||
# Extensions and layout data
|
||||
@editable = true
|
||||
@page_exists = !page.versions.empty?
|
||||
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
||||
@mathjax = wiki.mathjax
|
||||
@h1_title = wiki.h1_title
|
||||
@bar_side = wiki.bar_side
|
||||
@editable = true
|
||||
@page_exists = !page.versions.empty?
|
||||
@toc_content = wiki.universal_toc ? @page.toc_data : nil
|
||||
@mathjax = wiki.mathjax
|
||||
@h1_title = wiki.h1_title
|
||||
@bar_side = wiki.bar_side
|
||||
@allow_uploads = wiki.allow_uploads
|
||||
|
||||
mustache :page
|
||||
@@ -483,9 +483,9 @@ module Precious
|
||||
|
||||
def update_wiki_page(wiki, page, content, commit, name = nil, format = nil)
|
||||
return if !page ||
|
||||
((!content || page.raw_data == content) && page.format == format)
|
||||
((!content || page.raw_data == content) && page.format == format)
|
||||
name ||= page.name
|
||||
format = (format || page.format).to_sym
|
||||
format = (format || page.format).to_sym
|
||||
content ||= page.raw_data
|
||||
wiki.update_page(page, name, format, content.to_s, commit)
|
||||
end
|
||||
@@ -499,8 +499,8 @@ module Precious
|
||||
# message is sourced from the incoming request parameters
|
||||
# author details are sourced from the session, to be populated by rack middleware ahead of us
|
||||
def commit_message
|
||||
msg = (params[:message].nil? or params[:message].empty?) ? "[no message]" : params[:message]
|
||||
commit_message = { :message => msg }
|
||||
msg = (params[:message].nil? or params[:message].empty?) ? "[no message]" : params[:message]
|
||||
commit_message = { :message => msg }
|
||||
author_parameters = session['gollum.author']
|
||||
commit_message.merge! author_parameters unless author_parameters.nil?
|
||||
commit_message
|
||||
|
||||
@@ -22,13 +22,13 @@ module Precious
|
||||
end
|
||||
|
||||
def sanitize_empty_params(param)
|
||||
[nil,''].include?(param) ? nil : CGI.unescape(param)
|
||||
[nil, ''].include?(param) ? nil : CGI.unescape(param)
|
||||
end
|
||||
|
||||
# Ensure path begins with a single leading slash
|
||||
def clean_path(path)
|
||||
if path
|
||||
(path[0] != '/' ? path.insert(0, '/') : path).gsub(/\/{2,}/,'/')
|
||||
(path[0] != '/' ? path.insert(0, '/') : path).gsub(/\/{2,}/, '/')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ module Precious
|
||||
# Remove all double slashes
|
||||
def clean_url url
|
||||
return url if url.nil?
|
||||
url.gsub('%2F','/').gsub(/^\/+/,'').gsub('//','/')
|
||||
url.gsub('%2F', '/').gsub(/^\/+/, '').gsub('//', '/')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
+142
-110
@@ -49,132 +49,164 @@ class String
|
||||
end
|
||||
end
|
||||
|
||||
module URI; class << self
|
||||
module URI
|
||||
;
|
||||
class << self
|
||||
# Does the char code correspond to an alpha-numeric char.
|
||||
# isAlphaNumeric('a'.ord) => true
|
||||
# isAlphaNumeric(''.ord) => false
|
||||
def isAlphaNumeric(cc)
|
||||
# a - z
|
||||
if (97 <= cc && cc <= 122); return true end
|
||||
# A - Z
|
||||
if (65 <= cc && cc <= 90); return true end
|
||||
# 0 - 9
|
||||
if (48 <= cc && cc <= 57); return true end
|
||||
def isAlphaNumeric(cc)
|
||||
# a - z
|
||||
if (97 <= cc && cc <= 122);
|
||||
return true
|
||||
end
|
||||
# A - Z
|
||||
if (65 <= cc && cc <= 90);
|
||||
return true
|
||||
end
|
||||
# 0 - 9
|
||||
if (48 <= cc && cc <= 57);
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def unescapePredicate(cc)
|
||||
if (isAlphaNumeric(cc)); return true end
|
||||
# !
|
||||
if (cc == 33); return true end
|
||||
# '()*
|
||||
if (39 <= cc && cc <= 42); return true end
|
||||
# -.
|
||||
if (45 <= cc && cc <= 46); return true end
|
||||
# _
|
||||
if (cc == 95); return true end
|
||||
# ~
|
||||
if (cc == 126); return true end
|
||||
def unescapePredicate(cc)
|
||||
if (isAlphaNumeric(cc));
|
||||
return true
|
||||
end
|
||||
# !
|
||||
if (cc == 33);
|
||||
return true
|
||||
end
|
||||
# '()*
|
||||
if (39 <= cc && cc <= 42);
|
||||
return true
|
||||
end
|
||||
# -.
|
||||
if (45 <= cc && cc <= 46);
|
||||
return true
|
||||
end
|
||||
# _
|
||||
if (cc == 95);
|
||||
return true
|
||||
end
|
||||
# ~
|
||||
if (cc == 126);
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def URIEncodeSingle(cc, result, index)
|
||||
x = (cc >> 12) & 0xF;
|
||||
y = (cc >> 6) & 63;
|
||||
z = cc & 63;
|
||||
octets = Array.new(3);
|
||||
if (cc <= 0x007F)
|
||||
octets[0] = cc;
|
||||
elsif (cc <= 0x07FF)
|
||||
octets[0] = y + 192;
|
||||
octets[1] = z + 128;
|
||||
else
|
||||
octets[0] = x + 224;
|
||||
octets[1] = y + 128;
|
||||
octets[2] = z + 128;
|
||||
end
|
||||
return URIEncodeOctets(octets, result, index);
|
||||
end
|
||||
def URIEncodeSingle(cc, result, index)
|
||||
x = (cc >> 12) & 0xF;
|
||||
y = (cc >> 6) & 63;
|
||||
z = cc & 63;
|
||||
octets = Array.new(3);
|
||||
if (cc <= 0x007F)
|
||||
octets[0] = cc;
|
||||
elsif (cc <= 0x07FF)
|
||||
octets[0] = y + 192;
|
||||
octets[1] = z + 128;
|
||||
else
|
||||
octets[0] = x + 224;
|
||||
octets[1] = y + 128;
|
||||
octets[2] = z + 128;
|
||||
end
|
||||
return URIEncodeOctets(octets, result, index);
|
||||
end
|
||||
|
||||
# Lazily initialized.
|
||||
@@hexCharCodeArray = 0;
|
||||
@@hexCharCodeArray = 0;
|
||||
|
||||
def URIAddEncodedOctetToBuffer(octet, result, index)
|
||||
result[index] = 37; # Char code of '%'.
|
||||
index += 1
|
||||
result[index] = @@hexCharCodeArray[octet >> 4];
|
||||
index += 1
|
||||
result[index] = @@hexCharCodeArray[octet & 0x0F];
|
||||
index += 1
|
||||
return index;
|
||||
end
|
||||
def URIAddEncodedOctetToBuffer(octet, result, index)
|
||||
result[index] = 37; # Char code of '%'.
|
||||
index += 1
|
||||
result[index] = @@hexCharCodeArray[octet >> 4];
|
||||
index += 1
|
||||
result[index] = @@hexCharCodeArray[octet & 0x0F];
|
||||
index += 1
|
||||
return index;
|
||||
end
|
||||
|
||||
def URIEncodeOctets(octets, result, index)
|
||||
if (@@hexCharCodeArray == 0)
|
||||
@@hexCharCodeArray = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
65, 66, 67, 68, 69, 70];
|
||||
end
|
||||
index = URIAddEncodedOctetToBuffer(octets[0], result, index);
|
||||
if (octets[1]); index = URIAddEncodedOctetToBuffer(octets[1], result, index) end
|
||||
if (octets[2]); index = URIAddEncodedOctetToBuffer(octets[2], result, index) end
|
||||
if (octets[3]); index = URIAddEncodedOctetToBuffer(octets[3], result, index) end
|
||||
return index;
|
||||
end
|
||||
def URIEncodeOctets(octets, result, index)
|
||||
if (@@hexCharCodeArray == 0)
|
||||
@@hexCharCodeArray = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
|
||||
65, 66, 67, 68, 69, 70];
|
||||
end
|
||||
index = URIAddEncodedOctetToBuffer(octets[0], result, index);
|
||||
if (octets[1]);
|
||||
index = URIAddEncodedOctetToBuffer(octets[1], result, index)
|
||||
end
|
||||
if (octets[2]);
|
||||
index = URIAddEncodedOctetToBuffer(octets[2], result, index)
|
||||
end
|
||||
if (octets[3]);
|
||||
index = URIAddEncodedOctetToBuffer(octets[3], result, index)
|
||||
end
|
||||
return index;
|
||||
end
|
||||
|
||||
def URIEncodePair(cc1 , cc2, result, index)
|
||||
u = ((cc1 >> 6) & 0xF) + 1;
|
||||
w = (cc1 >> 2) & 0xF;
|
||||
x = cc1 & 3;
|
||||
y = (cc2 >> 6) & 0xF;
|
||||
z = cc2 & 63;
|
||||
octets = Array.new(4);
|
||||
octets[0] = (u >> 2) + 240;
|
||||
octets[1] = (((u & 3) << 4) | w) + 128;
|
||||
octets[2] = ((x << 4) | y) + 128;
|
||||
octets[3] = z + 128;
|
||||
return URIEncodeOctets(octets, result, index);
|
||||
end
|
||||
def URIEncodePair(cc1, cc2, result, index)
|
||||
u = ((cc1 >> 6) & 0xF) + 1;
|
||||
w = (cc1 >> 2) & 0xF;
|
||||
x = cc1 & 3;
|
||||
y = (cc2 >> 6) & 0xF;
|
||||
z = cc2 & 63;
|
||||
octets = Array.new(4);
|
||||
octets[0] = (u >> 2) + 240;
|
||||
octets[1] = (((u & 3) << 4) | w) + 128;
|
||||
octets[2] = ((x << 4) | y) + 128;
|
||||
octets[3] = z + 128;
|
||||
return URIEncodeOctets(octets, result, index);
|
||||
end
|
||||
|
||||
# component must be String
|
||||
def URIEncodeComponent(componentString)
|
||||
Encode(componentString, :unescapePredicate);
|
||||
end
|
||||
def URIEncodeComponent(componentString)
|
||||
Encode(componentString, :unescapePredicate);
|
||||
end
|
||||
|
||||
# ECMA-262, section 15.1.3
|
||||
def Encode(uri, unescape)
|
||||
uriLength = uri.length;
|
||||
# We are going to pass result to %StringFromCharCodeArray
|
||||
# which does not expect any getters/setters installed
|
||||
# on the incoming array.
|
||||
result = Array.new(uriLength);
|
||||
index = 0;
|
||||
k = -1;
|
||||
while ((k+=1) < uriLength) do
|
||||
cc1 = uri.charCodeAt(k);
|
||||
next if cc1.nil?
|
||||
if (self.send(unescape, cc1))
|
||||
result[index] = cc1;
|
||||
index += 1
|
||||
else
|
||||
if (cc1 >= 0xDC00 && cc1 <= 0xDFFF); throw("URI malformed") end
|
||||
if (cc1 < 0xD800 || cc1 > 0xDBFF)
|
||||
index = URIEncodeSingle(cc1, result, index);
|
||||
else
|
||||
k+=1;
|
||||
if (k == uriLength); throw("URI malformed") end
|
||||
cc2 = uri.charCodeAt(k);
|
||||
if (cc2 < 0xDC00 || cc2 > 0xDFFF); throw("URI malformed") end
|
||||
index = URIEncodePair(cc1, cc2, result, index);
|
||||
def Encode(uri, unescape)
|
||||
uriLength = uri.length;
|
||||
# We are going to pass result to %StringFromCharCodeArray
|
||||
# which does not expect any getters/setters installed
|
||||
# on the incoming array.
|
||||
result = Array.new(uriLength);
|
||||
index = 0;
|
||||
k = -1;
|
||||
while ((k+=1) < uriLength) do
|
||||
cc1 = uri.charCodeAt(k);
|
||||
next if cc1.nil?
|
||||
if (self.send(unescape, cc1))
|
||||
result[index] = cc1;
|
||||
index += 1
|
||||
else
|
||||
if (cc1 >= 0xDC00 && cc1 <= 0xDFFF);
|
||||
throw("URI malformed")
|
||||
end
|
||||
if (cc1 < 0xD800 || cc1 > 0xDBFF)
|
||||
index = URIEncodeSingle(cc1, result, index);
|
||||
else
|
||||
k+=1;
|
||||
if (k == uriLength);
|
||||
throw("URI malformed")
|
||||
end
|
||||
cc2 = uri.charCodeAt(k);
|
||||
if (cc2 < 0xDC00 || cc2 > 0xDFFF);
|
||||
throw("URI malformed")
|
||||
end
|
||||
index = URIEncodePair(cc1, cc2, result, index);
|
||||
end
|
||||
end
|
||||
end
|
||||
# use .compact to get rid of nils from charCodeAt
|
||||
# return %StringFromCharCodeArray(result);
|
||||
# 'c' = 8 bit signed char
|
||||
# http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-pack
|
||||
return result.compact.pack 'c*'
|
||||
end
|
||||
end
|
||||
# use .compact to get rid of nils from charCodeAt
|
||||
# return %StringFromCharCodeArray(result);
|
||||
# 'c' = 8 bit signed char
|
||||
# http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-pack
|
||||
return result.compact.pack 'c*'
|
||||
end
|
||||
end # class << self
|
||||
end # class << self
|
||||
end # module
|
||||
|
||||
+16
-14
@@ -47,43 +47,45 @@ module Precious
|
||||
end
|
||||
|
||||
@left_diff_line_number = nil
|
||||
|
||||
def left_diff_line_number(id, line)
|
||||
if line =~ /^@@/
|
||||
m, li = *line.match(/\-(\d+)/)
|
||||
m, li = *line.match(/\-(\d+)/)
|
||||
@left_diff_line_number = li.to_i
|
||||
@current_line_number = @left_diff_line_number
|
||||
ret = '...'
|
||||
@current_line_number = @left_diff_line_number
|
||||
ret = '...'
|
||||
elsif line[0] == ?-
|
||||
ret = @left_diff_line_number.to_s
|
||||
ret = @left_diff_line_number.to_s
|
||||
@left_diff_line_number += 1
|
||||
@current_line_number = @left_diff_line_number - 1
|
||||
@current_line_number = @left_diff_line_number - 1
|
||||
elsif line[0] == ?+
|
||||
ret = ' '
|
||||
else
|
||||
ret = @left_diff_line_number.to_s
|
||||
ret = @left_diff_line_number.to_s
|
||||
@left_diff_line_number += 1
|
||||
@current_line_number = @left_diff_line_number - 1
|
||||
@current_line_number = @left_diff_line_number - 1
|
||||
end
|
||||
ret
|
||||
end
|
||||
|
||||
@right_diff_line_number = nil
|
||||
|
||||
def right_diff_line_number(id, line)
|
||||
if line =~ /^@@/
|
||||
m, ri = *line.match(/\+(\d+)/)
|
||||
m, ri = *line.match(/\+(\d+)/)
|
||||
@right_diff_line_number = ri.to_i
|
||||
@current_line_number = @right_diff_line_number
|
||||
ret = '...'
|
||||
@current_line_number = @right_diff_line_number
|
||||
ret = '...'
|
||||
elsif line[0] == ?-
|
||||
ret = ' '
|
||||
elsif line[0] == ?+
|
||||
ret = @right_diff_line_number.to_s
|
||||
ret = @right_diff_line_number.to_s
|
||||
@right_diff_line_number += 1
|
||||
@current_line_number = @right_diff_line_number - 1
|
||||
@current_line_number = @right_diff_line_number - 1
|
||||
else
|
||||
ret = @right_diff_line_number.to_s
|
||||
ret = @right_diff_line_number.to_s
|
||||
@right_diff_line_number += 1
|
||||
@current_line_number = @right_diff_line_number - 1
|
||||
@current_line_number = @right_diff_line_number - 1
|
||||
end
|
||||
ret
|
||||
end
|
||||
|
||||
@@ -6,10 +6,10 @@ module Precious
|
||||
|
||||
attr_reader :page, :content
|
||||
|
||||
# return path set in app.rb not @page.path
|
||||
def path
|
||||
@path
|
||||
end
|
||||
# return path set in app.rb not @page.path
|
||||
def path
|
||||
@path
|
||||
end
|
||||
|
||||
def title
|
||||
"#{@page.title}"
|
||||
|
||||
@@ -4,7 +4,7 @@ module Precious
|
||||
Gollum::Markup.formats.map do |key, val|
|
||||
{ :name => val[:name],
|
||||
:id => key.to_s,
|
||||
:selected => selected == key}
|
||||
:selected => selected == key }
|
||||
end.sort do |a, b|
|
||||
a[:name].downcase <=> b[:name].downcase
|
||||
end
|
||||
|
||||
@@ -10,8 +10,8 @@ module Precious
|
||||
def has_results
|
||||
!@results.empty?
|
||||
end
|
||||
|
||||
def no_results
|
||||
|
||||
def no_results
|
||||
@results.empty?
|
||||
end
|
||||
end
|
||||
|
||||
+14
-14
@@ -13,16 +13,16 @@ module Precious
|
||||
i = @versions.size + 1
|
||||
@versions.map do |v|
|
||||
i -= 1
|
||||
{ :id => v.id,
|
||||
:id7 => v.id[0..6],
|
||||
:num => i,
|
||||
:selected => @page.version.id == v.id,
|
||||
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
||||
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
||||
:date => v.authored_date.strftime("%B %d, %Y"),
|
||||
:gravatar => Digest::MD5.hexdigest(v.author.email.strip.downcase),
|
||||
{ :id => v.id,
|
||||
:id7 => v.id[0..6],
|
||||
:num => i,
|
||||
:selected => @page.version.id == v.id,
|
||||
:author => v.author.name.respond_to?(:force_encoding) ? v.author.name.force_encoding('UTF-8') : v.author.name,
|
||||
:message => v.message.respond_to?(:force_encoding) ? v.message.force_encoding('UTF-8') : v.message,
|
||||
:date => v.authored_date.strftime("%B %d, %Y"),
|
||||
:gravatar => Digest::MD5.hexdigest(v.author.email.strip.downcase),
|
||||
:identicon => self._identicon_code(v.author.email),
|
||||
:date_full=> v.authored_date,
|
||||
:date_full => v.authored_date,
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -36,16 +36,16 @@ module Precious
|
||||
|
||||
def string_to_code string
|
||||
# sha bytes
|
||||
b = [Digest::SHA1.hexdigest(string)[0,20]].pack('H*').bytes.to_a
|
||||
b = [Digest::SHA1.hexdigest(string)[0, 20]].pack('H*').bytes.to_a
|
||||
# Thanks donpark's IdenticonUtil.java for this.
|
||||
# Match the following Java code
|
||||
# ((b[0] & 0xFF) << 24) | ((b[1] & 0xFF) << 16) |
|
||||
# ((b[2] & 0xFF) << 8) | (b[3] & 0xFF)
|
||||
|
||||
return left_shift(b[0], 24) |
|
||||
left_shift(b[1], 16) |
|
||||
left_shift(b[2], 8) |
|
||||
b[3] & 0xFF
|
||||
left_shift(b[1], 16) |
|
||||
left_shift(b[2], 8) |
|
||||
b[3] & 0xFF
|
||||
end
|
||||
|
||||
def _identicon_code(blob)
|
||||
@@ -53,7 +53,7 @@ module Precious
|
||||
end
|
||||
|
||||
def use_identicon
|
||||
@page.wiki.user_icons == 'identicon'
|
||||
@page.wiki.user_icons == 'identicon'
|
||||
end
|
||||
|
||||
def partial(name)
|
||||
|
||||
@@ -4,9 +4,9 @@ module Precious
|
||||
include HasPage
|
||||
|
||||
attr_reader :content, :page, :header, :footer
|
||||
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
DATE_FORMAT = "%Y-%m-%d %H:%M:%S"
|
||||
DEFAULT_AUTHOR = 'you'
|
||||
@@to_xml = { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' }
|
||||
@@to_xml = { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' }
|
||||
|
||||
def title
|
||||
h1 = @h1_title ? page_header_from_content(@content) : false
|
||||
@@ -23,14 +23,14 @@ module Precious
|
||||
|
||||
def author
|
||||
page_versions = @page.versions
|
||||
first = page_versions ? page_versions.first : false
|
||||
first = page_versions ? page_versions.first : false
|
||||
return DEFAULT_AUTHOR unless first
|
||||
first.author.name.respond_to?(:force_encoding) ? first.author.name.force_encoding('UTF-8') : first.author.name
|
||||
end
|
||||
|
||||
def date
|
||||
page_versions = @page.versions
|
||||
first = page_versions ? page_versions.first : false
|
||||
first = page_versions ? page_versions.first : false
|
||||
return Time.now.strftime(DATE_FORMAT) unless first
|
||||
first.authored_date.strftime(DATE_FORMAT)
|
||||
end
|
||||
@@ -50,7 +50,7 @@ module Precious
|
||||
def allow_uploads
|
||||
@allow_uploads
|
||||
end
|
||||
|
||||
|
||||
def upload_dest
|
||||
@upload_dest
|
||||
end
|
||||
@@ -80,7 +80,7 @@ module Precious
|
||||
def footer_format
|
||||
has_footer && @footer.format.to_s
|
||||
end
|
||||
|
||||
|
||||
def bar_side
|
||||
@bar_side.to_s
|
||||
end
|
||||
@@ -153,7 +153,7 @@ module Precious
|
||||
# Extracts title from page if present.
|
||||
#
|
||||
def page_header_from_content(content)
|
||||
doc = build_document(content)
|
||||
doc = build_document(content)
|
||||
title = find_header_node(doc).inner_text.strip
|
||||
title = nil if title.empty?
|
||||
title
|
||||
@@ -162,11 +162,11 @@ module Precious
|
||||
# Returns page content without title if it was extracted.
|
||||
#
|
||||
def content_without_page_header(content)
|
||||
doc = build_document(content)
|
||||
doc = build_document(content)
|
||||
title = find_header_node(doc)
|
||||
title.remove unless title.empty?
|
||||
# .inner_html will cause href escaping on UTF-8
|
||||
doc.css("div#gollum-root").children.to_xml( @@to_xml )
|
||||
doc.css("div#gollum-root").children.to_xml(@@to_xml)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,7 +11,7 @@ module Precious
|
||||
|
||||
def breadcrumb
|
||||
if @path
|
||||
path = Pathname.new(@path)
|
||||
path = Pathname.new(@path)
|
||||
breadcrumb = [%{<a href="#{@base_url}/pages/">Home</a>}]
|
||||
path.descend do |crumb|
|
||||
title = crumb.basename
|
||||
@@ -34,7 +34,7 @@ module Precious
|
||||
folder_links = []
|
||||
|
||||
@results.map { |page|
|
||||
page_path = page.path.sub(/^#{@path}\//,'')
|
||||
page_path = page.path.sub(/^#{@path}\//, '')
|
||||
|
||||
if page_path.include?('/')
|
||||
folder = page_path.split('/').first
|
||||
|
||||
Reference in New Issue
Block a user