Class: Gollum::Wiki
Class Attribute Summary collapse
-
.default_committer_email ⇒ Object
Sets the default email for commits.
-
.default_committer_name ⇒ Object
Sets the default name for commits.
-
.default_options ⇒ Object
Hash for setting different default wiki options These defaults can be overridden by options passed directly to initialize().
-
.default_ref ⇒ Object
Sets the default ref for the wiki.
-
.default_ws_subs ⇒ Object
Array of chars to substitute whitespace for when trying to locate file in git repo.
-
.file_class ⇒ Object
Gets the file class used by all instances of this Wiki.
-
.history_sanitization ⇒ Object
Gets the default sanitization options for older page revisions used by instances of this Wiki.
-
.markup_classes ⇒ Object
Gets the markup class used by all instances of this Wiki.
-
.page_class ⇒ Object
Gets the page class used by all instances of this Wiki.
-
.sanitization ⇒ Object
Gets the default sanitization options for current pages used by instances of this Wiki.
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
The String base path to prefix to internal links.
-
#file_class ⇒ Object
readonly
Gets the file class used by all instances of this Wiki.
-
#history_sanitization ⇒ Object
readonly
Gets the sanitization options for older page revisions used by this Wiki.
-
#live_preview ⇒ Object
readonly
Gets the boolean live preview value.
-
#markup_classes ⇒ Object
readonly
Gets the markup class used by all instances of this Wiki.
-
#mathjax ⇒ Object
readonly
Toggles mathjax.
-
#page_class ⇒ Object
readonly
Gets the page class used by all instances of this Wiki.
-
#page_file_dir ⇒ Object
readonly
Gets the String directory in which all page files reside.
-
#path ⇒ Object
readonly
The String path to the Git repository that holds the Gollum site.
-
#ref ⇒ Object
readonly
Gets the String ref in which all page files reside.
-
#repo ⇒ Object
readonly
The Grit::Repo associated with the wiki.
-
#sanitization ⇒ Object
readonly
Gets the sanitization options for current pages used by this Wiki.
-
#universal_toc ⇒ Object
readonly
Toggles display of universal table of contents.
-
#ws_subs ⇒ Object
readonly
Gets the Array of chars to sub for ws in filenames.
Class Method Summary collapse
-
.markup_class(language = :default) ⇒ Object
(also: default_markup_class)
Gets the default markup class used by all instances of this Wiki.
-
.markup_class=(default) ⇒ Object
(also: default_markup_class=)
Sets the default markup class used by all instances of this Wiki.
Instance Method Summary collapse
-
#clear_cache ⇒ Object
Public: Refreshes just the cached Git reference data.
-
#commit_for(ref) ⇒ Object
Gets the commit object for the given ref or sha.
-
#default_committer_email ⇒ Object
Gets the default email for commits.
-
#default_committer_name ⇒ Object
Gets the default name for commits.
-
#delete_page(page, commit) ⇒ Object
Public: Delete a page.
-
#exist? ⇒ Boolean
Public: check whether the wiki’s git repo exists on the filesystem.
-
#file(name, version = @ref) ⇒ Object
Public: Get the static file for a given name.
-
#file_list(ref) ⇒ Object
Fill an array with a list of files.
-
#files(treeish = nil) ⇒ Object
Public: Lists all non-page files for this wiki.
-
#full_reverse_diff(sha1, sha2 = nil) ⇒ Object
Creates a reverse diff for the given SHAs.
-
#full_reverse_diff_for(page, sha1, sha2 = nil) ⇒ Object
Creates a reverse diff for the given SHAs on the given Gollum::Page.
-
#history_sanitizer ⇒ Object
Public: Creates a Sanitize instance using the Wiki’s history sanitization options.
-
#initialize(path, options = {}) ⇒ Wiki
constructor
Public: Initialize a new Gollum Repo.
- #inspect ⇒ Object
-
#log(options = {}) ⇒ Object
Public: All of the versions that have touched the Page.
-
#normalize(data) ⇒ Object
Normalize the data.
-
#page(name, version = @ref, dir = nil) ⇒ Object
Public: Get the formatted page for a given page name, version, and dir.
-
#page_file_name(name, format) ⇒ Object
Assemble a Page’s filename from its name and format.
-
#paged(name, dir = nil, version = @ref) ⇒ Object
Public: Convenience method instead of calling page(name, nil, dir).
-
#pages(treeish = nil) ⇒ Object
Public: Lists all pages for this wiki.
-
#preview_page(name, data, format) ⇒ Object
Public: Create an in-memory Page with the given data and format.
-
#revert_commit(sha1, sha2 = nil, commit = {}) ⇒ Object
Public: Applies a reverse diff to the repo.
-
#revert_page(page, sha1, sha2 = nil, commit = {}) ⇒ Object
Public: Applies a reverse diff for a given page.
-
#sanitizer ⇒ Object
Public: Creates a Sanitize instance using the Wiki’s sanitization options.
-
#search(query) ⇒ Object
Public: Search all pages for this wiki.
-
#size(ref = nil) ⇒ Object
Public: Returns the number of pages accessible from a commit.
-
#tree_list(ref) ⇒ Object
Fill an array with a list of pages.
-
#tree_map_for(ref, ignore_page_file_dir = false) ⇒ Object
Finds a full listing of files and their blob SHA for a given ref.
-
#update_page(page, name, format, data, commit = {}) ⇒ Object
Public: Update an existing page with new content.
-
#write_page(name, format, data, commit = {}) ⇒ Object
Public: Write a new version of a page to the Gollum repo root.
Methods included from Pagination
included, #log_pagination_options, #page_to_skip
Constructor Details
#initialize(path, options = {}) ⇒ Wiki
Public: Initialize a new Gollum Repo.
path - The String path to the Git repository that holds the Gollum
site.
options - Optional Hash:
:universal_toc - Table of contents on all pages. Default: false
:live_preview - Livepreview editing for markdown files. Default: true
:base_path - String base path for all Wiki links.
Default: "/"
:page_class - The page Class. Default: Gollum::Page
:file_class - The file Class. Default: Gollum::File
:markup_classes - A hash containing the markup Classes for each
document type. Default: { Gollum::Markup }
:sanitization - An instance of Sanitization.
:page_file_dir - String the directory in which all page files reside
:ref - String the repository ref to retrieve pages from
:ws_subs - Array of chars to sub for ws in filenames.
:mathjax - Set to false to disable mathjax.
Returns a fresh Gollum::Repo.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gollum/wiki.rb', line 159 def initialize(path, = {}) = self.class..merge() if path.is_a?(GitAccess) [:access] = path path = path.path end @path = path @repo_is_bare = [:repo_is_bare] @page_file_dir = [:page_file_dir] @access = [:access] || GitAccess.new(path, @page_file_dir, @repo_is_bare) @base_path = [:base_path] || "/" @page_class = [:page_class] || self.class.page_class @file_class = [:file_class] || self.class.file_class @markup_classes = [:markup_classes] || self.class.markup_classes @repo = @access.repo @ref = [:ref] || self.class.default_ref @sanitization = [:sanitization] || self.class.sanitization @ws_subs = [:ws_subs] || self.class.default_ws_subs @history_sanitization = [:history_sanitization] || self.class.history_sanitization @live_preview = .fetch(:live_preview, true) @universal_toc = .fetch(:universal_toc, false) @mathjax = [:mathjax] || true end |
Class Attribute Details
.default_committer_email ⇒ Object
Sets the default email for commits.
22 23 24 |
# File 'lib/gollum/wiki.rb', line 22 def default_committer_email @default_committer_email end |
.default_committer_name ⇒ Object
Sets the default name for commits.
19 20 21 |
# File 'lib/gollum/wiki.rb', line 19 def default_committer_name @default_committer_name end |
.default_options ⇒ Object
Hash for setting different default wiki options These defaults can be overridden by options passed directly to initialize()
37 38 39 |
# File 'lib/gollum/wiki.rb', line 37 def @default_options end |
.default_ref ⇒ Object
Sets the default ref for the wiki.
16 17 18 |
# File 'lib/gollum/wiki.rb', line 16 def default_ref @default_ref end |
.default_ws_subs ⇒ Object
Array of chars to substitute whitespace for when trying to locate file in git repo.
25 26 27 |
# File 'lib/gollum/wiki.rb', line 25 def default_ws_subs @default_ws_subs end |
.file_class ⇒ Object
Gets the file class used by all instances of this Wiki. Default: Gollum::File.
52 53 54 55 56 57 58 59 |
# File 'lib/gollum/wiki.rb', line 52 def file_class @file_class || if superclass.respond_to?(:file_class) superclass.file_class else ::Gollum::File end end |
.history_sanitization ⇒ Object
Gets the default sanitization options for older page revisions used by instances of this Wiki.
99 100 101 102 103 104 105 106 |
# File 'lib/gollum/wiki.rb', line 99 def history_sanitization if @history_sanitization.nil? @history_sanitization = sanitization ? sanitization.history_sanitization : false end @history_sanitization end |
.markup_classes ⇒ Object
Gets the markup class used by all instances of this Wiki. Default: Gollum::Markup
63 64 65 66 67 68 69 70 |
# File 'lib/gollum/wiki.rb', line 63 def markup_classes @markup_classes ||= if superclass.respond_to?(:markup_classes) superclass.markup_classes else Hash.new(::Gollum::Markup) end end |
.page_class ⇒ Object
Gets the page class used by all instances of this Wiki. Default: Gollum::Page.
41 42 43 44 45 46 47 48 |
# File 'lib/gollum/wiki.rb', line 41 def page_class @page_class || if superclass.respond_to?(:page_class) superclass.page_class else ::Gollum::Page end end |
.sanitization ⇒ Object
Gets the default sanitization options for current pages used by instances of this Wiki.
90 91 92 93 94 95 |
# File 'lib/gollum/wiki.rb', line 90 def sanitization if @sanitization.nil? @sanitization = Sanitization.new end @sanitization end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
The String base path to prefix to internal links. For example, when set to “/wiki”, the page “Hobbit” will be linked as “/wiki/Hobbit”. Defaults to “/”.
119 120 121 |
# File 'lib/gollum/wiki.rb', line 119 def base_path @base_path end |
#file_class ⇒ Object (readonly)
Gets the file class used by all instances of this Wiki.
575 576 577 |
# File 'lib/gollum/wiki.rb', line 575 def file_class @file_class end |
#history_sanitization ⇒ Object (readonly)
Gets the sanitization options for older page revisions used by this Wiki.
125 126 127 |
# File 'lib/gollum/wiki.rb', line 125 def history_sanitization @history_sanitization end |
#live_preview ⇒ Object (readonly)
Gets the boolean live preview value.
137 138 139 |
# File 'lib/gollum/wiki.rb', line 137 def live_preview @live_preview end |
#markup_classes ⇒ Object (readonly)
Gets the markup class used by all instances of this Wiki.
578 579 580 |
# File 'lib/gollum/wiki.rb', line 578 def markup_classes @markup_classes end |
#mathjax ⇒ Object (readonly)
Toggles mathjax.
584 585 586 |
# File 'lib/gollum/wiki.rb', line 584 def mathjax @mathjax end |
#page_class ⇒ Object (readonly)
Gets the page class used by all instances of this Wiki.
572 573 574 |
# File 'lib/gollum/wiki.rb', line 572 def page_class @page_class end |
#page_file_dir ⇒ Object (readonly)
Gets the String directory in which all page files reside.
131 132 133 |
# File 'lib/gollum/wiki.rb', line 131 def page_file_dir @page_file_dir end |
#path ⇒ Object (readonly)
The String path to the Git repository that holds the Gollum site.
Returns the String path.
569 570 571 |
# File 'lib/gollum/wiki.rb', line 569 def path @path end |
#ref ⇒ Object (readonly)
Gets the String ref in which all page files reside.
128 129 130 |
# File 'lib/gollum/wiki.rb', line 128 def ref @ref end |
#repo ⇒ Object (readonly)
The Grit::Repo associated with the wiki.
Returns the Grit::Repo.
564 565 566 |
# File 'lib/gollum/wiki.rb', line 564 def repo @repo end |
#sanitization ⇒ Object (readonly)
Gets the sanitization options for current pages used by this Wiki.
122 123 124 |
# File 'lib/gollum/wiki.rb', line 122 def sanitization @sanitization end |
#universal_toc ⇒ Object (readonly)
Toggles display of universal table of contents
581 582 583 |
# File 'lib/gollum/wiki.rb', line 581 def universal_toc @universal_toc end |
#ws_subs ⇒ Object (readonly)
Gets the Array of chars to sub for ws in filenames.
134 135 136 |
# File 'lib/gollum/wiki.rb', line 134 def ws_subs @ws_subs end |
Class Method Details
.markup_class(language = :default) ⇒ Object Also known as: default_markup_class
Gets the default markup class used by all instances of this Wiki. Kept for backwards compatibility until Gollum v2.x
74 75 76 |
# File 'lib/gollum/wiki.rb', line 74 def markup_class(language=:default) markup_classes[language] end |
.markup_class=(default) ⇒ Object Also known as: default_markup_class=
Sets the default markup class used by all instances of this Wiki. Kept for backwards compatibility until Gollum v2.x
80 81 82 83 |
# File 'lib/gollum/wiki.rb', line 80 def markup_class=(default) @markup_classes = Hash.new(default).update(markup_classes) default end |
Instance Method Details
#clear_cache ⇒ Object
Public: Refreshes just the cached Git reference data. This should be called after every Gollum update.
Returns nothing.
531 532 533 |
# File 'lib/gollum/wiki.rb', line 531 def clear_cache @access.refresh end |
#commit_for(ref) ⇒ Object
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.
689 690 691 692 |
# File 'lib/gollum/wiki.rb', line 689 def commit_for(ref) @access.commit(ref) rescue Grit::GitRuby::Repository::NoSuchShaFound end |
#default_committer_email ⇒ Object
Gets the default email for commits.
Returns the String email address.
679 680 681 682 |
# File 'lib/gollum/wiki.rb', line 679 def default_committer_email @default_committer_email ||= \ @repo.config['user.email'] || self.class.default_committer_email end |
#default_committer_name ⇒ Object
Gets the default name for commits.
Returns the String name.
671 672 673 674 |
# File 'lib/gollum/wiki.rb', line 671 def default_committer_name @default_committer_name ||= \ @repo.config['user.name'] || self.class.default_committer_name end |
#delete_page(page, commit) ⇒ Object
Public: Delete a page.
page - The Gollum::Page to delete. commit - The commit Hash details:
:message - The String commit message.
:name - The String author full name.
:email - The String email address.
:parent - Optional Grit::Commit parent to this update.
:tree - Optional String SHA of the tree to create the
index from.
:committer - Optional Gollum::Committer instance. If provided,
assume that this operation is part of batch of
updates and the commit happens later.
Returns the String SHA1 of the newly written version, or the Gollum::Committer instance if this is part of a batch update.
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/gollum/wiki.rb', line 355 def delete_page(page, commit) multi_commit = false committer = if obj = commit[:committer] multi_commit = true obj else Committer.new(self, commit) end committer.delete(page.path) committer.after_commit do |index, sha| dir = ::File.dirname(page.path) dir = '' if dir == '.' @access.refresh index.update_working_dir(dir, page.filename_stripped, page.format) end multi_commit ? committer : committer.commit end |
#exist? ⇒ Boolean
Public: check whether the wiki’s git repo exists on the filesystem.
Returns true if the repo exists, and false if it does not.
188 189 190 |
# File 'lib/gollum/wiki.rb', line 188 def exist? @access.exist? end |
#file(name, version = @ref) ⇒ Object
Public: Get the static file for a given name.
name - The full String pathname to the file. version - The String version ID to find (default: @ref).
Returns a Gollum::File or nil if no matching file was found.
221 222 223 |
# File 'lib/gollum/wiki.rb', line 221 def file(name, version = @ref) @file_class.new(self).find(name, version) end |
#file_list(ref) ⇒ Object
Fill an array with a list of files.
ref - A String ref that is either a commit SHA or references one.
Returns a flat Array of Gollum::File instances.
627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/gollum/wiki.rb', line 627 def file_list(ref) if sha = @access.ref_to_sha(ref) commit = @access.commit(sha) tree_map_for(sha).inject([]) do |list, entry| next list if entry.name.start_with?('_') next list if @page_class.valid_page_name?(entry.name) list << entry.file(self, commit) end else [] end end |
#files(treeish = nil) ⇒ Object
Public: Lists all non-page files for this wiki.
treeish - The String commit ID or ref to find (default: @ref)
Returns an Array of Gollum::File instances.
467 468 469 |
# File 'lib/gollum/wiki.rb', line 467 def files(treeish = nil) file_list(treeish || @ref) end |
#full_reverse_diff(sha1, sha2 = nil) ⇒ Object
Creates a reverse diff for the given SHAs.
sha1 - String SHA1 of the earlier parent if two SHAs are given,
or the child.
sha2 - Optional String SHA1 of the child.
Returns a String of the reverse Diff to apply.
664 665 666 |
# File 'lib/gollum/wiki.rb', line 664 def full_reverse_diff(sha1, sha2 = nil) full_reverse_diff_for(nil, sha1, sha2) end |
#full_reverse_diff_for(page, sha1, sha2 = nil) ⇒ Object
Creates a reverse diff for the given SHAs on the given Gollum::Page.
page - The Gollum::Page to scope the patch to, or a String Path. sha1 - String SHA1 of the earlier parent if two SHAs are given,
or the child.
sha2 - Optional String SHA1 of the child.
Returns a String of the reverse Diff to apply.
648 649 650 651 652 653 654 655 |
# File 'lib/gollum/wiki.rb', line 648 def full_reverse_diff_for(page, sha1, sha2 = nil) sha1, sha2 = "#{sha1}^", sha1 if sha2.nil? args = [{:R => true}, sha1, sha2] if page args << '--' << (page.respond_to?(:path) ? page.path : page.to_s) end repo.git.native(:diff, *args) end |
#history_sanitizer ⇒ Object
Public: Creates a Sanitize instance using the Wiki’s history sanitization options.
Returns a Sanitize instance.
549 550 551 552 553 |
# File 'lib/gollum/wiki.rb', line 549 def history_sanitizer if = history_sanitization @history_sanitizer ||= .to_sanitize end end |
#inspect ⇒ Object
712 713 714 |
# File 'lib/gollum/wiki.rb', line 712 def inspect %(#<#{self.class.name}:#{object_id} #{@repo.path}>) end |
#log(options = {}) ⇒ Object
Public: All of the versions that have touched the Page.
options - The options Hash:
:page - The Integer page number (default: 1).
:per_page - The Integer max count of items to return.
Returns an Array of Grit::Commit.
523 524 525 |
# File 'lib/gollum/wiki.rb', line 523 def log( = {}) @repo.log(@ref, nil, ()) end |
#normalize(data) ⇒ Object
Normalize the data.
data - The String data to be normalized.
Returns the normalized data String.
591 592 593 |
# File 'lib/gollum/wiki.rb', line 591 def normalize(data) data.gsub(/\r/, '') end |
#page(name, version = @ref, dir = nil) ⇒ Object
Public: Get the formatted page for a given page name, version, and dir.
name - The human or canonical String page name of the wiki page. version - The String version ID to find (default: @ref). dir - The directory String relative to the repo.
Returns a Gollum::Page or nil if no matching page was found.
199 200 201 202 |
# File 'lib/gollum/wiki.rb', line 199 def page(name, version = @ref, dir = nil) version = @ref if version.nil? @page_class.new(self).find(name, version, dir) end |
#page_file_name(name, format) ⇒ Object
Assemble a Page’s filename from its name and format.
name - The String name of the page (should be pre-canonicalized). format - The Symbol format of the page.
Returns the String filename.
601 602 603 |
# File 'lib/gollum/wiki.rb', line 601 def page_file_name(name, format) name + '.' + @page_class.format_to_ext(format) end |
#paged(name, dir = nil, version = @ref) ⇒ Object
Public: Convenience method instead of calling page(name, nil, dir).
name - The human or canonical String page name of the wiki page. version - The String version ID to find (default: @ref). dir - The directory String relative to the repo.
Returns a Gollum::Page or nil if no matching page was found.
211 212 213 |
# File 'lib/gollum/wiki.rb', line 211 def paged(name, dir = nil, version = @ref) page(name, version, dir) end |
#pages(treeish = nil) ⇒ Object
Public: Lists all pages for this wiki.
treeish - The String commit ID or ref to find (default: @ref)
Returns an Array of Gollum::Page instances.
458 459 460 |
# File 'lib/gollum/wiki.rb', line 458 def pages(treeish = nil) tree_list(treeish || @ref) end |
#preview_page(name, data, format) ⇒ Object
Public: Create an in-memory Page with the given data and format. This is useful for previewing what content will look like before committing it to the repository.
name - The String name of the page. format - The Symbol format of the page. data - The new String contents of the page.
Returns the in-memory Gollum::Page.
234 235 236 237 238 239 240 241 242 |
# File 'lib/gollum/wiki.rb', line 234 def preview_page(name, data, format) page = @page_class.new(self) ext = @page_class.format_to_ext(format.to_sym) name = @page_class.cname(name) + '.' + ext blob = OpenStruct.new(:name => name, :data => data) page.populate(blob) page.version = @access.commit('master') page end |
#revert_commit(sha1, sha2 = nil, commit = {}) ⇒ Object
Public: Applies a reverse diff to the repo. If only 1 SHA is given, the reverse diff will be taken from its parent (^SHA…SHA). If two SHAs are given, the reverse diff is taken from SHA1…SHA2.
sha1 - String SHA1 of the earlier parent if two SHAs are given,
or the child.
sha2 - Optional String SHA1 of the child. commit - The commit Hash details:
:message - The String commit message.
:name - The String author full name.
:email - The String email address.
Returns a String SHA1 of the new commit, or nil if the reverse diff does not apply.
449 450 451 |
# File 'lib/gollum/wiki.rb', line 449 def revert_commit(sha1, sha2 = nil, commit = {}) revert_page(nil, sha1, sha2, commit) end |
#revert_page(page, sha1, sha2 = nil, commit = {}) ⇒ Object
Public: Applies a reverse diff for a given page. If only 1 SHA is given, the reverse diff will be taken from its parent (^SHA…SHA). If two SHAs are given, the reverse diff is taken from SHA1…SHA2.
page - The Gollum::Page to delete. sha1 - String SHA1 of the earlier parent if two SHAs are given,
or the child.
sha2 - Optional String SHA1 of the child. commit - The commit Hash details:
:message - The String commit message.
:name - The String author full name.
:email - The String email address.
:parent - Optional Grit::Commit parent to this update.
Returns a String SHA1 of the new commit, or nil if the reverse diff does not apply.
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/gollum/wiki.rb', line 394 def revert_page(page, sha1, sha2 = nil, commit = {}) if sha2.is_a?(Hash) commit = sha2 sha2 = nil end patch = full_reverse_diff_for(page, sha1, sha2) committer = Committer.new(self, commit) parent = committer.parents[0] committer.[:tree] = @repo.git.apply_patch(parent.sha, patch) return false unless committer.[:tree] committer.after_commit do |index, sha| @access.refresh files = [] if page files << [page.path, page.filename_stripped, page.format] else # Grit::Diff can't parse reverse diffs.... yet patch.each_line do |line| if line =~ %r{^diff --git b/.+? a/(.+)$} path = $1 ext = ::File.extname(path) name = ::File.basename(path, ext) if format = ::Gollum::Page.format_for(ext) files << [path, name, format] end end end end files.each do |(path, name, format)| dir = ::File.dirname(path) dir = '' if dir == '.' index.update_working_dir(dir, name, format) end end committer.commit end |
#sanitizer ⇒ Object
Public: Creates a Sanitize instance using the Wiki’s sanitization options.
Returns a Sanitize instance.
539 540 541 542 543 |
# File 'lib/gollum/wiki.rb', line 539 def sanitizer if = sanitization @sanitizer ||= .to_sanitize end end |
#search(query) ⇒ Object
Public: Search all pages for this wiki.
query - The string to search for
Returns an Array with Objects of page name and count of matches
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/gollum/wiki.rb', line 489 def search(query) args = [{}, '-i', '-c', query, @ref, '--'] args << '--' << @page_file_dir if @page_file_dir results = {} @repo.git.grep(*args).split("\n").each do |line| result = line.split(':') result_1 = result[1] file_name = result_1.chomp(::File.extname(result_1)) results[file_name] = result[2].to_i end # Use git ls-files '*query*' to search for file names. Grep only searches file content. # Spaces are converted to dashes when saving pages to disk. @repo.git.ls_files({}, "*#{ query.gsub(' ', '-') }*").split("\n").each do |line| file_name = line.chomp(::File.extname(line)) # If there's not already a result for file_name then # the value is nil and nil.to_i is 0. results[file_name] = results[file_name].to_i + 1; end results.map do |key,val| { :count => val, :name => key } end end |
#size(ref = nil) ⇒ Object
Public: Returns the number of pages accessible from a commit
ref - A String ref that is either a commit SHA or references one.
Returns a Fixnum
476 477 478 479 480 481 482 |
# File 'lib/gollum/wiki.rb', line 476 def size(ref = nil) tree_map_for(ref || @ref).inject(0) do |num, entry| num + (@page_class.valid_page_name?(entry.name) ? 1 : 0) end rescue Grit::GitRuby::Repository::NoSuchShaFound 0 end |
#tree_list(ref) ⇒ Object
Fill an array with a list of pages.
ref - A String ref that is either a commit SHA or references one.
Returns a flat Array of Gollum::Page instances.
610 611 612 613 614 615 616 617 618 619 620 |
# File 'lib/gollum/wiki.rb', line 610 def tree_list(ref) if sha = @access.ref_to_sha(ref) commit = @access.commit(sha) tree_map_for(sha).inject([]) do |list, entry| next list unless @page_class.valid_page_name?(entry.name) list << entry.page(self, commit) end else [] end end |
#tree_map_for(ref, ignore_page_file_dir = false) ⇒ Object
Finds a full listing of files and their blob SHA for a given ref. Each listing is cached based on its actual commit SHA.
ref - A String ref that is either a commit SHA or references one. ignore_page_file_dir - Boolean, if true, searches all files within the git repo, regardless of dir/subdir
Returns an Array of BlobEntry instances.
701 702 703 704 705 706 707 708 709 710 |
# File 'lib/gollum/wiki.rb', line 701 def tree_map_for(ref, ignore_page_file_dir=false) if ignore_page_file_dir && !@page_file_dir.nil? @root_access ||= GitAccess.new(path, nil, @repo_is_bare) @root_access.tree(ref) else @access.tree(ref) end rescue Grit::GitRuby::Repository::NoSuchShaFound [] end |
#update_page(page, name, format, data, commit = {}) ⇒ Object
Public: Update an existing page with new content. The location of the page inside the repository will not change. If the given format is different than the current format of the page, the filename will be changed to reflect the new format.
page - The Gollum::Page to update. name - The String extension-less name of the page. format - The Symbol format of the page. data - The new String contents of the page. commit - The commit Hash details:
:message - The String commit message.
:name - The String author full name.
:email - The String email address.
:parent - Optional Grit::Commit parent to this update.
:tree - Optional String SHA of the tree to create the
index from.
:committer - Optional Gollum::Committer instance. If provided,
assume that this operation is part of batch of
updates and the commit happens later.
Returns the String SHA1 of the newly written version, or the Gollum::Committer instance if this is part of a batch update.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'lib/gollum/wiki.rb', line 306 def update_page(page, name, format, data, commit = {}) name ||= page.name format ||= page.format dir = ::File.dirname(page.path) dir = '' if dir == '.' filename = (rename = page.name != name) ? Gollum::Page.cname(name) : page.filename_stripped multi_commit = false committer = if obj = commit[:committer] multi_commit = true obj else Committer.new(self, commit) end if !rename && page.format == format committer.add(page.path, normalize(data)) else committer.delete(page.path) committer.add_to_index(dir, filename, format, data, :allow_same_ext) end committer.after_commit do |index, sha| @access.refresh index.update_working_dir(dir, page.filename_stripped, page.format) index.update_working_dir(dir, filename, format) end multi_commit ? committer : committer.commit end |
#write_page(name, format, data, commit = {}) ⇒ Object
Public: Write a new version of a page to the Gollum repo root.
name - The String name of the page. format - The Symbol format of the page. data - The new String contents of the page. commit - The commit Hash details:
:message - The String commit message.
:name - The String author full name.
:email - The String email address.
:parent - Optional Grit::Commit parent to this update.
:tree - Optional String SHA of the tree to create the
index from.
:committer - Optional Gollum::Committer instance. If provided,
assume that this operation is part of batch of
updates and the commit happens later.
Returns the String SHA1 of the newly written version, or the Gollum::Committer instance if this is part of a batch update.
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/gollum/wiki.rb', line 262 def write_page(name, format, data, commit = {}) multi_commit = false committer = if obj = commit[:committer] multi_commit = true obj else Committer.new(self, commit) end filename = Gollum::Page.cname(name) committer.add_to_index('', filename, format, data) committer.after_commit do |index, sha| @access.refresh index.update_working_dir('', filename, format) end multi_commit ? committer : committer.commit end |