gollum-export 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gollum-export.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alfonso Cora
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ #Gollum Export
2
+
3
+ ##Overview
4
+
5
+ This gem includes the `gollum-export` command that allows converting local markdown files to html. It also includes a switch to download and convert a full wiki from a github repo.
6
+
7
+ ##Installation
8
+
9
+ ```bash
10
+ $ gem install gollum-export
11
+ ```
12
+
13
+ ##Usage
14
+
15
+ Local conversion:
16
+
17
+ ```bash
18
+ gollum-export file1.md file2.md ...
19
+ ```
20
+
21
+ Download and convert a github wiki:
22
+
23
+ ```bash
24
+ gollum-export plataformatec/devise
25
+ ```
26
+
27
+ ##License
28
+
29
+ (The MIT License)
30
+
31
+ Copyright (c) 2012 Alfonso Cora
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'html/pipeline'
4
+ require 'gollum-export'
5
+
6
+ # get the output directory parameter
7
+ output_directory = nil
8
+ if o_index = ARGV.index('-o')
9
+ output_directory = ARGV[o_index + 1]
10
+ end
11
+
12
+ # detect mode
13
+ if ARGV.length == 0
14
+ # help mode
15
+ puts 'Usage:'
16
+ puts ' gollum-export plataformatec/devise'
17
+ puts ' gollum-export file1.md file2.md ...'
18
+ elsif ARGV.any? {|f| f =~ /\.md$/}
19
+ # file mode
20
+ ARGV.each do |file|
21
+ next unless file =~ /\.md$/
22
+ puts "Converting #{file}..."
23
+ Gollum::Export::Processor.convert_file(file, :output_directory => output_directory)
24
+ end
25
+ else
26
+ # github mode
27
+ repository = ARGV[0]
28
+ wiki_repository = "#{repository}.wiki"
29
+ directory = wiki_repository.split('/')[1]
30
+ output_directory ||= "#{directory}_html"
31
+
32
+ unless Dir.exists?(directory)
33
+ clone_command = "git clone git://github.com/#{wiki_repository}.git"
34
+ puts "> #{clone_command}"
35
+ fail unless system(clone_command)
36
+ end
37
+
38
+ unless Dir.exists?(output_directory)
39
+ mkdir_command = "mkdir #{output_directory}"
40
+ puts "> #{mkdir_command}"
41
+ fail unless system(mkdir_command)
42
+ end
43
+
44
+ Dir.glob("#{directory}/**/*.md").each do |file|
45
+ puts "Converting #{file}..."
46
+ Gollum::Export::Processor.convert_file(file, :output_directory => output_directory, :repository => repository)
47
+ end
48
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gollum/export/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "gollum-export"
8
+ gem.version = Gollum::Export::VERSION
9
+ gem.authors = ["Alfonso Cora"]
10
+ gem.email = ["acora6@gmail.com"]
11
+ gem.description = %q{This gem includes the `gollum-export` command that allows converting local markdown files to html. It also includes a switch to download and convert a full wiki from a github repo.}
12
+ gem.summary = %q{Downloads Gollum wikis and converts them to HTML}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'html-pipeline', '~> 0.0.6'
21
+ gem.add_development_dependency 'rspec', '~> 2.12.0'
22
+ end
@@ -0,0 +1,2 @@
1
+ require "gollum/export/version"
2
+ require 'gollum/export/processor'
@@ -0,0 +1,35 @@
1
+ module Gollum
2
+ module Export
3
+ class LinkFilter
4
+ def initialize(source, repository)
5
+ @source = source
6
+ @repository = repository
7
+ end
8
+
9
+ def call
10
+ @result = @source.gsub(/\[\[.*\]\]/) do |page_name|
11
+ page_name.gsub!(/[\[\]]/, '')
12
+ link = page_name_to_path(page_name)
13
+ "<a href=\"#{link}\">#{page_name}</a>"
14
+ end
15
+
16
+ if @repository
17
+ @result.gsub!(/"(https:\/\/github.com\/#{@repository}\/wiki\/)(.*)"/) do |explicit_link|
18
+ url, path = $1, $2
19
+
20
+ next explicit_link if path =~ /^_pages/
21
+
22
+ explicit_link.gsub!(url, '')
23
+ explicit_link.gsub!(path, page_name_to_path(path))
24
+ end
25
+ end
26
+
27
+ @result
28
+ end
29
+
30
+ def page_name_to_path(page_name)
31
+ "#{page_name.downcase.gsub(/\s/,'-').gsub(':', '%3A')}.html"
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,37 @@
1
+ require 'gollum/export/link_filter'
2
+
3
+ module Gollum
4
+ module Export
5
+ class Processor
6
+ def self.convert_file(source_filename, options={})
7
+ return unless source_filename =~ /\.md$/
8
+
9
+ output_directory = options.fetch(:output_directory, nil)
10
+ repository = options.fetch(:repository, nil)
11
+
12
+ File.open(source_filename, 'r') do |source_file|
13
+ File.open(target_filename(source_filename, output_directory), 'w') do |target_file|
14
+ md_filter = HTML::Pipeline::MarkdownFilter.new(source_file.read)
15
+ link_filter = Gollum::Export::LinkFilter.new(md_filter.call, repository)
16
+ target_file.write(link_filter.call)
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def self.target_filename(source_filename, output_directory=nil)
24
+ # sanitize final slash
25
+ if output_directory && !(output_directory =~ /\/$/)
26
+ output_directory += '/'
27
+ end
28
+
29
+ if output_directory
30
+ output_directory + source_filename.gsub(/^.*\//, '')
31
+ else
32
+ source_filename
33
+ end.gsub(/md$/, 'html').downcase
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,5 @@
1
+ module Gollum
2
+ module Export
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Gollum::Export::LinkFilter do
4
+ it 'should fix links to implicit pages' do
5
+ source = '[[Another-Local-Page]]'
6
+ Gollum::Export::LinkFilter.new(source, nil).call.should == '<a href="another-local-page.html">Another-Local-Page</a>'
7
+ end
8
+
9
+ it 'should fix explicit links' do
10
+ source = '<a href="https://github.com/user/repo/wiki/Another-Local-Page">Another-Local-Page</a>'
11
+ Gollum::Export::LinkFilter.new(source, 'user/repo').call.should == '<a href="another-local-page.html">Another-Local-Page</a>'
12
+ end
13
+
14
+ it 'should leave links to github pages untouched' do
15
+ source = '<a href="https://github.com/user/repo/wiki/_pages">Pages</a>'
16
+ Gollum::Export::LinkFilter.new(source, 'user/repo').call.should == source
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'gollum-export'
4
+
5
+ Dir[File.expand_path("support/*", File.dirname(__FILE__))].each {|f| require f}
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec
9
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gollum-export
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alfonso Cora
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: html-pipeline
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.6
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.6
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.12.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.12.0
46
+ description: This gem includes the `gollum-export` command that allows converting
47
+ local markdown files to html. It also includes a switch to download and convert
48
+ a full wiki from a github repo.
49
+ email:
50
+ - acora6@gmail.com
51
+ executables:
52
+ - gollum-export
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - bin/gollum-export
62
+ - gollum-export.gemspec
63
+ - lib/gollum-export.rb
64
+ - lib/gollum/export/link_filter.rb
65
+ - lib/gollum/export/processor.rb
66
+ - lib/gollum/export/version.rb
67
+ - spec/lib/gollum/export/link_filter_spec.rb
68
+ - spec/spec_helper.rb
69
+ homepage: ''
70
+ licenses: []
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 1.8.23
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Downloads Gollum wikis and converts them to HTML
93
+ test_files:
94
+ - spec/lib/gollum/export/link_filter_spec.rb
95
+ - spec/spec_helper.rb