gollum-lib 3.0.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of gollum-lib might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +7 -7
- data/gollum-lib.gemspec +17 -15
- data/lib/gollum-lib.rb +10 -11
- data/lib/gollum-lib/blob_entry.rb +4 -4
- data/lib/gollum-lib/committer.rb +7 -7
- data/lib/gollum-lib/file.rb +3 -3
- data/lib/gollum-lib/filter/code.rb +5 -1
- data/lib/gollum-lib/filter/macro.rb +56 -0
- data/lib/gollum-lib/filter/tags.rb +70 -43
- data/lib/gollum-lib/filter/toc.rb +98 -47
- data/lib/gollum-lib/filter/wsd.rb +1 -1
- data/lib/gollum-lib/git_access.rb +6 -12
- data/lib/gollum-lib/macro.rb +43 -0
- data/lib/gollum-lib/macro/all_pages.rb +11 -0
- data/lib/gollum-lib/markup.rb +5 -1
- data/lib/gollum-lib/page.rb +25 -25
- data/lib/gollum-lib/wiki.rb +61 -42
- metadata +30 -28
- data/lib/gollum-lib/grit_ext.rb +0 -20
@@ -1,61 +1,112 @@
|
|
1
1
|
# Inserts header anchors and creates TOC
|
2
2
|
class Gollum::Filter::TOC < Gollum::Filter
|
3
|
-
def extract(
|
4
|
-
|
3
|
+
def extract(data)
|
4
|
+
data
|
5
5
|
end
|
6
6
|
|
7
7
|
def process(data)
|
8
|
-
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
9
|
-
toc = nil
|
10
|
-
anchor_names = {}
|
11
|
-
|
12
|
-
doc.css('h1,h2,h3,h4,h5,h6').each do |h|
|
13
|
-
# must escape "
|
14
|
-
h_name = h.content.gsub(' ', '-').gsub('"', '%22')
|
15
|
-
|
16
|
-
# Ensure repeat anchors have a unique prefix or the
|
17
|
-
# toc will break
|
18
|
-
anchor_names[h_name] = 0 if anchor_names[h_name].nil?
|
19
|
-
anchor_names[h_name] += 1
|
20
|
-
|
21
|
-
anchor_prefix_number = anchor_names[h_name]
|
22
|
-
if anchor_prefix_number > 1
|
23
|
-
h_name = anchor_prefix_number.to_s + '-' + h_name
|
24
|
-
end
|
25
|
-
|
26
|
-
level = h.name.gsub(/[hH]/, '').to_i
|
27
8
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
9
|
+
@doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
10
|
+
@toc = nil
|
11
|
+
@anchor_names = {}
|
12
|
+
@current_ancestors = ""
|
32
13
|
|
33
|
-
|
34
|
-
toc
|
35
|
-
|
36
|
-
|
14
|
+
if @markup.sub_page && @markup.parent_page
|
15
|
+
@toc = @markup.parent_page.toc_data
|
16
|
+
else
|
17
|
+
@doc.css('h1,h2,h3,h4,h5,h6').each_with_index do |header, i|
|
18
|
+
next if header.content.empty?
|
19
|
+
# omit the first H1 (the page title) from the TOC if so configured
|
20
|
+
next if (i == 0 && header.name =~ /[Hh]1/) && @markup.wiki && @markup.wiki.h1_title
|
37
21
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
while tail_level > level
|
44
|
-
tail = tail.parent
|
45
|
-
tail_level -= 1
|
22
|
+
anchor_name = generate_anchor_name(header)
|
23
|
+
|
24
|
+
add_anchor_to_header header, anchor_name
|
25
|
+
add_entry_to_toc header, anchor_name
|
46
26
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
27
|
+
|
28
|
+
@toc = @toc.to_xml(@markup.to_xml_opts) if @toc != nil
|
29
|
+
data = @doc.to_xml(@markup.to_xml_opts)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
@markup.toc = @toc
|
34
|
+
data.gsub("[[_TOC_]]") do
|
35
|
+
@toc.nil? ? '' : @toc
|
51
36
|
end
|
37
|
+
end
|
52
38
|
|
53
|
-
|
54
|
-
data = doc.to_xml(@markup.to_xml_opts)
|
39
|
+
private
|
55
40
|
|
56
|
-
|
57
|
-
|
58
|
-
|
41
|
+
# Generates the anchor name from the given header element
|
42
|
+
# removing all non alphanumeric characters, replacing them
|
43
|
+
# with single dashes.
|
44
|
+
#
|
45
|
+
# Generates heading ancestry prefixing the headings
|
46
|
+
# ancestor names to the generated name.
|
47
|
+
#
|
48
|
+
# Prefixes duplicate anchors with an index
|
49
|
+
def generate_anchor_name(header)
|
50
|
+
name = header.content
|
51
|
+
level = header.name.gsub(/[hH]/, '').to_i
|
52
|
+
|
53
|
+
# normalize the header name
|
54
|
+
name.gsub!(/[^\d\w\u00C0-\u1FFF\u2C00-\uD7FF]/, "-")
|
55
|
+
name.gsub!(/-+/, "-")
|
56
|
+
name.gsub!(/^-/, "")
|
57
|
+
name.gsub!(/-$/, "")
|
58
|
+
name.downcase!
|
59
|
+
|
60
|
+
anchor_name = name
|
61
|
+
|
62
|
+
# Set and/or add the ancestors to the name
|
63
|
+
@current_ancestors = name if level == 1
|
64
|
+
anchor_name = (level == 1) ? name : "#{@current_ancestors}_#{name}"
|
65
|
+
@current_ancestors+= "_#{name}" if level > 1
|
66
|
+
|
67
|
+
# Ensure duplicate anchors have a unique prefix or the toc will break
|
68
|
+
index = increment_anchor_index(anchor_name)
|
69
|
+
anchor_name = "#{index}-#{anchor_name}" unless index.zero? # if the index is zero this name is unique
|
70
|
+
|
71
|
+
anchor_name
|
72
|
+
end
|
73
|
+
|
74
|
+
# Creates an anchor element with the given name and adds it before
|
75
|
+
# the given header element.
|
76
|
+
def add_anchor_to_header(header, name)
|
77
|
+
anchor_element = %Q(<a class="anchor" id="#{name}" href="##{name}"><i class="fa fa-link"></i></a>)
|
78
|
+
header.children.before anchor_element # Add anchor element before the header
|
79
|
+
end
|
80
|
+
|
81
|
+
# Adds an entry to the TOC for the given header. The generated entry
|
82
|
+
# is a link to the given anchor name
|
83
|
+
def add_entry_to_toc(header, name)
|
84
|
+
@toc ||= Nokogiri::XML::DocumentFragment.parse('<div class="toc"><div class="toc-title">Table of Contents</div></div>')
|
85
|
+
tail ||= @toc.child
|
86
|
+
tail_level ||= 0
|
87
|
+
|
88
|
+
level = header.name.gsub(/[hH]/, '').to_i
|
89
|
+
|
90
|
+
while tail_level < level
|
91
|
+
node = Nokogiri::XML::Node.new('ul', @doc)
|
92
|
+
tail = tail.add_child(node)
|
93
|
+
tail_level += 1
|
59
94
|
end
|
95
|
+
|
96
|
+
while tail_level > level
|
97
|
+
tail = tail.parent
|
98
|
+
tail_level -= 1
|
99
|
+
end
|
100
|
+
node = Nokogiri::XML::Node.new('li', @doc)
|
101
|
+
# % -> %25 so anchors work on Firefox. See issue #475
|
102
|
+
node.add_child(%Q{<a href="##{name}">#{header.content}</a>})
|
103
|
+
tail.add_child(node)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Increments the number of anchors with the given name
|
107
|
+
# and returns the current index
|
108
|
+
def increment_anchor_index(name)
|
109
|
+
@anchor_names = {} if @anchor_names.nil?
|
110
|
+
@anchor_names[name].nil? ? @anchor_names[name] = 0 : @anchor_names[name] += 1
|
60
111
|
end
|
61
|
-
end
|
112
|
+
end
|
@@ -44,7 +44,7 @@ class Gollum::Filter::WSD < Gollum::Filter
|
|
44
44
|
def render_wsd(code, style)
|
45
45
|
response = Net::HTTP.post_form(URI.parse(WSD_URL), 'style' => style, 'message' => code)
|
46
46
|
if response.body =~ /img: "(.+)"/
|
47
|
-
url = "
|
47
|
+
url = "//www.websequencediagrams.com/#{$1}"
|
48
48
|
"<img src=\"#{url}\" />"
|
49
49
|
else
|
50
50
|
puts response.body
|
@@ -13,13 +13,7 @@ module Gollum
|
|
13
13
|
def initialize(path, page_file_dir = nil, bare = false)
|
14
14
|
@page_file_dir = page_file_dir
|
15
15
|
@path = path
|
16
|
-
|
17
|
-
@repo = Grit::Repo.new(path, { :is_bare => bare })
|
18
|
-
rescue Grit::InvalidGitRepositoryError
|
19
|
-
raise Gollum::InvalidGitRepositoryError
|
20
|
-
rescue Grit::NoSuchPathError
|
21
|
-
raise Gollum::NoSuchPathError
|
22
|
-
end
|
16
|
+
@repo = Gollum::Git::Repo.new(path, { :is_bare => bare })
|
23
17
|
clear
|
24
18
|
end
|
25
19
|
|
@@ -75,7 +69,7 @@ module Gollum
|
|
75
69
|
#
|
76
70
|
# ref - A String Git SHA or ref.
|
77
71
|
#
|
78
|
-
# Returns a
|
72
|
+
# Returns a Gollum::Git::Commit.
|
79
73
|
def commit(ref)
|
80
74
|
if sha?(ref)
|
81
75
|
get_cache(:commit, ref) { commit!(ref) }
|
@@ -117,7 +111,7 @@ module Gollum
|
|
117
111
|
# Gets the String path to the Git repository.
|
118
112
|
attr_reader :path
|
119
113
|
|
120
|
-
# Gets the
|
114
|
+
# Gets the Gollum::Git::Repo instance for the Git repository.
|
121
115
|
attr_reader :repo
|
122
116
|
|
123
117
|
# Gets a Hash cache of refs to commit SHAs.
|
@@ -132,9 +126,9 @@ module Gollum
|
|
132
126
|
#
|
133
127
|
attr_reader :tree_map
|
134
128
|
|
135
|
-
# Gets a Hash cache of commit SHAs to the
|
129
|
+
# Gets a Hash cache of commit SHAs to the Gollum::Git::Commit instance.
|
136
130
|
#
|
137
|
-
# {"abcd123" => <
|
131
|
+
# {"abcd123" => <Gollum::Git::Commit>}
|
138
132
|
#
|
139
133
|
attr_reader :commit_map
|
140
134
|
|
@@ -191,7 +185,7 @@ module Gollum
|
|
191
185
|
#
|
192
186
|
# sha - The string SHA of the Git commit.
|
193
187
|
#
|
194
|
-
# Returns a
|
188
|
+
# Returns a Gollum::Git::Commit.
|
195
189
|
def commit!(sha)
|
196
190
|
@repo.commit(sha)
|
197
191
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Gollum
|
2
|
+
class Macro
|
3
|
+
# Find the macro named, create an instance of that, and return it
|
4
|
+
def self.instance(macro_name, wiki, page)
|
5
|
+
begin
|
6
|
+
self.const_get(macro_name).new(wiki, page)
|
7
|
+
rescue NameError
|
8
|
+
Unknown_Macro.new(macro_name)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(wiki, page)
|
13
|
+
@wiki = wiki
|
14
|
+
@page = page
|
15
|
+
end
|
16
|
+
|
17
|
+
def render(*_args)
|
18
|
+
raise ArgumentError,
|
19
|
+
"#{self.class} does not implement #render. "+
|
20
|
+
"This is a bug in #{self.class}."
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
def html_error(s)
|
25
|
+
"<p class=\"gollum-error\">#{s}</p>"
|
26
|
+
end
|
27
|
+
|
28
|
+
# The special class we reserve for only the finest of screwups. The
|
29
|
+
# underscore is to make sure nobody can define a real, callable macro
|
30
|
+
# with the same name, because that would be... exciting.
|
31
|
+
class Unknown_Macro < Macro
|
32
|
+
def initialize(macro_name)
|
33
|
+
@macro_name = macro_name
|
34
|
+
end
|
35
|
+
|
36
|
+
def render(*_args)
|
37
|
+
"!!!Unknown macro: #{@macro_name}!!!"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Dir[File.expand_path('../macro/*.rb', __FILE__)].each { |f| require f }
|
data/lib/gollum-lib/markup.rb
CHANGED
@@ -53,6 +53,9 @@ module Gollum
|
|
53
53
|
attr_reader :sanitize
|
54
54
|
attr_reader :format
|
55
55
|
attr_reader :wiki
|
56
|
+
attr_reader :page
|
57
|
+
attr_reader :parent_page
|
58
|
+
attr_reader :sub_page
|
56
59
|
attr_reader :name
|
57
60
|
attr_reader :include_levels
|
58
61
|
attr_reader :to_xml_opts
|
@@ -72,6 +75,7 @@ module Gollum
|
|
72
75
|
@format = page.format
|
73
76
|
@sub_page = page.sub_page
|
74
77
|
@parent_page = page.parent_page
|
78
|
+
@page = page
|
75
79
|
@dir = ::File.dirname(page.path)
|
76
80
|
end
|
77
81
|
@metadata = nil
|
@@ -105,7 +109,7 @@ module Gollum
|
|
105
109
|
# filter_chain - the chain to process
|
106
110
|
#
|
107
111
|
# Returns the formatted data
|
108
|
-
def process_chain
|
112
|
+
def process_chain(data, filter_chain)
|
109
113
|
# First we extract the data through the chain...
|
110
114
|
filter_chain.each do |filter|
|
111
115
|
data = filter.extract(data)
|
data/lib/gollum-lib/page.rb
CHANGED
@@ -84,10 +84,11 @@ module Gollum
|
|
84
84
|
#
|
85
85
|
# Returns a newly initialized Gollum::Page.
|
86
86
|
def initialize(wiki)
|
87
|
-
@wiki
|
88
|
-
@blob
|
89
|
-
@
|
90
|
-
@
|
87
|
+
@wiki = wiki
|
88
|
+
@blob = @header = @footer = @sidebar = nil
|
89
|
+
@formatted_data = nil
|
90
|
+
@doc = nil
|
91
|
+
@parent_page = nil
|
91
92
|
end
|
92
93
|
|
93
94
|
# Public: The on-disk filename of the page including extension.
|
@@ -216,10 +217,18 @@ module Gollum
|
|
216
217
|
#
|
217
218
|
# Returns the String data.
|
218
219
|
def formatted_data(encoding = nil, include_levels = 10, &block)
|
219
|
-
|
220
|
-
|
221
|
-
|
220
|
+
return nil unless @blob
|
221
|
+
|
222
|
+
if @formatted_data && @doc then
|
223
|
+
yield @doc if block_given?
|
224
|
+
else
|
225
|
+
@formatted_data = markup_class.render(historical?, encoding, include_levels) do |doc|
|
226
|
+
@doc = doc
|
227
|
+
yield doc if block_given?
|
228
|
+
end
|
222
229
|
end
|
230
|
+
|
231
|
+
@formatted_data
|
223
232
|
end
|
224
233
|
|
225
234
|
# Public: The table of contents of the page.
|
@@ -257,7 +266,7 @@ module Gollum
|
|
257
266
|
|
258
267
|
# Public: The current version of the page.
|
259
268
|
#
|
260
|
-
# Returns the
|
269
|
+
# Returns the Gollum::Git::Commit.
|
261
270
|
attr_reader :version
|
262
271
|
|
263
272
|
# Public: All of the versions that have touched the Page.
|
@@ -265,20 +274,11 @@ module Gollum
|
|
265
274
|
# options - The options Hash:
|
266
275
|
# :page - The Integer page number (default: 1).
|
267
276
|
# :per_page - The Integer max count of items to return.
|
268
|
-
# :follow - Follow's a file across renames,
|
269
|
-
# to a slower Grit native call (implicit in repo.git.log). (default: false)
|
277
|
+
# :follow - Follow's a file across renames, slower. (default: false)
|
270
278
|
#
|
271
|
-
# Returns an Array of
|
279
|
+
# Returns an Array of Gollum::Git::Commit.
|
272
280
|
def versions(options = {})
|
273
|
-
|
274
|
-
options[:pretty] = 'raw'
|
275
|
-
options.delete :max_count
|
276
|
-
options.delete :skip
|
277
|
-
log = @wiki.repo.git.log(options, @wiki.ref, "--", @path)
|
278
|
-
Grit::Commit.list_from_string(@wiki.repo, log)
|
279
|
-
else
|
280
|
-
@wiki.repo.log(@wiki.ref, @path, log_pagination_options(options))
|
281
|
-
end
|
281
|
+
@wiki.repo.git.versions_for_path(@path, @wiki.ref, log_pagination_options(options))
|
282
282
|
end
|
283
283
|
|
284
284
|
# Public: The first 7 characters of the current version.
|
@@ -365,7 +365,7 @@ module Gollum
|
|
365
365
|
# Returns the Gollum::Wiki containing the page.
|
366
366
|
attr_reader :wiki
|
367
367
|
|
368
|
-
# Set the
|
368
|
+
# Set the Gollum::Git::Commit version of the page.
|
369
369
|
#
|
370
370
|
# Returns nothing.
|
371
371
|
attr_writer :version
|
@@ -379,12 +379,12 @@ module Gollum
|
|
379
379
|
def find(name, version, dir = nil, exact = false)
|
380
380
|
map = @wiki.tree_map_for(version.to_s)
|
381
381
|
if page = find_page_in_tree(map, name, dir, exact)
|
382
|
-
page.version = version.is_a?(
|
382
|
+
page.version = version.is_a?(Gollum::Git::Commit) ?
|
383
383
|
version : @wiki.commit_for(version)
|
384
384
|
page.historical = page.version.to_s == version.to_s
|
385
385
|
page
|
386
386
|
end
|
387
|
-
rescue
|
387
|
+
rescue Gollum::Git::NoSuchShaFound
|
388
388
|
end
|
389
389
|
|
390
390
|
# Find a page in a given tree.
|
@@ -414,7 +414,7 @@ module Gollum
|
|
414
414
|
|
415
415
|
# Populate the Page with information from the Blob.
|
416
416
|
#
|
417
|
-
# blob - The
|
417
|
+
# blob - The Gollum::Git::Blob that contains the info.
|
418
418
|
# path - The String directory path of the page file.
|
419
419
|
#
|
420
420
|
# Returns the populated Gollum::Page.
|
@@ -427,7 +427,7 @@ module Gollum
|
|
427
427
|
# The full directory path for the given tree.
|
428
428
|
#
|
429
429
|
# treemap - The Hash treemap containing parentage information.
|
430
|
-
# tree - The
|
430
|
+
# tree - The Gollum::Git::Tree for which to compute the path.
|
431
431
|
#
|
432
432
|
# Returns the String path.
|
433
433
|
def tree_path(treemap, tree)
|
data/lib/gollum-lib/wiki.rb
CHANGED
@@ -14,16 +14,16 @@ module Gollum
|
|
14
14
|
attr_writer :markup_classes
|
15
15
|
|
16
16
|
# Sets the default ref for the wiki.
|
17
|
-
|
17
|
+
attr_writer :default_ref
|
18
18
|
|
19
19
|
# Sets the default name for commits.
|
20
|
-
|
20
|
+
attr_writer :default_committer_name
|
21
21
|
|
22
22
|
# Sets the default email for commits.
|
23
|
-
|
23
|
+
attr_writer :default_committer_email
|
24
24
|
|
25
25
|
# Array of chars to substitute whitespace for when trying to locate file in git repo.
|
26
|
-
|
26
|
+
attr_writer :default_ws_subs
|
27
27
|
|
28
28
|
# Sets sanitization options. Set to false to deactivate
|
29
29
|
# sanitization altogether.
|
@@ -35,7 +35,7 @@ module Gollum
|
|
35
35
|
|
36
36
|
# Hash for setting different default wiki options
|
37
37
|
# These defaults can be overridden by options passed directly to initialize()
|
38
|
-
|
38
|
+
attr_writer :default_options
|
39
39
|
|
40
40
|
# Gets the page class used by all instances of this Wiki.
|
41
41
|
# Default: Gollum::Page.
|
@@ -105,14 +105,27 @@ module Gollum
|
|
105
105
|
end
|
106
106
|
@history_sanitization
|
107
107
|
end
|
108
|
-
end
|
109
108
|
|
110
|
-
|
111
|
-
|
112
|
-
|
109
|
+
def default_ref
|
110
|
+
@default_ref || 'master'
|
111
|
+
end
|
113
112
|
|
114
|
-
|
115
|
-
|
113
|
+
def default_committer_name
|
114
|
+
@default_committer_name || 'Anonymous'
|
115
|
+
end
|
116
|
+
|
117
|
+
def default_committer_email
|
118
|
+
@default_committer_email || 'anon@anon.com'
|
119
|
+
end
|
120
|
+
|
121
|
+
def default_ws_subs
|
122
|
+
@default_ws_subs || ['_', '-']
|
123
|
+
end
|
124
|
+
|
125
|
+
def default_options
|
126
|
+
@default_options || {}
|
127
|
+
end
|
128
|
+
end
|
116
129
|
|
117
130
|
# The String base path to prefix to internal links. For example, when set
|
118
131
|
# to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults
|
@@ -235,7 +248,7 @@ module Gollum
|
|
235
248
|
@allow_uploads = options.fetch :allow_uploads, false
|
236
249
|
@per_page_uploads = options.fetch :per_page_uploads, false
|
237
250
|
@filter_chain = options.fetch :filter_chain,
|
238
|
-
[:Metadata, :PlainText, :TOC, :RemoteCode, :Code, :Sanitize, :WSD, :Tags, :Render]
|
251
|
+
[:Metadata, :PlainText, :TOC, :RemoteCode, :Code, :Macro, :Sanitize, :WSD, :Tags, :Render]
|
239
252
|
end
|
240
253
|
|
241
254
|
# Public: check whether the wiki's git repo exists on the filesystem.
|
@@ -310,7 +323,7 @@ module Gollum
|
|
310
323
|
# :message - The String commit message.
|
311
324
|
# :name - The String author full name.
|
312
325
|
# :email - The String email address.
|
313
|
-
# :parent - Optional
|
326
|
+
# :parent - Optional Gollum::Git::Commit parent to this update.
|
314
327
|
# :tree - Optional String SHA of the tree to create the
|
315
328
|
# index from.
|
316
329
|
# :committer - Optional Gollum::Committer instance. If provided,
|
@@ -322,19 +335,19 @@ module Gollum
|
|
322
335
|
# Gollum::Committer instance if this is part of a batch update.
|
323
336
|
def write_page(name, format, data, commit = {}, dir = '')
|
324
337
|
# spaces must be dashes
|
325
|
-
name.gsub
|
326
|
-
dir.gsub
|
338
|
+
sanitized_name = name.gsub(' ', '-')
|
339
|
+
sanitized_dir = dir.gsub(' ', '-')
|
327
340
|
|
328
341
|
multi_commit = !!commit[:committer]
|
329
342
|
committer = multi_commit ? commit[:committer] : Committer.new(self, commit)
|
330
343
|
|
331
|
-
filename = Gollum::Page.cname(
|
344
|
+
filename = Gollum::Page.cname(sanitized_name)
|
332
345
|
|
333
|
-
committer.add_to_index(
|
346
|
+
committer.add_to_index(sanitized_dir, filename, format, data)
|
334
347
|
|
335
348
|
committer.after_commit do |index, sha|
|
336
349
|
@access.refresh
|
337
|
-
index.update_working_dir(
|
350
|
+
index.update_working_dir(sanitized_dir, filename, format)
|
338
351
|
end
|
339
352
|
|
340
353
|
multi_commit ? committer : committer.commit
|
@@ -348,7 +361,7 @@ module Gollum
|
|
348
361
|
# :message - The String commit message.
|
349
362
|
# :name - The String author full name.
|
350
363
|
# :email - The String email address.
|
351
|
-
# :parent - Optional
|
364
|
+
# :parent - Optional Gollum::Git::Commit parent to this update.
|
352
365
|
# :tree - Optional String SHA of the tree to create the
|
353
366
|
# index from.
|
354
367
|
# :committer - Optional Gollum::Committer instance. If provided,
|
@@ -404,7 +417,7 @@ module Gollum
|
|
404
417
|
# :message - The String commit message.
|
405
418
|
# :name - The String author full name.
|
406
419
|
# :email - The String email address.
|
407
|
-
# :parent - Optional
|
420
|
+
# :parent - Optional Gollum::Git::Commit parent to this update.
|
408
421
|
# :tree - Optional String SHA of the tree to create the
|
409
422
|
# index from.
|
410
423
|
# :committer - Optional Gollum::Committer instance. If provided,
|
@@ -447,7 +460,7 @@ module Gollum
|
|
447
460
|
# :message - The String commit message.
|
448
461
|
# :name - The String author full name.
|
449
462
|
# :email - The String email address.
|
450
|
-
# :parent - Optional
|
463
|
+
# :parent - Optional Gollum::Git::Commit parent to this update.
|
451
464
|
# :tree - Optional String SHA of the tree to create the
|
452
465
|
# index from.
|
453
466
|
# :committer - Optional Gollum::Committer instance. If provided,
|
@@ -486,7 +499,7 @@ module Gollum
|
|
486
499
|
# :message - The String commit message.
|
487
500
|
# :name - The String author full name.
|
488
501
|
# :email - The String email address.
|
489
|
-
# :parent - Optional
|
502
|
+
# :parent - Optional Gollum::Git::Commit parent to this update.
|
490
503
|
#
|
491
504
|
# Returns a String SHA1 of the new commit, or nil if the reverse diff does
|
492
505
|
# not apply.
|
@@ -576,7 +589,7 @@ module Gollum
|
|
576
589
|
tree_map_for(ref || @ref).inject(0) do |num, entry|
|
577
590
|
num + (@page_class.valid_page_name?(entry.name) ? 1 : 0)
|
578
591
|
end
|
579
|
-
rescue
|
592
|
+
rescue Gollum::Git::NoSuchShaFound
|
580
593
|
0
|
581
594
|
end
|
582
595
|
|
@@ -586,27 +599,22 @@ module Gollum
|
|
586
599
|
#
|
587
600
|
# Returns an Array with Objects of page name and count of matches
|
588
601
|
def search(query)
|
589
|
-
|
590
|
-
args << '--' << @page_file_dir if @page_file_dir
|
591
|
-
|
602
|
+
options = {:path => page_file_dir, :ref => ref}
|
592
603
|
results = {}
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
result_1 = result[1]
|
604
|
+
@repo.git.grep(query, options).each do |hit|
|
605
|
+
name = hit[:name]
|
606
|
+
count = hit[:count]
|
597
607
|
# Remove ext only from known extensions.
|
598
608
|
# test.pdf => test.pdf, test.md => test
|
599
|
-
file_name
|
600
|
-
|
601
|
-
results[file_name] = result[2].to_i
|
609
|
+
file_name = Page::valid_page_name?(name) ? name.chomp(::File.extname(name)) : name
|
610
|
+
results[file_name] = count
|
602
611
|
end
|
603
612
|
|
604
613
|
# Use git ls-files '*query*' to search for file names. Grep only searches file content.
|
605
614
|
# Spaces are converted to dashes when saving pages to disk.
|
606
|
-
@repo.git.ls_files(
|
615
|
+
@repo.git.ls_files(query.gsub(' ','-'), options).each do |path|
|
607
616
|
# Remove ext only from known extensions.
|
608
|
-
file_name = Page::valid_page_name?(
|
609
|
-
line
|
617
|
+
file_name = Page::valid_page_name?(path) ? path.chomp(::File.extname(path)) : path
|
610
618
|
# If there's not already a result for file_name then
|
611
619
|
# the value is nil and nil.to_i is 0.
|
612
620
|
results[file_name] = results[file_name].to_i + 1;
|
@@ -623,11 +631,22 @@ module Gollum
|
|
623
631
|
# :page - The Integer page number (default: 1).
|
624
632
|
# :per_page - The Integer max count of items to return.
|
625
633
|
#
|
626
|
-
# Returns an Array of
|
634
|
+
# Returns an Array of Gollum::Git::Commit.
|
627
635
|
def log(options = {})
|
628
636
|
@repo.log(@ref, nil, log_pagination_options(options))
|
629
637
|
end
|
630
638
|
|
639
|
+
# Returns the latest changes in the wiki (globally)
|
640
|
+
#
|
641
|
+
# options - The options Hash:
|
642
|
+
# :max_count - The Integer number of items to return.
|
643
|
+
#
|
644
|
+
# Returns an Array of Gollum::Git::Commit.
|
645
|
+
def latest_changes(options={})
|
646
|
+
max_count = options.fetch(:max_count, 10)
|
647
|
+
@repo.log(@ref, nil, options)
|
648
|
+
end
|
649
|
+
|
631
650
|
# Public: Refreshes just the cached Git reference data. This should
|
632
651
|
# be called after every Gollum update.
|
633
652
|
#
|
@@ -730,9 +749,9 @@ module Gollum
|
|
730
749
|
#
|
731
750
|
#########################################################################
|
732
751
|
|
733
|
-
# The
|
752
|
+
# The Gollum::Git::Repo associated with the wiki.
|
734
753
|
#
|
735
|
-
# Returns the
|
754
|
+
# Returns the Gollum::Git::Repo.
|
736
755
|
attr_reader :repo
|
737
756
|
|
738
757
|
# The String path to the Git repository that holds the Gollum site.
|
@@ -874,10 +893,10 @@ module Gollum
|
|
874
893
|
#
|
875
894
|
# ref - A string ref or SHA pointing to a valid commit.
|
876
895
|
#
|
877
|
-
# Returns a
|
896
|
+
# Returns a Gollum::Git::Commit instance.
|
878
897
|
def commit_for(ref)
|
879
898
|
@access.commit(ref)
|
880
|
-
rescue
|
899
|
+
rescue Gollum::Git::NoSuchShaFound
|
881
900
|
end
|
882
901
|
|
883
902
|
# Finds a full listing of files and their blob SHA for a given ref. Each
|
@@ -894,7 +913,7 @@ module Gollum
|
|
894
913
|
else
|
895
914
|
@access.tree(ref)
|
896
915
|
end
|
897
|
-
rescue
|
916
|
+
rescue Gollum::Git::NoSuchShaFound
|
898
917
|
[]
|
899
918
|
end
|
900
919
|
|