gollum-lib 1.0.9 → 2.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.

@@ -10,5 +10,6 @@ module Gollum
10
10
  register(:asciidoc, "AsciiDoc")
11
11
  register(:mediawiki, "MediaWiki", :regexp => /(media)?wiki/)
12
12
  register(:pod, "Pod")
13
+ register(:txt, "Plain Text")
13
14
  end
14
15
  end
@@ -150,6 +150,12 @@ module Gollum
150
150
 
151
151
  # Gets side on which the sidebar should be shown
152
152
  attr_reader :bar_side
153
+
154
+ # An array of symbols which refer to classes under Gollum::Filter,
155
+ # each of which is an element in the "filtering chain". See
156
+ # the documentation for Gollum::Filter for more on how this chain
157
+ # works, and what filter classes need to implement.
158
+ attr_reader :filter_chain
153
159
 
154
160
  # Public: Initialize a new Gollum Repo.
155
161
  #
@@ -183,6 +189,10 @@ module Gollum
183
189
  # - :left
184
190
  # - :right
185
191
  # :allow_uploads - Set to true to allow file uploads.
192
+ # :per_page_uploads - Whether uploads should be stored in a central
193
+ # 'uploads' directory, or in a directory named for
194
+ # the page they were uploaded to.
195
+ # :filter_chain - Override the default filter chain with your own.
186
196
  #
187
197
  # Returns a fresh Gollum::Repo.
188
198
  def initialize(path, options = {})
@@ -223,6 +233,9 @@ module Gollum
223
233
  @user_icons = ['gravatar', 'identicon'].include?( options[:user_icons] ) ?
224
234
  options[:user_icons] : 'none'
225
235
  @allow_uploads = options.fetch :allow_uploads, false
236
+ @per_page_uploads = options.fetch :per_page_uploads, false
237
+ @filter_chain = options.fetch :filter_chain,
238
+ [:Metadata, :PlainText, :TOC, :RemoteCode, :Code, :Sanitize, :WSD, :Tags, :Render]
226
239
  end
227
240
 
228
241
  # Public: check whether the wiki's git repo exists on the filesystem.
@@ -642,6 +655,74 @@ module Gollum
642
655
  @history_sanitizer ||= options.to_sanitize
643
656
  end
644
657
  end
658
+
659
+ # Public: Add an additional link to the filter chain.
660
+ #
661
+ # name - A symbol which represents the name of a class under the
662
+ # Gollum::Render namespace to insert into the chain.
663
+ #
664
+ # loc - A "location specifier" -- that is, where to put the new
665
+ # filter in the chain. This can be one of `:first`, `:last`,
666
+ # `:before => :SomeElement`, or `:after => :SomeElement`, where
667
+ # `:SomeElement` (if specified) is a symbol already in the
668
+ # filter chain. A `:before` or `:after` which references a
669
+ # filter that doesn't exist will cause `ArgumentError` to be
670
+ # raised.
671
+ #
672
+ # Returns nothing.
673
+ def add_filter(name, loc)
674
+ unless name.is_a? Symbol
675
+ raise ArgumentError,
676
+ "Invalid filter name #{name.inspect} (must be a symbol)"
677
+ end
678
+
679
+ case loc
680
+ when :first
681
+ @filter_chain.unshift(name)
682
+ when :last
683
+ @filter_chain.push(name)
684
+ when Hash
685
+ if loc.length != 1
686
+ raise ArgumentError,
687
+ "Invalid location specifier"
688
+ end
689
+ if ([:before, :after] && loc.keys).empty?
690
+ raise ArgumentError,
691
+ "Invalid location specifier"
692
+ end
693
+
694
+ next_to = loc.values.first
695
+ relative = loc.keys.first
696
+
697
+ i = @filter_chain.index(next_to)
698
+ if i.nil?
699
+ raise ArgumentError,
700
+ "Unknown filter #{next_to.inspect}"
701
+ end
702
+
703
+ i += 1 if relative == :after
704
+ @filter_chain.insert(i, name)
705
+ else
706
+ raise ArgumentError,
707
+ "Invalid location specifier"
708
+ end
709
+ end
710
+
711
+ # Remove the named filter from the filter chain.
712
+ #
713
+ # Returns nothing. Raises `ArgumentError` if the named filter doesn't
714
+ # exist in the chain.
715
+ def remove_filter(name)
716
+ unless name.is_a? Symbol
717
+ raise ArgumentError,
718
+ "Invalid filter name #{name.inspect} (must be a symbol)"
719
+ end
720
+
721
+ unless @filter_chain.delete(name)
722
+ raise ArgumentError,
723
+ "#{name.inspect} not found in filter chain"
724
+ end
725
+ end
645
726
 
646
727
  #########################################################################
647
728
  #
@@ -687,6 +768,10 @@ module Gollum
687
768
  # Toggles file upload functionality.
688
769
  attr_reader :allow_uploads
689
770
 
771
+ # Toggles whether uploaded files go into 'uploads', or a directory
772
+ # named after the page they were uploaded to.
773
+ attr_reader :per_page_uploads
774
+
690
775
  # Normalize the data.
691
776
  #
692
777
  # data - The String data to be normalized.
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: 1.0.9
4
+ version: 2.0.0
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: 2013-11-02 00:00:00.000000000 Z
12
+ date: 2014-02-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gitlab-grit
@@ -46,19 +46,19 @@ dependencies:
46
46
  - !ruby/object:Gem::Version
47
47
  version: 1.0.0
48
48
  - !ruby/object:Gem::Dependency
49
- name: pygments.rb
49
+ name: rouge
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.2
54
+ version: 1.3.1
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.5.2
61
+ version: 1.3.1
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: sanitize
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -345,6 +345,16 @@ files:
345
345
  - lib/gollum-lib/committer.rb
346
346
  - lib/gollum-lib/file.rb
347
347
  - lib/gollum-lib/file_view.rb
348
+ - lib/gollum-lib/filter.rb
349
+ - lib/gollum-lib/filter/code.rb
350
+ - lib/gollum-lib/filter/metadata.rb
351
+ - lib/gollum-lib/filter/plain_text.rb
352
+ - lib/gollum-lib/filter/remote_code.rb
353
+ - lib/gollum-lib/filter/render.rb
354
+ - lib/gollum-lib/filter/sanitize.rb
355
+ - lib/gollum-lib/filter/tags.rb
356
+ - lib/gollum-lib/filter/toc.rb
357
+ - lib/gollum-lib/filter/wsd.rb
348
358
  - lib/gollum-lib/git_access.rb
349
359
  - lib/gollum-lib/gitcode.rb
350
360
  - lib/gollum-lib/grit_ext.rb
@@ -354,9 +364,7 @@ files:
354
364
  - lib/gollum-lib/markups.rb
355
365
  - lib/gollum-lib/page.rb
356
366
  - lib/gollum-lib/pagination.rb
357
- - lib/gollum-lib/remote_code.rb
358
367
  - lib/gollum-lib/sanitization.rb
359
- - lib/gollum-lib/web_sequence_diagram.rb
360
368
  - lib/gollum-lib/wiki.rb
361
369
  - licenses/licenses.txt
362
370
  homepage: http://github.com/gollum/gollum-lib
@@ -380,7 +388,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
380
388
  version: '0'
381
389
  requirements: []
382
390
  rubyforge_project: gollum-lib
383
- rubygems_version: 2.0.6
391
+ rubygems_version: 2.1.11
384
392
  signing_key:
385
393
  specification_version: 2
386
394
  summary: A simple, Git-powered wiki.
@@ -1,39 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require 'net/http'
3
- require 'net/https' # ruby 1.8.7 fix, remove at upgrade
4
- require 'uri'
5
- require 'open-uri'
6
-
7
- module Gollum
8
- class RemoteCode
9
- def initialize path
10
- raise(ArgumentError, 'path is nil or empty') if path.nil? or path.empty?
11
- @uri = URI(path)
12
- end
13
-
14
- def contents
15
- @contents ||= req @uri
16
- end
17
-
18
- private
19
-
20
- def req uri, cut = 1
21
- return "Too many redirects or retries" if cut >= 10
22
- http = Net::HTTP.new uri.host, uri.port
23
- http.use_ssl = true
24
- resp = http.get uri.path, {
25
- 'Accept' => 'text/plain',
26
- 'Cache-Control' => 'no-cache',
27
- 'Connection' => 'keep-alive',
28
- 'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0'
29
- }
30
- code = resp.code.to_i
31
- return resp.body if code == 200
32
- return "Not Found" if code == 404
33
- return "Unhandled Response Code #{code}" unless code == 304 or not resp.header['location'].nil?
34
- loc = URI.parse resp.header['location']
35
- uri2 = loc.relative? ? (uri + loc) : loc # overloads (+)
36
- req uri2, (cut + 1)
37
- end
38
- end
39
- end
@@ -1,44 +0,0 @@
1
- # ~*~ encoding: utf-8 ~*~
2
- require 'net/http'
3
- require 'uri'
4
- require 'open-uri'
5
-
6
- class Gollum::WebSequenceDiagram
7
- WSD_URL = "http://www.websequencediagrams.com/index.php"
8
-
9
- # Initialize a new WebSequenceDiagram object.
10
- #
11
- # code - The String containing the sequence diagram markup.
12
- # style - The String containing the rendering style.
13
- #
14
- # Returns a new Gollum::WebSequenceDiagram object
15
- def initialize(code, style)
16
- @code = code
17
- @style = style
18
- @tag = ""
19
-
20
- render
21
- end
22
-
23
- # Render the sequence diagram on the remote server and store the url to
24
- # the rendered image.
25
- #
26
- # Returns nil.
27
- def render
28
- response = Net::HTTP.post_form(URI.parse(WSD_URL), 'style' => @style, 'message' => @code)
29
- if response.body =~ /img: "(.+)"/
30
- url = "http://www.websequencediagrams.com/#{$1}"
31
- @tag = "<img src=\"#{url}\" />"
32
- else
33
- puts response.body
34
- @tag ="Sorry, unable to render sequence diagram at this time."
35
- end
36
- end
37
-
38
- # Gets the HTML IMG tag for the sequence diagram.
39
- #
40
- # Returns a String containing the IMG tag.
41
- def to_tag
42
- @tag
43
- end
44
- end