gollum-lib 4.0.3-java → 4.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@ require 'open-uri'
6
6
 
7
7
  module Gollum
8
8
  class Gitcode
9
- def initialize path
9
+ def initialize(path)
10
10
  raise(ArgumentError, 'path is nil or empty') if path.nil? or path.empty?
11
11
 
12
12
  @uri = URI::HTTP.build({
@@ -20,12 +20,12 @@ module Gollum
20
20
  @contents ||= self.req @uri
21
21
  end
22
22
 
23
- def unchomp p
23
+ def unchomp(p)
24
24
  return p if p.nil?
25
25
  p[0] == '/' ? p : ('/' + p)
26
26
  end
27
27
 
28
- def req uri, cut = 1
28
+ def req(uri, cut = 1)
29
29
  return "Too many redirects or retries" if cut >= 10
30
30
  http = Net::HTTP.new uri.host, uri.port
31
31
  http.use_ssl = true
@@ -2,7 +2,7 @@
2
2
  module Gollum
3
3
  module Helpers
4
4
 
5
- def trim_leading_slash url
5
+ def trim_leading_slash(url)
6
6
  return url if url.nil?
7
7
  url.gsub!('%2F', '/')
8
8
  return '/' + url.gsub(/^\/+/, '') if url[0, 1] == '/'
@@ -0,0 +1,12 @@
1
+ module Gollum
2
+ class Macro
3
+ class GlobalTOC < Gollum::Macro
4
+ def render(title = "Global Table of Contents")
5
+ if @wiki.pages.size > 0
6
+ result = '<ul>' + @wiki.pages.map { |p| "<li><a href=\"#{p.url_path}\">#{p.url_path_display}</a></li>" }.join + '</ul>'
7
+ end
8
+ "<div class=\"toc\"><div class=\"toc-title\">#{title}</div>#{result}</div>"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,48 @@
1
+ module Gollum
2
+ class Macro
3
+
4
+ class Series < Gollum::Macro
5
+ def render(series_prefix = "")
6
+ raise "This page's name does not match the prefix '#{series_prefix}'" unless @page.name =~ /^#{series_prefix}/
7
+ render_links(*find_series(series_prefix))
8
+ end
9
+
10
+ def render_links(previous_page, next_page)
11
+ result = "Previous: <a href=\"#{::File.join(@wiki.base_path,previous_page.escaped_url_path)}\">#{previous_page.name}</a>" if previous_page
12
+ result = "#{result}#{result ? ' | ' : ''}Next: <a href=\"#{::File.join(@wiki.base_path,next_page.escaped_url_path)}\">#{next_page.name}</a>" if next_page
13
+ wrap_result(result)
14
+ end
15
+
16
+ def wrap_result(result)
17
+ result.nil? ? "" : "<div class=\"series\">#{result}</div>"
18
+ end
19
+
20
+ def find_series(series_prefix = "")
21
+ dir = @wiki.pages.select {|page| ::File.dirname(page.path) == ::File.dirname(@page.path)}
22
+ dir.select! {|page| page.name =~ /\A#{series_prefix}/ } unless series_prefix.empty?
23
+ dir.sort_by! {|page| page.name}
24
+ self_index = dir.find_index {|page| page.name == @page.name}
25
+ if self_index > 0
26
+ return dir[self_index-1], dir[self_index+1]
27
+ else
28
+ return nil, dir[self_index+1]
29
+ end
30
+ end
31
+ end
32
+
33
+ class SeriesStart < Gollum::Macro::Series
34
+ def render_links(previous_page, next_page)
35
+ result = "Next: <a href=\"#{::File.join(@wiki.base_path,next_page.escaped_url_path)}\">#{next_page.name}</a>" if next_page
36
+ wrap_result(result)
37
+ end
38
+ end
39
+
40
+ class SeriesEnd < Gollum::Macro::Series
41
+ def render_links(previous_page, next_page)
42
+ result = "Previous: <a href=\"#{::File.join(@wiki.base_path,previous_page.escaped_url_path)}\">#{previous_page.name}</a>" if previous_page
43
+ wrap_result(result)
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -42,8 +42,9 @@ module Gollum
42
42
  # If given a block, that block will be registered with GitHub::Markup to
43
43
  # render any matching pages
44
44
  def register(ext, name, options = {}, &block)
45
- regexp = options[:regexp] || Regexp.new(ext.to_s)
46
- @formats[ext] = { :name => name, :regexp => regexp }
45
+ @formats[ext] = { :name => name,
46
+ :regexp => options.fetch(:regexp, Regexp.new(ext.to_s)),
47
+ :reverse_links => options.fetch(:reverse_links, false) }
47
48
  end
48
49
  end
49
50
 
@@ -82,6 +83,10 @@ module Gollum
82
83
  @to_xml_opts = { :save_with => Nokogiri::XML::Node::SaveOptions::DEFAULT_XHTML ^ 1, :indent => 0, :encoding => 'UTF-8' }
83
84
  end
84
85
 
86
+ def reverse_links?
87
+ self.class.formats[@format][:reverse_links]
88
+ end
89
+
85
90
  # Render data using default chain in the target format.
86
91
  #
87
92
  # data - the data to render
@@ -89,7 +94,7 @@ module Gollum
89
94
  # name - name using the extension of the format
90
95
  #
91
96
  # Returns the processed data
92
- def render_default data, format=:markdown, name='render_default.md'
97
+ def render_default(data, format=:markdown, name='render_default.md')
93
98
  # set instance vars so we're able to render data without a wiki or page.
94
99
  @format = format
95
100
  @name = name
@@ -10,10 +10,10 @@ module Gollum
10
10
  register(:textile, "Textile")
11
11
  register(:rdoc, "RDoc")
12
12
  register(:org, "Org-mode")
13
- register(:creole, "Creole")
13
+ register(:creole, "Creole", :reverse_links => true)
14
14
  register(:rest, "reStructuredText", :regexp => /re?st(\.txt)?/)
15
15
  register(:asciidoc, "AsciiDoc")
16
- register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki/)
16
+ register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki/, :reverse_links => true)
17
17
  register(:pod, "Pod")
18
18
  register(:txt, "Plain Text")
19
19
  end
@@ -23,7 +23,7 @@ module Gollum
23
23
  # Returns e.g. ["Home", :markdown], or [] if the extension is unregistered
24
24
  def self.parse_filename(filename)
25
25
  return [] unless filename =~ /^(.+)\.([a-zA-Z]\w*)$/i
26
- pref, ext = $1, $2
26
+ pref, ext = Regexp.last_match[1], Regexp.last_match[2]
27
27
 
28
28
  Gollum::Markup.formats.each_pair do |name, format|
29
29
  return [pref, name] if ext =~ format[:regexp]
@@ -236,7 +236,7 @@ module Gollum
236
236
  # formatted_data - page already marked up in html.
237
237
  #
238
238
  # Returns the String data.
239
- def toc_data()
239
+ def toc_data
240
240
  return @parent_page.toc_data if @parent_page and @sub_page
241
241
  formatted_data if markup_class.toc == nil
242
242
  markup_class.toc
@@ -245,7 +245,7 @@ module Gollum
245
245
  # Public: Embedded metadata.
246
246
  #
247
247
  # Returns Hash of metadata.
248
- def metadata()
248
+ def metadata
249
249
  formatted_data if markup_class.metadata == nil
250
250
  markup_class.metadata
251
251
  end
@@ -341,7 +341,7 @@ module Gollum
341
341
  # Returns the String canonical name.
342
342
  def self.cname(name, char_white_sub = '-', char_other_sub = '-')
343
343
  name.respond_to?(:gsub) ?
344
- name.gsub(%r{\s}, char_white_sub).gsub(%r{[<>+]}, char_other_sub) :
344
+ name.gsub(%r(\s), char_white_sub).gsub(%r([<>+]), char_other_sub) :
345
345
  ''
346
346
  end
347
347
 
@@ -378,7 +378,7 @@ module Gollum
378
378
  # Returns a Gollum::Page or nil if the page could not be found.
379
379
  def find(name, version, dir = nil, exact = false)
380
380
  map = @wiki.tree_map_for(version.to_s)
381
- if page = find_page_in_tree(map, name, dir, exact)
381
+ if (page = find_page_in_tree(map, name, dir, exact))
382
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
@@ -431,7 +431,7 @@ module Gollum
431
431
  #
432
432
  # Returns the String path.
433
433
  def tree_path(treemap, tree)
434
- if ptree = treemap[tree]
434
+ if (ptree = treemap[tree])
435
435
  tree_path(treemap, ptree) + '/' + tree.name
436
436
  else
437
437
  ''
@@ -445,7 +445,7 @@ module Gollum
445
445
  #
446
446
  # Returns a Boolean.
447
447
  def page_match(name, path)
448
- if match = self.class.valid_filename?(path)
448
+ if (match = self.class.valid_filename?(path))
449
449
  @wiki.ws_subs.each do |sub|
450
450
  return true if Page.cname(name).downcase == Page.cname(match, sub).downcase
451
451
  end
@@ -471,14 +471,14 @@ module Gollum
471
471
  dirs.pop
472
472
  map = @wiki.tree_map_for(@wiki.ref, true)
473
473
  while !dirs.empty?
474
- if page = find_page_in_tree(map, name, dirs.join('/'))
474
+ if (page = find_page_in_tree(map, name, dirs.join('/')))
475
475
  page.parent_page = self
476
476
  return page
477
477
  end
478
478
  dirs.pop
479
479
  end
480
480
 
481
- if page = find_page_in_tree(map, name, '')
481
+ if (page = find_page_in_tree(map, name, ''))
482
482
  page.parent_page = self
483
483
  end
484
484
  page
@@ -50,7 +50,7 @@ module Gollum
50
50
  }.freeze
51
51
 
52
52
  ADD_ATTRIBUTES = lambda do |env, node|
53
- if add = env[:config][:add_attributes][node.name]
53
+ if (add = env[:config][:add_attributes][node.name])
54
54
  add.each do |key, value|
55
55
  node[key] = value
56
56
  end
@@ -71,7 +71,7 @@ module Gollum
71
71
  return if env[:is_whitelisted] || !node.element?
72
72
  prefix = env[:config][:id_prefix]
73
73
  found_attrs = %w(id name).select do |key|
74
- if value = node[key]
74
+ if (value = node[key])
75
75
  node[key] = value.gsub(/\A(#{prefix})?/, prefix)
76
76
  end
77
77
  end
@@ -82,7 +82,7 @@ module Gollum
82
82
  end,
83
83
  lambda do |env|
84
84
  node = env[:node]
85
- return unless value = node['href']
85
+ return unless (value = node['href'])
86
86
  prefix = env[:config][:id_prefix]
87
87
  node['href'] = value.gsub(/\A\#(#{prefix})?/, '#'+prefix)
88
88
  ADD_ATTRIBUTES.call(env, node)
@@ -1,5 +1,5 @@
1
1
  module Gollum
2
2
  module Lib
3
- VERSION = '4.0.3'
3
+ VERSION = '4.1.0'
4
4
  end
5
5
  end
@@ -248,7 +248,7 @@ module Gollum
248
248
  @allow_uploads = options.fetch :allow_uploads, false
249
249
  @per_page_uploads = options.fetch :per_page_uploads, false
250
250
  @filter_chain = options.fetch :filter_chain,
251
- [:Metadata, :PlainText, :TOC, :RemoteCode, :Code, :Macro, :Sanitize, :WSD, :Tags, :Render]
251
+ [:Metadata, :PlainText, :TOC, :RemoteCode, :Code, :Macro, :Sanitize, :WSD, :PlantUML, :Tags, :Render]
252
252
  end
253
253
 
254
254
  # Public: check whether the wiki's git repo exists on the filesystem.
@@ -345,7 +345,7 @@ module Gollum
345
345
 
346
346
  committer.add_to_index(sanitized_dir, filename, format, data)
347
347
 
348
- committer.after_commit do |index, sha|
348
+ committer.after_commit do |index, _sha|
349
349
  @access.refresh
350
350
  index.update_working_dir(sanitized_dir, filename, format)
351
351
  end
@@ -395,7 +395,7 @@ module Gollum
395
395
  committer.delete(page.path)
396
396
  committer.add_to_index(target_dir, target_name, page.format, page.raw_data)
397
397
 
398
- committer.after_commit do |index, sha|
398
+ committer.after_commit do |index, _sha|
399
399
  @access.refresh
400
400
  index.update_working_dir(source_dir, source_name, page.format)
401
401
  index.update_working_dir(target_dir, target_name, page.format)
@@ -444,7 +444,7 @@ module Gollum
444
444
  committer.add_to_index(dir, filename, format, data)
445
445
  end
446
446
 
447
- committer.after_commit do |index, sha|
447
+ committer.after_commit do |index, _sha|
448
448
  @access.refresh
449
449
  index.update_working_dir(dir, page.filename_stripped, page.format)
450
450
  index.update_working_dir(dir, filename, format)
@@ -476,7 +476,7 @@ module Gollum
476
476
 
477
477
  committer.delete(page.path)
478
478
 
479
- committer.after_commit do |index, sha|
479
+ committer.after_commit do |index, _sha|
480
480
  dir = ::File.dirname(page.path)
481
481
  dir = '' if dir == '.'
482
482
 
@@ -509,12 +509,12 @@ module Gollum
509
509
  sha2 = nil
510
510
  end
511
511
 
512
- patch = full_reverse_diff_for(page, sha1, sha2)
513
- committer = Committer.new(self, commit)
514
- parent = committer.parents[0]
512
+ patch = full_reverse_diff_for(page, sha1, sha2)
513
+ committer = Committer.new(self, commit)
514
+ parent = committer.parents[0]
515
515
  committer.options[:tree] = @repo.git.apply_patch(parent.sha, patch)
516
516
  return false unless committer.options[:tree]
517
- committer.after_commit do |index, sha|
517
+ committer.after_commit do |index, _sha|
518
518
  @access.refresh
519
519
 
520
520
  files = []
@@ -523,11 +523,11 @@ module Gollum
523
523
  else
524
524
  # Grit::Diff can't parse reverse diffs.... yet
525
525
  patch.each_line do |line|
526
- if line =~ %r{^diff --git b/.+? a/(.+)$}
527
- path = $1
526
+ if line =~ %r(^diff --git b/.+? a/(.+)$)
527
+ path = Regexp.last_match[1]
528
528
  ext = ::File.extname(path)
529
529
  name = ::File.basename(path, ext)
530
- if format = ::Gollum::Page.format_for(ext)
530
+ if (format = ::Gollum::Page.format_for(ext))
531
531
  files << [path, name, format]
532
532
  end
533
533
  end
@@ -643,7 +643,7 @@ module Gollum
643
643
  #
644
644
  # Returns an Array of Gollum::Git::Commit.
645
645
  def latest_changes(options={})
646
- max_count = options.fetch(:max_count, 10)
646
+ options[:max_count] = 10 unless options[:max_count]
647
647
  @repo.log(@ref, nil, options)
648
648
  end
649
649
 
@@ -660,7 +660,7 @@ module Gollum
660
660
  #
661
661
  # Returns a Sanitize instance.
662
662
  def sanitizer
663
- if options = sanitization
663
+ if (options = sanitization)
664
664
  @sanitizer ||= options.to_sanitize
665
665
  end
666
666
  end
@@ -670,7 +670,7 @@ module Gollum
670
670
  #
671
671
  # Returns a Sanitize instance.
672
672
  def history_sanitizer
673
- if options = history_sanitization
673
+ if (options = history_sanitization)
674
674
  @history_sanitizer ||= options.to_sanitize
675
675
  end
676
676
  end
@@ -816,7 +816,7 @@ module Gollum
816
816
  #
817
817
  # Returns a flat Array of Gollum::Page instances.
818
818
  def tree_list(ref)
819
- if sha = @access.ref_to_sha(ref)
819
+ if (sha = @access.ref_to_sha(ref))
820
820
  commit = @access.commit(sha)
821
821
  tree_map_for(sha).inject([]) do |list, entry|
822
822
  next list unless @page_class.valid_page_name?(entry.name)
@@ -833,7 +833,7 @@ module Gollum
833
833
  #
834
834
  # Returns a flat Array of Gollum::File instances.
835
835
  def file_list(ref)
836
- if sha = @access.ref_to_sha(ref)
836
+ if (sha = @access.ref_to_sha(ref))
837
837
  commit = @access.commit(sha)
838
838
  tree_map_for(sha).inject([]) do |list, entry|
839
839
  next list if entry.name.start_with?('_')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gollum-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-10 00:00:00.000000000 Z
12
+ date: 2015-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gollum-rjgit_adapter
@@ -33,14 +33,14 @@ dependencies:
33
33
  requirements:
34
34
  - - ~>
35
35
  - !ruby/object:Gem::Version
36
- version: 1.7.4
36
+ version: '1.9'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: 1.7.4
43
+ version: '1.9'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: nokogiri
46
46
  requirement: !ruby/object:Gem::Requirement
@@ -362,6 +362,7 @@ files:
362
362
  - lib/gollum-lib/filter/macro.rb
363
363
  - lib/gollum-lib/filter/metadata.rb
364
364
  - lib/gollum-lib/filter/plain_text.rb
365
+ - lib/gollum-lib/filter/plantuml.rb
365
366
  - lib/gollum-lib/filter/remote_code.rb
366
367
  - lib/gollum-lib/filter/render.rb
367
368
  - lib/gollum-lib/filter/sanitize.rb
@@ -374,6 +375,8 @@ files:
374
375
  - lib/gollum-lib/hook.rb
375
376
  - lib/gollum-lib/macro.rb
376
377
  - lib/gollum-lib/macro/all_pages.rb
378
+ - lib/gollum-lib/macro/global_toc.rb
379
+ - lib/gollum-lib/macro/series.rb
377
380
  - lib/gollum-lib/markup.rb
378
381
  - lib/gollum-lib/markups.rb
379
382
  - lib/gollum-lib/page.rb