Format code
This commit is contained in:
+4
-2
@@ -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
|
||||
|
||||
+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
|
||||
|
||||
+5
-5
@@ -56,7 +56,7 @@ 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
|
||||
@@ -216,7 +216,7 @@ module Precious
|
||||
end
|
||||
|
||||
committer = Gollum::Committer.new(wiki, commit_message)
|
||||
commit = {:committer => committer}
|
||||
commit = { :committer => committer }
|
||||
|
||||
success = wiki.rename_page(page, rename, commit)
|
||||
if !success
|
||||
@@ -239,7 +239,7 @@ 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]
|
||||
@@ -309,7 +309,7 @@ module Precious
|
||||
@path = wikip.path
|
||||
@name = wikip.name
|
||||
wiki = wikip.wiki
|
||||
@page = wiki.paged(@name,@path)
|
||||
@page = wiki.paged(@name, @path)
|
||||
sha1 = params[:sha1]
|
||||
sha2 = params[:sha2]
|
||||
|
||||
@@ -405,7 +405,7 @@ module Precious
|
||||
@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
|
||||
@results = wiki.search(@query).sort { |a, b| (a[:count] <=> b[:count]).nonzero? || b[:name] <=> a[:name] }.reverse
|
||||
@name = @query
|
||||
mustache :search
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -49,38 +49,58 @@ 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)
|
||||
def isAlphaNumeric(cc)
|
||||
# a - z
|
||||
if (97 <= cc && cc <= 122); return true end
|
||||
if (97 <= cc && cc <= 122);
|
||||
return true
|
||||
end
|
||||
# A - Z
|
||||
if (65 <= cc && cc <= 90); return true end
|
||||
if (65 <= cc && cc <= 90);
|
||||
return true
|
||||
end
|
||||
# 0 - 9
|
||||
if (48 <= cc && cc <= 57); return true end
|
||||
if (48 <= cc && cc <= 57);
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def unescapePredicate(cc)
|
||||
if (isAlphaNumeric(cc)); return true end
|
||||
def unescapePredicate(cc)
|
||||
if (isAlphaNumeric(cc));
|
||||
return true
|
||||
end
|
||||
# !
|
||||
if (cc == 33); return true end
|
||||
if (cc == 33);
|
||||
return true
|
||||
end
|
||||
# '()*
|
||||
if (39 <= cc && cc <= 42); return true end
|
||||
if (39 <= cc && cc <= 42);
|
||||
return true
|
||||
end
|
||||
# -.
|
||||
if (45 <= cc && cc <= 46); return true end
|
||||
if (45 <= cc && cc <= 46);
|
||||
return true
|
||||
end
|
||||
# _
|
||||
if (cc == 95); return true end
|
||||
if (cc == 95);
|
||||
return true
|
||||
end
|
||||
# ~
|
||||
if (cc == 126); return true end
|
||||
if (cc == 126);
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def URIEncodeSingle(cc, result, index)
|
||||
def URIEncodeSingle(cc, result, index)
|
||||
x = (cc >> 12) & 0xF;
|
||||
y = (cc >> 6) & 63;
|
||||
z = cc & 63;
|
||||
@@ -96,12 +116,12 @@ def URIEncodeSingle(cc, result, index)
|
||||
octets[2] = z + 128;
|
||||
end
|
||||
return URIEncodeOctets(octets, result, index);
|
||||
end
|
||||
end
|
||||
|
||||
# Lazily initialized.
|
||||
@@hexCharCodeArray = 0;
|
||||
@@hexCharCodeArray = 0;
|
||||
|
||||
def URIAddEncodedOctetToBuffer(octet, result, index)
|
||||
def URIAddEncodedOctetToBuffer(octet, result, index)
|
||||
result[index] = 37; # Char code of '%'.
|
||||
index += 1
|
||||
result[index] = @@hexCharCodeArray[octet >> 4];
|
||||
@@ -109,21 +129,27 @@ def URIAddEncodedOctetToBuffer(octet, result, index)
|
||||
result[index] = @@hexCharCodeArray[octet & 0x0F];
|
||||
index += 1
|
||||
return index;
|
||||
end
|
||||
end
|
||||
|
||||
def URIEncodeOctets(octets, result, index)
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
def URIEncodePair(cc1 , cc2, result, index)
|
||||
def URIEncodePair(cc1, cc2, result, index)
|
||||
u = ((cc1 >> 6) & 0xF) + 1;
|
||||
w = (cc1 >> 2) & 0xF;
|
||||
x = cc1 & 3;
|
||||
@@ -135,15 +161,15 @@ def URIEncodePair(cc1 , cc2, result, index)
|
||||
octets[2] = ((x << 4) | y) + 128;
|
||||
octets[3] = z + 128;
|
||||
return URIEncodeOctets(octets, result, index);
|
||||
end
|
||||
end
|
||||
|
||||
# component must be String
|
||||
def URIEncodeComponent(componentString)
|
||||
def URIEncodeComponent(componentString)
|
||||
Encode(componentString, :unescapePredicate);
|
||||
end
|
||||
end
|
||||
|
||||
# ECMA-262, section 15.1.3
|
||||
def Encode(uri, unescape)
|
||||
def Encode(uri, unescape)
|
||||
uriLength = uri.length;
|
||||
# We are going to pass result to %StringFromCharCodeArray
|
||||
# which does not expect any getters/setters installed
|
||||
@@ -158,14 +184,20 @@ def Encode(uri, unescape)
|
||||
result[index] = cc1;
|
||||
index += 1
|
||||
else
|
||||
if (cc1 >= 0xDC00 && cc1 <= 0xDFFF); throw("URI malformed") end
|
||||
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
|
||||
if (k == uriLength);
|
||||
throw("URI malformed")
|
||||
end
|
||||
cc2 = uri.charCodeAt(k);
|
||||
if (cc2 < 0xDC00 || cc2 > 0xDFFF); throw("URI malformed") end
|
||||
if (cc2 < 0xDC00 || cc2 > 0xDFFF);
|
||||
throw("URI malformed")
|
||||
end
|
||||
index = URIEncodePair(cc1, cc2, result, index);
|
||||
end
|
||||
end
|
||||
@@ -175,6 +207,6 @@ def Encode(uri, unescape)
|
||||
# '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
|
||||
end # class << self
|
||||
end # module
|
||||
|
||||
@@ -47,6 +47,7 @@ module Precious
|
||||
end
|
||||
|
||||
@left_diff_line_number = nil
|
||||
|
||||
def left_diff_line_number(id, line)
|
||||
if line =~ /^@@/
|
||||
m, li = *line.match(/\-(\d+)/)
|
||||
@@ -68,6 +69,7 @@ module Precious
|
||||
end
|
||||
|
||||
@right_diff_line_number = nil
|
||||
|
||||
def right_diff_line_number(id, line)
|
||||
if line =~ /^@@/
|
||||
m, ri = *line.match(/\+(\d+)/)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -22,7 +22,7 @@ module Precious
|
||||
: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,7 +36,7 @@ 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) |
|
||||
|
||||
@@ -166,7 +166,7 @@ module Precious
|
||||
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
|
||||
|
||||
@@ -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