whitespace plugin

This commit is contained in:
rick
2011-01-10 16:44:07 -08:00
parent cc85879810
commit 0fd639a149
3 changed files with 33 additions and 30 deletions
+1 -1
View File
@@ -59,7 +59,7 @@ module Precious
page = wiki.page(params[:splat].first) page = wiki.page(params[:splat].first)
name = params[:rename] || page.name name = params[:rename] || page.name
msg = commit_message msg = commit_message
update_wiki_page(wiki, page, params[:content], msg, name, update_wiki_page(wiki, page, params[:content], msg, name,
params[:format]) params[:format])
update_wiki_page(wiki, page.footer, params[:footer], msg) if params[:footer] update_wiki_page(wiki, page.footer, params[:footer], msg) if params[:footer]
update_wiki_page(wiki, page.sidebar, params[:sidebar], msg) if params[:sidebar] update_wiki_page(wiki, page.sidebar, params[:sidebar], msg) if params[:sidebar]
+9 -9
View File
@@ -28,8 +28,8 @@ module Gollum
# #
# Returns the formatted String content. # Returns the formatted String content.
def render(no_follow = false) def render(no_follow = false)
sanitize = no_follow ? sanitize = no_follow ?
@wiki.history_sanitizer : @wiki.history_sanitizer :
@wiki.sanitizer @wiki.sanitizer
data = extract_tex(@data.dup) data = extract_tex(@data.dup)
@@ -147,7 +147,7 @@ module Gollum
# Process a single tag into its final HTML form. # Process a single tag into its final HTML form.
# #
# tag - The String tag contents (the stuff inside the double # tag - The String tag contents (the stuff inside the double
# brackets). # brackets).
# no_follow - Boolean that determines if rel="nofollow" is added to all # no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags. # <a> tags.
@@ -252,7 +252,7 @@ module Gollum
# Attempt to process the tag as a file link tag. # Attempt to process the tag as a file link tag.
# #
# tag - The String tag contents (the stuff inside the double # tag - The String tag contents (the stuff inside the double
# brackets). # brackets).
# no_follow - Boolean that determines if rel="nofollow" is added to all # no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags. # <a> tags.
@@ -286,7 +286,7 @@ module Gollum
# Attempt to process the tag as a page link tag. # Attempt to process the tag as a page link tag.
# #
# tag - The String tag contents (the stuff inside the double # tag - The String tag contents (the stuff inside the double
# brackets). # brackets).
# no_follow - Boolean that determines if rel="nofollow" is added to all # no_follow - Boolean that determines if rel="nofollow" is added to all
# <a> tags. # <a> tags.
@@ -335,7 +335,7 @@ module Gollum
# #
# cname - The String canonical page name. # cname - The String canonical page name.
# #
# Returns a Gollum::Page instance if a page is found, or an Array of # Returns a Gollum::Page instance if a page is found, or an Array of
# [Gollum::Page, String extra] if a page without the extra anchor data # [Gollum::Page, String extra] if a page without the extra anchor data
# is found. # is found.
def find_page_from_name(cname) def find_page_from_name(cname)
@@ -362,8 +362,8 @@ module Gollum
data.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do data.gsub!(/^``` ?(.+?)\r?\n(.+?)\r?\n```\r?$/m) do
id = Digest::SHA1.hexdigest($2) id = Digest::SHA1.hexdigest($2)
cached = check_cache(:code, id) cached = check_cache(:code, id)
@codemap[id] = cached ? @codemap[id] = cached ?
{ :output => cached } : { :output => cached } :
{ :lang => $1, :code => $2 } { :lang => $1, :code => $2 }
id id
end end
@@ -393,7 +393,7 @@ module Gollum
data data
end end
# Hook for getting the formatted value of extracted tag data. # Hook for getting the formatted value of extracted tag data.
# #
# type - Symbol value identifying what type of data is being extracted. # type - Symbol value identifying what type of data is being extracted.
# id - String SHA1 hash of original extracted tag data. # id - String SHA1 hash of original extracted tag data.
+23 -20
View File
@@ -59,7 +59,7 @@ module Gollum
end end
end end
# Gets the default sanitization options for current pages used by # Gets the default sanitization options for current pages used by
# instances of this Wiki. # instances of this Wiki.
def sanitization def sanitization
if @sanitization.nil? if @sanitization.nil?
@@ -68,7 +68,7 @@ module Gollum
@sanitization @sanitization
end end
# Gets the default sanitization options for older page revisions used by # Gets the default sanitization options for older page revisions used by
# instances of this Wiki. # instances of this Wiki.
def history_sanitization def history_sanitization
if @history_sanitization.nil? if @history_sanitization.nil?
@@ -120,7 +120,7 @@ module Gollum
@markup_class = options[:markup_class] || self.class.markup_class @markup_class = options[:markup_class] || self.class.markup_class
@repo = @access.repo @repo = @access.repo
@sanitization = options[:sanitization] || self.class.sanitization @sanitization = options[:sanitization] || self.class.sanitization
@history_sanitization = options[:history_sanitization] || @history_sanitization = options[:history_sanitization] ||
self.class.history_sanitization self.class.history_sanitization
end end
@@ -266,7 +266,7 @@ module Gollum
tree_list(treeish || 'master') tree_list(treeish || 'master')
end end
# Public: Returns the number of pages accessible from a commit # Public: Returns the number of pages accessible from a commit
# #
# ref - A String ref that is either a commit SHA or references one. # ref - A String ref that is either a commit SHA or references one.
# #
@@ -340,7 +340,7 @@ module Gollum
@access.refresh @access.refresh
end end
# Public: Creates a Sanitize instance using the Wiki's sanitization # Public: Creates a Sanitize instance using the Wiki's sanitization
# options. # options.
# #
# Returns a Sanitize instance. # Returns a Sanitize instance.
@@ -350,7 +350,7 @@ module Gollum
end end
end end
# Public: Creates a Sanitize instance using the Wiki's history sanitization # Public: Creates a Sanitize instance using the Wiki's history sanitization
# options. # options.
# #
# Returns a Sanitize instance. # Returns a Sanitize instance.
@@ -536,6 +536,12 @@ module Gollum
index.add(fullpath, normalize(data)) index.add(fullpath, normalize(data))
end end
# Commits to the repo. This is a common method used by Gollum for
# creating, updating, and deleting pages. There are typically three steps:
# building an index with the current tree, yielding the index for
# modification, and then writing the commit.
#
# options - Hash of option
def commit_index(options = {}) def commit_index(options = {})
normalize_commit(options) normalize_commit(options)
parents = [options[:parent] || @repo.commit('master')] parents = [options[:parent] || @repo.commit('master')]
@@ -549,6 +555,8 @@ module Gollum
end end
yield index if block_given? yield index if block_given?
options[:name] = default_committer_name if options[:name].to_s.empty?
options[:email] = default_committer_email if options[:email].to_s.empty?
actor = Grit::Actor.new(options[:name], options[:email]) actor = Grit::Actor.new(options[:name], options[:email])
index.commit(options[:message], parents, actor) index.commit(options[:message], parents, actor)
end end
@@ -558,32 +566,27 @@ module Gollum
repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path) repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path)
end end
# Ensures a commit hash has all the required fields for a commit.
#
# commit - The commit Hash details:
# :message - The String commit message.
# :name - The String author full name.
# :email - The String email address.
#
# Returns the commit Hash
def normalize_commit(commit = {})
commit[:name] = default_committer_name if commit[:name].to_s.empty?
commit[:email] = default_committer_email if commit[:email].to_s.empty?
commit
end
# Gets the default name for commits. # Gets the default name for commits.
#
# Returns the String name.
def default_committer_name def default_committer_name
@default_committer_name ||= \ @default_committer_name ||= \
@repo.config['user.name'] || self.class.default_committer_name @repo.config['user.name'] || self.class.default_committer_name
end end
# Gets the default email for commits. # Gets the default email for commits.
#
# Returns the String email address.
def default_committer_email def default_committer_email
@default_committer_email ||= \ @default_committer_email ||= \
@repo.config['user.email'] || self.class.default_committer_email @repo.config['user.email'] || self.class.default_committer_email
end end
# Gets the commit object for the given ref or sha.
#
# ref - A string ref or SHA pointing to a valid commit.
#
# Returns a Grit::Commit instance.
def commit_for(ref) def commit_for(ref)
@access.commit(ref) @access.commit(ref)
rescue Grit::GitRuby::Repository::NoSuchShaFound rescue Grit::GitRuby::Repository::NoSuchShaFound