Class: Gollum::Wiki

Inherits:
Object
  • Object
show all
Includes:
Pagination
Defined in:
lib/gollum-lib/wiki.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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
:base_path     - String base path for all Wiki links.
                 Default: "/"
:page_file_dir - String the directory in which all page files reside
:ref - String the repository ref to retrieve pages from
:mathjax       - Set to false to disable mathjax.
:user_icons    - Enable user icons on the history page. [gravatar, identicon, none].
                 Default: none
:global_tag_lookup        - Enable 4.x compatibility behavior for links
:hyphened_tag_lookup - Spaces in tag paths are treated as dashes (-)
:case_insensitive_tag_lookup - Paths in tags are compared case_insensitively
:css           - Include the custom.css file from the repo.
:emoji         - Parse and interpret emoji tags (e.g. :heart:).
:h1_title      - Concatenate all h1's on a page to form the
                 page title.
:display_metadata - Whether or not to render a page's metadata on the page. Default: true
:index_page    - The default page to retrieve or create if the
                 a directory is accessed.
:bar_side      - Where the sidebar should be displayed, may be:
                  - :left
                  - :right
:allow_uploads - Set to true to allow file uploads.
:per_page_uploads - Whether uploads should be stored in a central
                 'uploads' directory, or in a directory named for
                 the page they were uploaded to.
:filter_chain  - Override the default filter chain with your own.

Returns a fresh Gollum::Repo.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/gollum-lib/wiki.rb', line 116

def initialize(path, options = {})
  options = self.class.default_options.merge(options)
  if path.is_a?(GitAccess)
    options[:access] = path
    path             = path.path
  end

  @path                 = path
  @repo_is_bare         = options.fetch :repo_is_bare, nil
  @page_file_dir        = options.fetch :page_file_dir, nil
  @page_file_dir        = Pathname.new("/#{@page_file_dir}").cleanpath.to_s[1..-1] if @page_file_dir
  @access               = options.fetch :access, GitAccess.new(path, @page_file_dir, @repo_is_bare)
  @base_path            = options.fetch :base_path, "/"
  @repo                 = @access.repo
  @ref                  = options.fetch :ref, self.class.default_ref
  @universal_toc        = options.fetch :universal_toc, false
  @mathjax              = options.fetch :mathjax, false
  @global_tag_lookup    = options.fetch :global_tag_lookup, false
  @hyphened_tag_lookup  = options.fetch :hyphened_tag_lookup, false
  @case_insensitive_tag_lookup = options.fetch :case_insensitive_tag_lookup, false
  @css                  = options.fetch :css, false
  @emoji                = options.fetch :emoji, false
  @critic_markup        = options.fetch :critic_markup, false
  @h1_title             = options.fetch :h1_title, false
  @display_metadata     = options.fetch :display_metadata, true
  @index_page           = options.fetch :index_page, 'Home'
  @bar_side             = options.fetch :sidebar, :right
  @user_icons           = ['gravatar', 'identicon'].include?(options[:user_icons]) ?
      options[:user_icons] : 'none'
  @allow_uploads        = options.fetch :allow_uploads, false
  @per_page_uploads     = options.fetch :per_page_uploads, false
  @metadata             = options.fetch :metadata, {}
  @filter_chain         = options.fetch :filter_chain,
                                        [:YAML, :BibTeX, :PlainText, :CriticMarkup, :TOC, :RemoteCode, :Code, :Macro, :Emoji, :Sanitize, :PlantUML, :Tags, :PandocBib, :Render]
  @filter_chain.delete(:Emoji) unless options.fetch :emoji, false
  @filter_chain.delete(:PandocBib) unless ::Gollum::MarkupRegisterUtils.using_pandoc?
  @filter_chain.delete(:CriticMarkup) unless options.fetch :critic_markup, false
end

Class Attribute Details

.default_committer_emailObject



30
31
32
# File 'lib/gollum-lib/wiki.rb', line 30

def default_committer_email
  @default_committer_email || '[email protected]'
end

.default_committer_nameObject



26
27
28
# File 'lib/gollum-lib/wiki.rb', line 26

def default_committer_name
  @default_committer_name || 'Anonymous'
end

.default_optionsObject



34
35
36
# File 'lib/gollum-lib/wiki.rb', line 34

def default_options
  @default_options || {}
end

.default_refObject



22
23
24
# File 'lib/gollum-lib/wiki.rb', line 22

def default_ref
  @default_ref || 'master'
end

Instance Attribute Details

#allow_uploadsObject (readonly)

Toggles file upload functionality.



603
604
605
# File 'lib/gollum-lib/wiki.rb', line 603

def allow_uploads
  @allow_uploads
end

#bar_sideObject (readonly)

Gets side on which the sidebar should be shown



72
73
74
# File 'lib/gollum-lib/wiki.rb', line 72

def bar_side
  @bar_side
end

#base_pathObject (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 “/”.



48
49
50
# File 'lib/gollum-lib/wiki.rb', line 48

def base_path
  @base_path
end

#case_insensitive_tag_lookupObject (readonly)

Enable 4.x compatibility for case-case_insensitive links



597
598
599
# File 'lib/gollum-lib/wiki.rb', line 597

def case_insensitive_tag_lookup
  @case_insensitive_tag_lookup
end

#cssObject (readonly)

Injects custom css from custom.css in root repo. Defaults to false



58
59
60
# File 'lib/gollum-lib/wiki.rb', line 58

def css
  @css
end

#display_metadataObject (readonly)

Whether or not to render a page’s metadata on the page Defaults to true



66
67
68
# File 'lib/gollum-lib/wiki.rb', line 66

def 
  @display_metadata
end

#filter_chainObject (readonly)

An array of symbols which refer to classes under Gollum::Filter, each of which is an element in the “filtering chain”. See the documentation for Gollum::Filter for more on how this chain works, and what filter classes need to implement.



78
79
80
# File 'lib/gollum-lib/wiki.rb', line 78

def filter_chain
  @filter_chain
end

#global_tag_lookupObject (readonly)

Enable 4.x compatibility behavior for links



594
595
596
# File 'lib/gollum-lib/wiki.rb', line 594

def global_tag_lookup
  @global_tag_lookup
end

#h1_titleObject (readonly)

Sets page title to value of first h1 Defaults to false



62
63
64
# File 'lib/gollum-lib/wiki.rb', line 62

def h1_title
  @h1_title
end

#hyphened_tag_lookupObject (readonly)

Spaces in tag paths are treated as dashes (-)



600
601
602
# File 'lib/gollum-lib/wiki.rb', line 600

def hyphened_tag_lookup
  @hyphened_tag_lookup
end

#index_pageObject (readonly)

Gets the custom index page for / and subdirs (e.g. foo/)



69
70
71
# File 'lib/gollum-lib/wiki.rb', line 69

def index_page
  @index_page
end

#mathjaxObject (readonly)

Toggles mathjax.



584
585
586
# File 'lib/gollum-lib/wiki.rb', line 584

def mathjax
  @mathjax
end

#metadataObject (readonly)

Global metadata to be merged into the metadata for each page



81
82
83
# File 'lib/gollum-lib/wiki.rb', line 81

def 
  @metadata
end

#page_file_dirObject (readonly)

Gets the String directory in which all page files reside.



54
55
56
# File 'lib/gollum-lib/wiki.rb', line 54

def page_file_dir
  @page_file_dir
end

#pathObject (readonly)

The String path to the Git repository that holds the Gollum site.

Returns the String path.



43
44
45
# File 'lib/gollum-lib/wiki.rb', line 43

def path
  @path
end

#per_page_uploadsObject (readonly)

Toggles whether uploaded files go into ‘uploads’, or a directory named after the page they were uploaded to.



607
608
609
# File 'lib/gollum-lib/wiki.rb', line 607

def per_page_uploads
  @per_page_uploads
end

#refObject (readonly)

Gets the String ref in which all page files reside.



51
52
53
# File 'lib/gollum-lib/wiki.rb', line 51

def ref
  @ref
end

#repoObject (readonly)

The Gollum::Git::Repo associated with the wiki.

Returns the Gollum::Git::Repo.



573
574
575
# File 'lib/gollum-lib/wiki.rb', line 573

def repo
  @repo
end

#repo_is_bareObject (readonly)

Whether or not the wiki’s repository is bare (doesn’t have a working directory)



40
41
42
# File 'lib/gollum-lib/wiki.rb', line 40

def repo_is_bare
  @repo_is_bare
end

#show_allObject (readonly)

Toggles showing all files in files view. Default is false. When false, only valid pages in the git repo are displayed.



591
592
593
# File 'lib/gollum-lib/wiki.rb', line 591

def show_all
  @show_all
end

#universal_tocObject (readonly)

Toggles display of universal table of contents



581
582
583
# File 'lib/gollum-lib/wiki.rb', line 581

def universal_toc
  @universal_toc
end

#user_iconsObject (readonly)

Toggles user icons. Default: ‘none’



587
588
589
# File 'lib/gollum-lib/wiki.rb', line 587

def user_icons
  @user_icons
end

Instance Method Details

#add_redirect(old_path, new_path) ⇒ Object



554
555
556
557
# File 'lib/gollum-lib/wiki.rb', line 554

def add_redirect(old_path, new_path)
  redirects[old_path] = new_path
  redirects.dump
end

#clear_cacheObject

Public: Refreshes just the cached Git reference data. This should be called after every Gollum update.

Returns nothing.



541
542
543
# File 'lib/gollum-lib/wiki.rb', line 541

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 Gollum::Git::Commit instance.



671
672
673
674
# File 'lib/gollum-lib/wiki.rb', line 671

def commit_for(ref)
  @access.commit(ref)
rescue Gollum::Git::NoSuchShaFound
end

#default_committer_emailObject

Gets the default email for commits.

Returns the String email address.



660
661
662
663
664
# File 'lib/gollum-lib/wiki.rb', line 660

def default_committer_email
  email = @repo.config['user.email']
  email = email.delete('<>') if email
  @default_committer_email ||= email || self.class.default_committer_email
end

#default_committer_nameObject

Gets the default name for commits.

Returns the String name.



652
653
654
655
# File 'lib/gollum-lib/wiki.rb', line 652

def default_committer_name
  @default_committer_name ||= \
    @repo.config['user.name'] || self.class.default_committer_name
end

#delete_file(path, commit) ⇒ Object

Public: Delete a file.

path - The path to the file 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 Gollum::Git::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.



397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/gollum-lib/wiki.rb', line 397

def delete_file(path, commit)
  fullpath     = ::File.join([page_file_dir, path].compact)
  multi_commit = !!commit[:committer]
  committer    = multi_commit ? commit[:committer] : Committer.new(self, commit)

  committer.delete(fullpath)

  committer.after_commit do |index, _sha|
    dir = '' if dir == '.'
    @access.refresh
    index.update_working_dir(fullpath)
  end

  multi_commit ? committer : committer.commit
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 Gollum::Git::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.



377
378
379
# File 'lib/gollum-lib/wiki.rb', line 377

def delete_page(page, commit)
  delete_file(page.url_path, 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.

Returns:

  • (Boolean)


158
159
160
# File 'lib/gollum-lib/wiki.rb', line 158

def exist?
  @access.exist?
end

#file(name, version = nil, try_on_disk = false) ⇒ 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). try_on_disk - If true, try to return just a reference to a file

that exists on the disk.

Returns a Gollum::File or nil if no matching file was found. Note that if you specify try_on_disk=true, you may or may not get a file for which on_disk? is actually true.



183
184
185
# File 'lib/gollum-lib/wiki.rb', line 183

def file(name, version = nil, try_on_disk = false)
  ::Gollum::File.find(self, name, version.nil? ? @ref : version, try_on_disk)
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.



468
469
470
# File 'lib/gollum-lib/wiki.rb', line 468

def files(treeish = nil)
  tree_list(treeish || @ref, false, true)
end

#inspectObject



694
695
696
# File 'lib/gollum-lib/wiki.rb', line 694

def inspect
  %(#<#{self.class.name}:#{object_id} #{@repo.path}>)
end

#latest_changes(options = {}) ⇒ Object

Returns the latest changes in the wiki (globally)

options - The options Hash:

:max_count  - The Integer number of items to return.

Returns an Array of Gollum::Git::Commit.



532
533
534
535
# File 'lib/gollum-lib/wiki.rb', line 532

def latest_changes(options={})
  options[:max_count] = 10 unless options[:max_count]
  @repo.log(@ref, page_file_dir, options)
end

#log(options = {}) ⇒ Object

Public: All of the versions that have touched the Page.

options - The options Hash:

:page_num  - The Integer page number (default: 1).
:per_page  - The Integer max count of items to return.

Returns an Array of Gollum::Git::Commit.



522
523
524
# File 'lib/gollum-lib/wiki.rb', line 522

def log(options = {})
  @repo.log(@ref, nil, log_pagination_options(options))
end

#normalize(data) ⇒ Object

Normalize the data.

data - The String data to be normalized.

Returns the normalized data String.



614
615
616
# File 'lib/gollum-lib/wiki.rb', line 614

def normalize(data)
  data.gsub(/\r/, '')
end

#overwrite_file(name, data, commit = {}) ⇒ Object

Public: Write a file to the Gollum repo regardless of existing versions.

path - The String path where the file will be written. 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 Gollum::Git::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



257
258
259
# File 'lib/gollum-lib/wiki.rb', line 257

def overwrite_file(name, data, commit = {})
  write(merge_path_elements(nil, name, nil), data, commit, force_overwrite = true)
end

#page(path, version = nil, global_match = false) ⇒ Object

Public: Get the formatted page for a given page name, version, and dir.

path - The String path to the the wiki page (may or may not include file extension). version - The String version ID to find (default: @ref). global_match - If true, find a File matching path’s filename, but not it’s directory (so anywhere in the repo)

Returns a Gollum::Page or nil if no matching page was found.



169
170
171
# File 'lib/gollum-lib/wiki.rb', line 169

def page(path, version = nil, global_match = false)
  ::Gollum::Page.find(self, path, version.nil? ? @ref : version, false, global_match)
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.



624
625
626
# File 'lib/gollum-lib/wiki.rb', line 624

def page_file_name(name, format)
  format.nil? ? name : "#{name}.#{::Gollum::Page.format_to_ext(format)}"
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.



459
460
461
# File 'lib/gollum-lib/wiki.rb', line 459

def pages(treeish = nil)
  tree_list(treeish || @ref, true, false)
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.



196
197
198
# File 'lib/gollum-lib/wiki.rb', line 196

def preview_page(name, data, format)
  ::Gollum::PreviewPage.new(self, "#{name}.#{::Gollum::Page.format_to_ext(format.to_sym)}", data, @access.commit(@ref))
end

#redirectsObject



545
546
547
548
549
550
551
552
# File 'lib/gollum-lib/wiki.rb', line 545

def redirects
  if @redirects.nil? || @redirects.stale?
    @redirects = {}.extend(::Gollum::Redirects)
    @redirects.init(self)
    @redirects.load
  end
  @redirects
end

#remove_redirect(path) ⇒ Object



559
560
561
562
# File 'lib/gollum-lib/wiki.rb', line 559

def remove_redirect(path)
  redirects.tap{|k| k.delete(path)}
  redirects.dump
end

#rename_page(page, rename, commit = {}) ⇒ Object

Public: Rename an existing page without altering content.

page - The Gollum::Page to update. rename - The String extension-less full path of the page (leading ‘/’ is ignored). commit - The commit Hash details:

:message   - The String commit message.
:name      - The String author full name.
:email     - The String email address.
:parent    - Optional Gollum::Git::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. Returns false if the operation is a NOOP.



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/gollum-lib/wiki.rb', line 279

def rename_page(page, rename, commit = {})
  return false if page.nil?
  return false if rename.nil? or rename.empty?

  (target_dir, target_name) = ::File.split(rename)
  (source_dir, source_name) = ::File.split(page.path)
  source_name               = page.filename_stripped

  # File.split gives us relative paths with ".", commiter.add_to_index doesn't like that.
  target_dir                = '' if target_dir == '.'
  source_dir                = '' if source_dir == '.'
  target_dir                = target_dir.gsub(/^\//, '')

  # if the rename is a NOOP, abort
  if source_dir == target_dir and source_name == target_name
    return false
  end

  multi_commit = !!commit[:committer]
  committer    = multi_commit ? commit[:committer] : Committer.new(self, commit)

  committer.delete(page.path)
  committer.add_to_index(merge_path_elements(target_dir, target_name, page.format), page.raw_data)

  committer.after_commit do |index, _sha|
    @access.refresh
    index.update_working_dir(merge_path_elements(source_dir, source_name, page.format))
    index.update_working_dir(merge_path_elements(target_dir, target_name, page.format))
  end

  multi_commit ? committer : committer.commit
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.



448
449
450
451
452
# File 'lib/gollum-lib/wiki.rb', line 448

def revert_commit(sha1, sha2 = nil, commit = {})
  left, right, options = parse_revert_options(sha1, sha2, commit)
  tree, files = repo.git.revert_commit(left, right)
  commit_and_update_paths(tree, files, options)
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 Gollum::Git::Commit parent to this update.

Returns a String SHA1 of the new commit, or nil if the reverse diff does not apply.



428
429
430
431
432
# File 'lib/gollum-lib/wiki.rb', line 428

def revert_page(page, sha1, sha2 = nil, commit = {})
  return false unless page
  left, right, options = parse_revert_options(sha1, sha2, commit)
  commit_and_update_paths(@repo.git.revert_path(page.path, left, right), [page.path], options)
end

#sanitizerObject

Public: Creates a Sanitize instance

Returns a Sanitize instance.



701
702
703
# File 'lib/gollum-lib/wiki.rb', line 701

def sanitizer
  @sanitizer ||= Gollum::Sanitization.new(Gollum::Markup.to_xml_opts)
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



490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/gollum-lib/wiki.rb', line 490

def search(query)
  options = {:path => page_file_dir, :ref => ref}
  search_terms = query.scan(/"([^"]+)"|(\S+)/).flatten.compact.map {|term| Regexp.escape(term)}
  search_terms_regex = search_terms.join('|')
  query = /^(.*(?:#{search_terms_regex}).*)$/i
  results = @repo.git.grep(search_terms, options) do |name, data|
    result = {:count => 0}
    result[:name] = extract_page_file_dir(name)
    result[:filename_count] = result[:name].scan(/#{search_terms_regex}/i).size
    result[:context] = []
    if data
      begin
        data.scan(query) do |match|
          result[:context] << match.first
          result[:count] += match.first.scan(/#{search_terms_regex}/i).size
        end
      rescue ArgumentError # https://github.com/gollum/gollum/issues/1491
        next
      end
    end
    ((result[:count] + result[:filename_count]) == 0) ? nil : result
  end
  [results, search_terms]
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



477
478
479
480
481
482
483
# File 'lib/gollum-lib/wiki.rb', line 477

def size(ref = nil)
  tree_map_for(ref || @ref).inject(0) do |num, entry|
    num + (::Gollum::Page.valid_page_name?(entry.name) ? 1 : 0)
  end
rescue Gollum::Git::NoSuchShaFound
  0
end

#tree_list(ref = @ref, pages = true, files = true) ⇒ Object

Fill an array with a list of pages and files in the wiki.

ref - A String ref that is either a commit SHA or references one.

Returns a flat Array of Gollum::Page and Gollum::File instances.



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'lib/gollum-lib/wiki.rb', line 633

def tree_list(ref = @ref, pages=true, files=true)
  if (sha = @access.ref_to_sha(ref))
    commit = @access.commit(sha)
    tree_map_for(sha).inject([]) do |list, entry|
      if ::Gollum::Page.valid_page_name?(entry.name)
        list << entry.page(self, commit) if pages
      elsif files && !entry.name.start_with?('_') && !::Gollum::Page.protected_files.include?(entry.name)
        list << entry.file(self, commit)
      end
      list
    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.



683
684
685
686
687
688
689
690
691
692
# File 'lib/gollum-lib/wiki.rb', line 683

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 Gollum::Git::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 Gollum::Git::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.



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/gollum-lib/wiki.rb', line 334

def update_page(page, name, format, data, commit = {})
  name     ||= page.name
  format   ||= page.format
  dir      = ::File.dirname(page.path)
  dir      = nil if dir == '.'
  rename   = (page.name != name || page.format != format)
  new_path = ::File.join([dir, self.page_file_name(name, format)].compact) if rename

  multi_commit = !!commit[:committer]
  committer    = multi_commit ? commit[:committer] : Committer.new(self, commit)

  if !rename
    committer.add(page.path, normalize(data))
  else
    committer.delete(page.path)
    committer.add_to_index(new_path, data)
  end

  committer.after_commit do |index, _sha|
    @access.refresh
    index.update_working_dir(page.path)
    index.update_working_dir(new_path) if rename
  end

  multi_commit ? committer : committer.commit
end

#write_file(name, data, commit = {}) ⇒ Object

Public: Write a new version of a file to the Gollum repo.

path - The String path where the file will be written. 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 Gollum::Git::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



237
238
239
# File 'lib/gollum-lib/wiki.rb', line 237

def write_file(name, data, commit = {})
  write(merge_path_elements(nil, name, nil), data, commit)
end

#write_page(path, format, data, commit = {}) ⇒ Object

Public: Write a new version of a page to the Gollum repo root.

path - The String path where the page will be written. 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 Gollum::Git::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.



217
218
219
# File 'lib/gollum-lib/wiki.rb', line 217

def write_page(path, format, data, commit = {})
 write(merge_path_elements(nil, path, format), data, commit)
end