gollum-lib 5.0.a.1 → 5.0.a.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e2a9bc73881bcc33b66757b63f6c185ddc2576e
4
- data.tar.gz: 4c3e252678d02c073238a84055cae92104bf6665
3
+ metadata.gz: fe17d31af04eac933565ca3a8064c14e6958b1fe
4
+ data.tar.gz: c66f0147ff6edd7e1b83259fff3f090bce156c96
5
5
  SHA512:
6
- metadata.gz: 84db71e0ad0f5fa9ce423a3de399476feb573b3f9f89977af3c2af69c5ae65b20749f66dceeb84ce3ee124cf7d9255dab2c1194da16473ae9969913fc4cf14c5
7
- data.tar.gz: 88c21171f76cfa9255ac1c7c17245520fbd2748c69a966349eb790e859cc88f8d9ed18785bf44679713ba8a0a3b364ea3d58caad70b3bbce1879347ea898344a
6
+ metadata.gz: 8007eb7edd7b8e74aaedd7ebc5ab9968a34f58007d9bcdc6577789018b64bcc92c421c35892a5fa3348fc1e9132391b65ab4732b773cd25eb02ff13c0dd780da
7
+ data.tar.gz: 6dc4517307645b99009596814ee06bca440085d1da04cec3d99c34bbde7eddad6c1ff1d0b25ec3599ec6d226d1cb0615d3ba9575ce8766028bae5e96dcd25442
data/gemspec.rb CHANGED
@@ -8,7 +8,7 @@ def specification(version, default_adapter, platform = nil)
8
8
  s.name = 'gollum-lib'
9
9
  s.version = version
10
10
  s.platform = platform if platform
11
- s.date = '2017-04-08'
11
+ s.date = '2017-04-12'
12
12
  s.rubyforge_project = 'gollum-lib'
13
13
  s.license = 'MIT'
14
14
 
@@ -78,14 +78,12 @@ module Gollum
78
78
  # name - The String Gollum::Page filename_stripped.
79
79
  # format - The Symbol Gollum::Page format.
80
80
  # data - The String wiki data to store in the tree map.
81
- # allow_same_ext - A Boolean determining if the tree map allows the same
82
- # filename with the same extension.
83
81
  #
84
82
  # Raises Gollum::DuplicatePageError if a matching filename already exists.
85
83
  # This way, pages are not inadvertently overwritten.
86
84
  #
87
85
  # Returns nothing (modifies the Index in place).
88
- def add_to_index(dir, name, format, data, allow_same_ext = false)
86
+ def add_to_index(dir, name, format, data)
89
87
  path = @wiki.page_file_name(name, format)
90
88
 
91
89
  dir = '/' if dir.strip.empty?
@@ -108,7 +106,7 @@ module Gollum
108
106
 
109
107
  new_file_ext = ::File.extname(path).sub(/^\./, '')
110
108
 
111
- if downpath == existing_file && !(allow_same_ext && new_file_ext == existing_file_ext)
109
+ if downpath == existing_file && (new_file_ext == existing_file_ext)
112
110
  raise DuplicatePageError.new(dir, blob.name, path)
113
111
  end
114
112
  end
@@ -3,7 +3,7 @@ module Gollum
3
3
  class GlobalTOC < Gollum::Macro
4
4
  def render(title = "Global Table of Contents")
5
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>'
6
+ result = '<ul>' + @wiki.pages.map { |p| "<li><a href=\"/#{p.url_path}\">#{p.url_path}</a></li>" }.join + '</ul>'
7
7
  end
8
8
  "<div class=\"toc\"><div class=\"toc-title\">#{title}</div>#{result}</div>"
9
9
  end
@@ -6,7 +6,7 @@ module Gollum
6
6
  if @wiki.pages.size > 0
7
7
  list_items = @wiki.pages.map do |page|
8
8
  if page.url_path.start_with?(toc_root_path)
9
- path_display = full_path ? page.url_path_display : page.url_path_display.sub(toc_root_path,"").sub(/^\//,'')
9
+ path_display = full_path ? page.url_path_display : page.url_path.sub(toc_root_path,"").sub(/^\//,'')
10
10
  "<li><a href=\"/#{page.url_path}\">#{path_display}</a></li>"
11
11
  end
12
12
  end
@@ -19,6 +19,7 @@ module Gollum
19
19
  include Helpers
20
20
 
21
21
  @formats = {}
22
+ @extensions = []
22
23
 
23
24
  class << self
24
25
 
@@ -31,20 +32,33 @@ module Gollum
31
32
  end
32
33
  end
33
34
 
35
+ def extensions
36
+ @extensions
37
+ end
38
+
34
39
  # Register a file format
35
40
  #
36
41
  # ext - The file extension
37
42
  # name - The name of the markup type
38
43
  # options - Hash of options:
39
- # regexp - Regexp to match against.
40
- # Defaults to exact match of ext.
44
+ # extensions - Array of valid file extensions, for instance ['md']
45
+ # enabled - Whether the markup is enabled
41
46
  #
42
47
  # If given a block, that block will be registered with GitHub::Markup to
43
48
  # render any matching pages
44
49
  def register(ext, name, options = {}, &block)
50
+ if options[:regexp] then
51
+ STDERR.puts <<-EOS
52
+ Warning: attempted to register a markup (name: #{name.to_s}) by passing the deprecated :regexp option.
53
+ Please pass an Array of valid file extensions (:extensions => ['ext1', 'ext2']) instead.
54
+ EOS
55
+ end
56
+ new_extension = options.fetch(:extensions, [ext.to_s])
45
57
  @formats[ext] = { :name => name,
46
- :regexp => options.fetch(:regexp, Regexp.new(ext.to_s)),
47
- :reverse_links => options.fetch(:reverse_links, false) }
58
+ :extensions => new_extension,
59
+ :reverse_links => options.fetch(:reverse_links, false),
60
+ :enabled => options.fetch(:enabled, true) }
61
+ @extensions.concat(new_extension)
48
62
  end
49
63
  end
50
64
 
@@ -1,20 +1,61 @@
1
1
  # ~*~ encoding: utf-8 ~*~
2
+
3
+ require "pathname"
4
+
5
+ module Gollum
6
+ module MarkupRegisterUtils
7
+ # Check if a gem exists. This implementation requires Gem::Specificaton to
8
+ # be filled.
9
+ def gem_exists?(name)
10
+ Gem::Specification.find {|spec| spec.name == name} != nil
11
+ end
12
+
13
+ # Check if an executable exists. This implementation comes from
14
+ # stackoverflow question 2108727.
15
+ def executable_exists?(name)
16
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
17
+ paths = ENV["PATH"].split(::File::PATH_SEPARATOR)
18
+ paths.each do |path|
19
+ exts.each do |ext|
20
+ exe = Pathname(path) + "#{name}#{ext}"
21
+ return true if exe.executable?
22
+ end
23
+ end
24
+ return false
25
+ end
26
+ end
27
+ end
28
+
29
+ include Gollum::MarkupRegisterUtils
30
+
2
31
  module Gollum
3
32
  class Markup
4
-
5
33
  GitHub::Markup::Markdown::MARKDOWN_GEMS['kramdown'] = proc { |content|
6
34
  Kramdown::Document.new(content, :auto_ids => false, :smart_quotes => ["'", "'", '"', '"'].map{|char| char.codepoints.first}).to_html
7
35
  }
8
36
 
9
- register(:markdown, "Markdown", :regexp => /md|mkdn?|mdown|markdown/)
10
- register(:textile, "Textile")
11
- register(:rdoc, "RDoc")
12
- register(:org, "Org-mode")
13
- register(:creole, "Creole", :reverse_links => true)
14
- register(:rest, "reStructuredText", :regexp => /re?st(\.txt)?/)
15
- register(:asciidoc, "AsciiDoc")
16
- register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki/, :reverse_links => true)
17
- register(:pod, "Pod")
18
- register(:txt, "Plain Text")
37
+ # markdown, rdoc, and plain text are always supported.
38
+ register(:markdown, "Markdown", :extensions => ['md','mkd','mkdn','mdown','markdown'])
39
+ register(:rdoc, "RDoc")
40
+ register(:txt, "Plain Text")
41
+ # the following formats are available only when certain gem is installed
42
+ # or certain program exists.
43
+ register(:textile, "Textile",
44
+ :enabled => MarkupRegisterUtils::gem_exists?("RedCloth"))
45
+ register(:org, "Org-mode",
46
+ :enabled => MarkupRegisterUtils::gem_exists?("org-ruby"))
47
+ register(:creole, "Creole",
48
+ :enabled => MarkupRegisterUtils::gem_exists?("creole"),
49
+ :reverse_links => true)
50
+ register(:rest, "reStructuredText",
51
+ :enabled => MarkupRegisterUtils::executable_exists?("python2"),
52
+ :extensions => ['rest', 'rst', 'rst.txt', 'rest.txt'])
53
+ register(:asciidoc, "AsciiDoc",
54
+ :enabled => MarkupRegisterUtils::gem_exists?("asciidoctor"))
55
+ register(:mediawiki, "MediaWiki",
56
+ :enabled => MarkupRegisterUtils::gem_exists?("wikicloth"),
57
+ :extensions => ['mediawiki','wiki'], :reverse_links => true)
58
+ register(:pod, "Pod",
59
+ :enabled => MarkupRegisterUtils::executable_exists?("perl"))
19
60
  end
20
- end
61
+ end
@@ -17,25 +17,13 @@ module Gollum
17
17
  # Returns a Page
18
18
  attr_accessor :parent_page
19
19
 
20
- # Find the Symbol format for the file extension
21
- #
22
- # ext - String file extension, like ".md"
23
- #
24
- # Returns the Symbol format associated with ext
25
- def self.parse_extension(ext)
26
- Gollum::Markup.formats.each_pair do |name, format|
27
- return name if ext =~ format[:regexp]
28
- end
29
- nil
30
- end
31
-
32
20
  # Checks if a filename has a valid, registered extension
33
21
  #
34
22
  # filename - String filename, like "Home.md".
35
23
  #
36
24
  # Returns true or false.
37
25
  def self.valid_extension?(filename)
38
- !!self.parse_extension(::File.extname(filename))
26
+ Gollum::Markup.extensions.include?(::File.extname(filename.to_s).sub(/^\./,''))
39
27
  end
40
28
 
41
29
  # Checks if a filename has a valid extension understood by GitHub::Markup.
@@ -55,15 +43,11 @@ module Gollum
55
43
  #
56
44
  # Returns the Symbol format of the page; one of the registered format types
57
45
  def self.format_for(filename)
58
- self.parse_extension(::File.extname(filename))
59
- end
60
-
61
- # Reusable filter to turn a filename (without path) into a canonical name.
62
- # Strips extension, convert to string if possible.
63
- #
64
- # Returns the filtered String.
65
- def self.canonicalize_filename(filename)
66
- self.strip_filename(filename.to_s)
46
+ ext = ::File.extname(filename.to_s).sub(/^\./,'')
47
+ Gollum::Markup.formats.each_pair do |name, format|
48
+ return name if format[:extensions].include?(ext)
49
+ end
50
+ nil
67
51
  end
68
52
 
69
53
  # Reusable filter to strip extension and path from filename
@@ -72,7 +56,7 @@ module Gollum
72
56
  #
73
57
  # Returns the stripped String.
74
58
  def self.strip_filename(filename)
75
- ::File.basename(filename, ::File.extname(filename))
59
+ ::File.basename(filename.to_s, ::File.extname(filename.to_s))
76
60
  end
77
61
 
78
62
  # Public: Initialize a page.
@@ -88,6 +72,13 @@ module Gollum
88
72
  @parent_page = nil
89
73
  end
90
74
 
75
+ # Public: The SHA hash identifying this page
76
+ #
77
+ # Returns the String SHA.
78
+ def sha
79
+ @blob && @blob.id
80
+ end
81
+
91
82
  # Public: The on-disk filename of the page including extension.
92
83
  #
93
84
  # Returns the String name.
@@ -106,7 +97,7 @@ module Gollum
106
97
  #
107
98
  # Returns the String name.
108
99
  def name
109
- self.class.canonicalize_filename(filename)
100
+ self.class.strip_filename(filename)
110
101
  end
111
102
 
112
103
  # Public: The title will be constructed from the
@@ -140,17 +131,10 @@ module Gollum
140
131
  ''
141
132
  end
142
133
 
143
- path << self.name
134
+ path << self.filename
144
135
  path
145
136
  end
146
137
 
147
- # Public: The display form of the url path required to reach this page within the repo.
148
- #
149
- # Returns the String url_path
150
- def url_path_display
151
- url_path
152
- end
153
-
154
138
  # Public: Defines title for page.rb
155
139
  #
156
140
  # Returns the String title
@@ -158,6 +142,13 @@ module Gollum
158
142
  metadata_title || url_path
159
143
  end
160
144
 
145
+ # Public: The url_path, but CGI escaped.
146
+ #
147
+ # Returns the String url_path
148
+ def escaped_url_path
149
+ CGI.escape(self.url_path).gsub('%2F', '/')
150
+ end
151
+
161
152
  # Public: Metadata title
162
153
  #
163
154
  # Set with <!-- --- title: New Title --> in page content
@@ -179,13 +170,6 @@ module Gollum
179
170
  @wiki.display_metadata
180
171
  end
181
172
 
182
- # Public: The url_path, but CGI escaped.
183
- #
184
- # Returns the String url_path
185
- def escaped_url_path
186
- CGI.escape(self.url_path).gsub('%2F', '/')
187
- end
188
-
189
173
  # Public: The raw contents of the page.
190
174
  #
191
175
  # Returns the String data.
@@ -390,7 +374,7 @@ module Gollum
390
374
 
391
375
  map.each do |entry|
392
376
  next if entry.name.to_s.empty? || !self.class.valid_extension?(entry.name)
393
- entry_name = ::File.extname(name).empty? ? Page.canonicalize_filename(entry.name) : entry.name
377
+ entry_name = ::File.extname(name).empty? ? ::Gollum::Page.strip_filename(entry.name) : entry.name
394
378
  path = checked_dir ? ::File.join(entry.dir, entry_name) : entry_name
395
379
  next unless query.downcase == path.downcase
396
380
  return entry.page(@wiki, @version)
@@ -1,5 +1,5 @@
1
1
  module Gollum
2
2
  module Lib
3
- VERSION = '5.0.a.1'
3
+ VERSION = '5.0.a.2'
4
4
  end
5
- end
5
+ end
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: 5.0.a.1
4
+ version: 5.0.a.2
5
5
  platform: ruby
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: 2017-04-08 00:00:00.000000000 Z
12
+ date: 2017-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gollum-grit_adapter