github_exporter 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47dcd5396b00731afac0413cf3828b3b68a7c08f
4
+ data.tar.gz: e2e30f973770a966a06ce78bb97a711695204218
5
+ SHA512:
6
+ metadata.gz: 22976c785ba411819679e2882c765d46c236cc347d2b08c040382013dc0bd0afc6a684f5ffccf84148af48885e6bc5dac76e0e3ee6e455d9cd9c8843d798f1f6
7
+ data.tar.gz: c2840d83bed7a41e8925e1f5d945023086389f6aed3002498ebe1abe3e368817ff97675c8f861ed696ca854ea4ce4c8a527ff13d8d00fbb4106e5b6284669509
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
18
+ # Custom generated files
19
+ .ruby-version
data/.rubocop.yml ADDED
@@ -0,0 +1,96 @@
1
+ AllCops:
2
+ Include:
3
+ - Gemfile
4
+ - Rakefile
5
+ - bin/*
6
+ - github_exporter.gemspec
7
+ - lib/**/*.rb
8
+ - test/**/*.rb
9
+ # Avoid long parameter lists
10
+ ParameterLists:
11
+ Max: 5
12
+ CountKeywordArgs: true
13
+
14
+ MethodLength:
15
+ CountComments: false
16
+ Max: 15
17
+
18
+ # Avoid more than `Max` levels of nesting.
19
+ BlockNesting:
20
+ Max: 4
21
+
22
+ # Align with the style guide.
23
+ CollectionMethods:
24
+ PreferredMethods:
25
+ collect: 'map'
26
+ inject: 'reduce'
27
+ find_all: 'select'
28
+ #find: 'detect' # comment out for now as this will trigger changes for
29
+ # Pathname.find to Pathname.detect which is not correct
30
+
31
+ # Do not force public/protected/private keyword to be indented at the same
32
+ # level as the def keyword. My personal preference is to outdent these keywords
33
+ # because I think when scanning code it makes it easier to identify the
34
+ # sections of code and visually separate them. When the keyword is at the same
35
+ # level I think it sort of blends in with the def keywords and makes it harder
36
+ # to scan the code and see where the sections are.
37
+ AccessModifierIndentation:
38
+ Enabled: false
39
+
40
+ # Limit line length
41
+ LineLength:
42
+ Enabled: false
43
+
44
+ # Disable documentation checking until a class needs to be documented once
45
+ Documentation:
46
+ Enabled: false
47
+
48
+ # Enforce Ruby 1.8-compatible hash syntax
49
+ HashSyntax:
50
+ Enabled: true
51
+
52
+ # Use spaces inside hash literals
53
+ SpaceInsideHashLiteralBraces:
54
+ EnforcedStyle: space
55
+
56
+ # Allow dots at the end of lines
57
+ DotPosition:
58
+ Enabled: false
59
+
60
+ # Don't require magic comment at the top of every file
61
+ Encoding:
62
+ Enabled: false
63
+
64
+ # Enforce outdenting of access modifiers (i.e. public, private, protected)
65
+ AccessModifierIndentation:
66
+ EnforcedStyle: outdent
67
+
68
+ EmptyLinesAroundAccessModifier:
69
+ Enabled: true
70
+
71
+ # Align ends correctly
72
+ EndAlignment:
73
+ AlignWith: variable
74
+
75
+ # Indentation of when/else
76
+ CaseIndentation:
77
+ IndentWhenRelativeTo: end
78
+ IndentOneStep: false
79
+
80
+ DoubleNegation:
81
+ Enabled: false
82
+
83
+ PercentLiteralDelimiters:
84
+ PreferredDelimiters:
85
+ '%': ()
86
+ '%i': ()
87
+ '%q': ()
88
+ '%Q': ()
89
+ '%r': '{}'
90
+ '%s': ()
91
+ '%w': '[]'
92
+ '%W': '[]'
93
+ '%x': ()
94
+
95
+ StringLiterals:
96
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ #### 0.1.0
2
+
3
+ - Initial release following the [semantic versioning][]
4
+ - Allow the export from local source
5
+
6
+ [semantic versioning]: http://semver.org
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in valid_filename.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Burin Choomnuan
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.
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ ## github_exporter
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/github_exporter.svg)][gem]
4
+ [![Dependency Status](https://gemnasium.com/agilecreativity/github_exporter.png)][gemnasium]
5
+ [![Code Climate](https://codeclimate.com/github/agilecreativity/github_exporter.png)][codeclimate]
6
+
7
+ [gem]: http://badge.fury.io/rb/github_exporter
8
+ [gemnasium]: https://gemnasium.com/agilecreativity/github_exporter
9
+ [codeclimate]: https://codeclimate.com/github/agilecreativity/github_exporter
10
+
11
+ Export/print content of a given github repository (or local project directory) to single pdf for quick review offline.
12
+
13
+ ## Requirements
14
+
15
+ - Valid installation of [Ghostscript][] required by [pdfs2pdf][] gem
16
+ - Valid installation of [Wkhtmltopdf][] required by [html2pdf][] gem
17
+ - Valid installation of [Vim][] required by [vim_printer][] gem
18
+
19
+ ## Installation
20
+
21
+ ```
22
+ gem install github_exporter
23
+ ```
24
+
25
+ ## Synopsis/Usage
26
+
27
+ ```shell
28
+ Usage:
29
+
30
+ $github_exporter -e, --exts=EXT1 EXT2 EXT3 -u, --url=URL -theme=theme_name
31
+
32
+ Example:
33
+
34
+ # Export the *.rb from the given repository
35
+
36
+ $github_exporter -e rb -u https://github.com/agilecreativity/filename_cleaner.git
37
+
38
+ # Export the *.rb and also 'Gemfile' from a given directory 'filename_cleaner'
39
+ # Note: must be one directory directly relative to current directory
40
+
41
+ $github_exporter -e rb -f Gemfile -u filename_cleaner
42
+
43
+ # Export the *.rb and also 'Gemfile' from a given directory 'filename_cleaner'
44
+ # using 'solarized' theme
45
+ # Note: must be one directory directly relative to current directory
46
+
47
+ $github_exporter -e rb -f Gemfile -u filename_cleaner -t solarized
48
+
49
+ Options:
50
+
51
+ -u, --url=URL # The full url of the github project to be cloned
52
+
53
+ -e, --exts=EXT1 EXT2 EXT3 .. # The list of extension names to be exported
54
+ # e.g. -e md rb java
55
+
56
+ -f, [--non-exts=one two three] # The list of file without extension to be exported
57
+ # e.g. -f Gemfile LICENSE
58
+
59
+ -t, [--theme=theme_name] # The theme to be used with vim_printer see :h :colorscheme from Vim
60
+ # default: 'default'
61
+ # e.g. -t solarized
62
+
63
+ Export a given URL or project to a single pdf file
64
+
65
+ ```
66
+
67
+ ### Sample Usage:
68
+
69
+ ```shell
70
+ github_exporter -u https://github.com/agilecreativity/github_exporter.git -e rb
71
+ ```
72
+
73
+ Should result in something similar to this in the console
74
+
75
+ ```
76
+ git clone https://github.com/agilecreativity/github_exporter.git ./github_exporter
77
+ FYI: list of extensions: ["gemspec", "md", "pdf", "png", "rb"]
78
+ FYI: list of all files : ["./lib/github_exporter.rb", "./lib/github_exporter/cli.rb", "./lib/github_exporter/exporter.rb", "./lib/github_exporter/github_exporter.rb", "./lib/github_exporter/logger.rb", "./lib/github_exporter/version.rb", "./test/lib/github_exporter/test_github_exporter.rb", "./test/test_helper.rb"]
79
+ Your input options for VimPrinter : ["print", "--base-dir", "./github_exporter", "--exts", ["rb"], "--theme", "default", "--recursive"]
80
+ FYI: process file 1 of 8 : ./lib/github_exporter.rb
81
+ FYI: process file 2 of 8 : ./lib/github_exporter/cli.rb
82
+ FYI: process file 3 of 8 : ./lib/github_exporter/exporter.rb
83
+ FYI: process file 4 of 8 : ./lib/github_exporter/github_exporter.rb
84
+ FYI: process file 5 of 8 : ./lib/github_exporter/logger.rb
85
+ FYI: process file 6 of 8 : ./lib/github_exporter/version.rb
86
+ FYI: process file 7 of 8 : ./test/lib/github_exporter/test_github_exporter.rb
87
+ FYI: process file 8 of 8 : ./test/test_helper.rb
88
+ Your output file is './github_exporter/vim_printer_github_exporter.tar.gz'
89
+ Convert file 1 of 9 : ./index.html
90
+ Convert file 2 of 9 : ./lib/github_exporter.rb.xhtml
91
+ Convert file 3 of 9 : ./lib/github_exporter/cli.rb.xhtml
92
+ Convert file 4 of 9 : ./lib/github_exporter/exporter.rb.xhtml
93
+ Convert file 5 of 9 : ./lib/github_exporter/github_exporter.rb.xhtml
94
+ Convert file 6 of 9 : ./lib/github_exporter/logger.rb.xhtml
95
+ Convert file 7 of 9 : ./lib/github_exporter/version.rb.xhtml
96
+ Convert file 8 of 9 : ./test/lib/github_exporter/test_github_exporter.rb.xhtml
97
+ Convert file 9 of 9 : ./test/test_helper.rb.xhtml
98
+ Convert files to pdfs took 2.324978936 ms
99
+ Your final output is './github_exporter_tmp/github_exporter/html2pdf_github_exporter.tar.gz'
100
+ Create pdfmarks took 0.027517634 ms
101
+ Combine pdf files took 0.763918867 ms
102
+ Your combined pdf is available at ./github_exporter_tmp/github_exporter/pdfs2pdf_github_exporter.pdf
103
+ Your final output is ./github_exporter.pdf
104
+ ```
105
+
106
+ ### Sample Output
107
+
108
+ #### Using the 'default' theme/colorscheme for Vim
109
+
110
+ ```shell
111
+ github_exporter -u https://github.com/agilecreativity/github_exporter.git --exts rb
112
+ ```
113
+
114
+ Which generated the following [pdf output file](/samples/github_exporter_default_colorscheme.pdf)
115
+
116
+ The example screenshot:
117
+
118
+ ![](/samples/github_exporter_default_colorscheme.png)
119
+
120
+ #### Use non-default colorscheme/theme for Vim
121
+
122
+ Use [seoul256][] colorscheme
123
+
124
+ ```shell
125
+ github_exporter -u https://github.com/agilecreativity/github_exporter.git --exts rb --theme seoul256
126
+ ```
127
+
128
+ Which generated the following [pdf output file](/samples/github_exporter_seoul256_colorscheme.pdf)
129
+
130
+ The example screenshot:
131
+
132
+ ![](/samples/github_exporter_seoul256_colorscheme.png)
133
+
134
+ ### Contributing
135
+
136
+ 1. Fork it
137
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
138
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
139
+ 4. Push to the branch (`git push origin my-new-feature`)
140
+ 5. Create new Pull Request
141
+
142
+ [thor]: https://github.com/erikhuda/thor
143
+ [minitest]: https://github.com/seattlerb/minitest
144
+ [yard]: https://github.com/lsegal/yard
145
+ [pry]: https://github.com/pry/pry
146
+ [rubocop]: https://github.com/bbatsov/rubocop
147
+ [grit]: https://github.com/mojombo/grit
148
+ [Ghostscript]: http://todo.com/
149
+ [Wkhtmltopdf]: http://todo.com/
150
+ [Vim]: http://www.vim.org
151
+ [vim_printer]: https://github.com/agilecreativity/vim_printer
152
+ [pdfs2pdf]: https://github.com/agilecreativity/pdfs2pdf
153
+ [html2pdf]: https://github.com/agilecreativity/html2pdf
154
+ [monokai]: https://github.com/lsdr/monokai
155
+ [seoul256]: https://github.com/junegunn/seoul256.vim
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ project_name = "github_exporter"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "lib/#{project_name}"
7
+ t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
8
+ t.verbose = true
9
+ end
10
+
11
+ task default: [:test, :rubocop]
12
+ task :pry do
13
+ require "pry"
14
+ require "awesome_print"
15
+ require_relative "lib/github_exporter"
16
+ include GithubExporter
17
+ ARGV.clear
18
+ Pry.start
19
+ end
20
+
21
+ require "rubocop/rake_task"
22
+ desc "Run RuboCop on the lib directory"
23
+ RuboCop::RakeTask.new(:rubocop) do |task|
24
+ task.patterns = ["lib/**/*.rb"]
25
+ # only show the files with failures
26
+ task.formatters = ["files"]
27
+ # don't abort rake on failure
28
+ task.fail_on_error = false
29
+ end
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/github_exporter"
3
+ include GithubExporter
4
+ if ARGV.empty?
5
+ GithubExporter::CLI.start(%w[usage])
6
+ else
7
+ GithubExporter::CLI.start(%w[export].concat(ARGV))
8
+ end
@@ -0,0 +1,49 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "github_exporter/version"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "github_exporter"
7
+ spec.version = GithubExporter::VERSION
8
+ spec.authors = ["Burin Choomnuan"]
9
+ spec.email = ["agilecreativity@gmail.com"]
10
+ spec.summary = %q(Export any project from github to a single pdf file)
11
+ spec.description = %q{Export any project from github to a single pdf file.
12
+ Combine useful features of the following ruby gems
13
+ (vim_printer, html2pdf, pdfs2pdf and others)
14
+ to produce a single pdf file that can be view any where
15
+ where pdf is supported.
16
+ }
17
+ spec.homepage = "https://github.com/agilecreativity/github_exporter"
18
+ spec.license = "MIT"
19
+ spec.files = Dir.glob("{bin,lib,templates}/**/*") + %w[Gemfile
20
+ Rakefile
21
+ github_exporter.gemspec
22
+ README.md
23
+ CHANGELOG.md
24
+ LICENSE
25
+ .rubocop.yml
26
+ .gitignore]
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
29
+ spec.require_paths = ["lib"]
30
+ spec.add_runtime_dependency "thor", "~> 0.19"
31
+ spec.add_runtime_dependency "git", "~> 1.2"
32
+ spec.add_runtime_dependency "awesome_print", "~> 1.2"
33
+ spec.add_runtime_dependency "agile_utils", "~> 0.1.3"
34
+ spec.add_runtime_dependency "code_lister", "~> 0.1.2"
35
+ spec.add_runtime_dependency "vim_printer", "~> 0.1.7"
36
+ spec.add_runtime_dependency "html2pdf", "~> 0.1.6"
37
+ spec.add_runtime_dependency "pdfs2pdf", "~> 0.1.6"
38
+ spec.add_development_dependency "bundler", "~> 1.5"
39
+ spec.add_development_dependency "gem-ctags", "~> 1.0"
40
+ spec.add_development_dependency "guard", "~> 2.6"
41
+ spec.add_development_dependency "guard-minitest", "~> 2.2"
42
+ spec.add_development_dependency "minitest", "~> 5.3"
43
+ spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
44
+ spec.add_development_dependency "pry", "~> 0.9"
45
+ spec.add_development_dependency "pry-theme"
46
+ spec.add_development_dependency "rake", "~> 10.1"
47
+ spec.add_development_dependency "rubocop", "~> 0.23"
48
+ spec.add_development_dependency "yard", "~> 0.8"
49
+ end
@@ -0,0 +1,81 @@
1
+ require "thor"
2
+ require "vim_printer"
3
+ require "html2pdf"
4
+ require "pdfs2pdf"
5
+ require_relative "github_exporter"
6
+ module GithubExporter
7
+ class CLI < Thor
8
+ desc "export", "Export a given URL or project to a single pdf file"
9
+ method_option "url",
10
+ aliases: "-u",
11
+ desc: "The full url of the github project to be cloned",
12
+ required: true
13
+ method_option "exts",
14
+ type: :array,
15
+ aliases: "-e",
16
+ desc: "The list of file extension to be exported",
17
+ required: true
18
+ method_option "non_exts",
19
+ type: :array,
20
+ aliases: "-f",
21
+ desc: "The list of file without extension to be exported",
22
+ default: []
23
+ method_option "theme",
24
+ type: :string,
25
+ aliases: "-t",
26
+ desc: "The theme to be used with vim_printer",
27
+ default: "default"
28
+ def export
29
+ exporter = GithubExporter::Exporter.new options[:url],
30
+ exts: options[:exts],
31
+ non_exts: options[:non_exts],
32
+ theme: options[:theme]
33
+ exporter.export
34
+ end
35
+
36
+ desc "usage", "Display help screen"
37
+ def usage
38
+ puts <<-EOS
39
+ Usage:
40
+
41
+ $github_exporter -e, --exts=EXT1 EXT2 EXT3 -u, --url=URL -theme=theme_name
42
+
43
+ Example:
44
+
45
+ # Export the *.rb from the given repository
46
+
47
+ $github_exporter -e rb -u https://github.com/agilecreativity/filename_cleaner.git
48
+
49
+ # Export the *.rb and also 'Gemfile' from a given directory 'filename_cleaner'
50
+ # Note: must be one directory directly relative to current directory
51
+
52
+ $github_exporter -e rb -f Gemfile -u filename_cleaner
53
+
54
+ # Export the *.rb and also 'Gemfile' from a given directory 'filename_cleaner'
55
+ # using 'solarized' theme
56
+ # Note: must be one directory directly relative to current directory
57
+
58
+ $github_exporter -e rb -f Gemfile -u filename_cleaner -t solarized
59
+
60
+ Options:
61
+
62
+ -u, --url=URL # The full url of the github project to be cloned
63
+
64
+ -e, --exts=EXT1 EXT2 EXT3 .. # The list of extension names to be exported
65
+ # e.g. -e md rb java
66
+
67
+ -f, [--non-exts=one two three] # The list of file without extension to be exported
68
+ # e.g. -f Gemfile LICENSE
69
+
70
+ -t, [--theme=theme_name] # The theme to be used with vim_printer see :h :colorscheme from Vim
71
+ # default: 'default'
72
+ # e.g. -t solarized
73
+
74
+ Export a given URL or project to a single pdf file
75
+
76
+ EOS
77
+ end
78
+
79
+ default_task :usage
80
+ end
81
+ end
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env ruby
2
+ require "uri"
3
+ require "agile_utils"
4
+ require_relative "../github_exporter"
5
+ module GithubExporter
6
+ # The temporary directory
7
+ TMP_DIR = "github_exporter_tmp"
8
+
9
+ class Exporter
10
+ attr_reader :url,
11
+ :exts,
12
+ :non_exts,
13
+ :theme
14
+ attr_reader :base_dir,
15
+ :repo_name,
16
+ :output_path
17
+ # Constructor for Executor
18
+ #
19
+ # @param [String] url the input URL like
20
+ # https://github.com/opal/opal.git or just the immediat folder name
21
+ # @param [Hash<Symbol,Object>] opts the option hash
22
+ #
23
+ # @option opts [Array<String>] :exts the list of file extension to be used
24
+ # @option opts [Array<String>] :non_exts the list of file without extension to be used
25
+ # @option opts [String] :theme the theme to use for `vim_printer`
26
+ def initialize(url, opts = {})
27
+ @url = url
28
+ @base_dir = Dir.pwd
29
+ @exts = opts[:exts] || []
30
+ @non_exts = opts[:non_exts] || []
31
+ @theme = opts[:theme] || "default"
32
+ @repo_name = project_name(url)
33
+ @output_path = File.expand_path([base_dir, repo_name].join(File::SEPARATOR))
34
+ end
35
+
36
+ # Print and export the source from a given URL to a pdf
37
+ def export
38
+ clone
39
+ puts "FYI: list of extensions: #{all_extensions}"
40
+ puts "FYI: list of all files : #{all_files}"
41
+ files2htmls
42
+ htmls2pdfs
43
+ pdfs2pdf
44
+ cleanup
45
+ end
46
+
47
+ def to_s
48
+ <<-EOT
49
+ url : #{url}
50
+ base_dir : #{base_dir}
51
+ exts : #{exts}
52
+ non_exts : #{non_exts}
53
+ repo_name : #{repo_name}
54
+ theme : #{theme}
55
+ output_path : #{output_path}
56
+ EOT
57
+ end
58
+
59
+ private
60
+
61
+ def clone
62
+ if File.exist?(output_path)
63
+ puts "The project #{output_path} already exist, no git clone needed!"
64
+ return
65
+ end
66
+ GithubExporter.clone_repository(url, repo_name, base_dir)
67
+ end
68
+
69
+ # List all extensions
70
+ def all_extensions
71
+ all_exts = GithubExporter.list_extensions(output_path)
72
+ # Strip off the '.' in the output if any.
73
+ all_exts.map! { |e| e.gsub(/^\./, "") }
74
+ all_exts
75
+ end
76
+
77
+ # List all files base on simple criteria
78
+ def all_files
79
+ files = []
80
+ if input_available?
81
+ files = GithubExporter.list_files base_dir: output_path,
82
+ exts: exts,
83
+ non_exts: non_exts,
84
+ recursive: true
85
+
86
+ end
87
+ files
88
+ end
89
+
90
+ # Convert files to htmls
91
+ def files2htmls
92
+ if input_available?
93
+ GithubExporter.files_to_htmls base_dir: output_path,
94
+ exts: exts,
95
+ non_exts: non_exts,
96
+ theme: theme
97
+ end
98
+ end
99
+
100
+ # Convert list of html to list of pdf files
101
+ def htmls2pdfs
102
+ input_file = File.expand_path("#{output_path}/vim_printer_#{repo_name}.tar.gz")
103
+ if File.exist?(input_file)
104
+ FileUtils.mkdir_p output_dir
105
+ # input_file = File.expand_path("#{output_path}/vim_printer_#{repo_name}.tar.gz")
106
+ AgileUtils::FileUtil.gunzip input_file, output_dir
107
+ GithubExporter.htmls_to_pdfs(base_dir: output_dir)
108
+ end
109
+ end
110
+
111
+ # Merge/join multiple pdf files into single pdf
112
+ def pdfs2pdf
113
+ input_file = File.expand_path("#{output_dir}/html2pdf_#{repo_name}.tar.gz")
114
+ if File.exist?(input_file)
115
+ AgileUtils::FileUtil.gunzip input_file, output_dir
116
+ GithubExporter.pdfs_to_pdf base_dir: output_dir,
117
+ recursive: true
118
+ end
119
+ end
120
+
121
+ def cleanup
122
+ generated_file = "#{output_dir}/pdfs2pdf_#{repo_name}.pdf"
123
+ if File.exist?(generated_file)
124
+ destination_file = File.expand_path(File.dirname(output_dir) + "../../#{repo_name}.pdf")
125
+ FileUtils.mv generated_file, destination_file
126
+ puts "Your final output is #{File.expand_path(destination_file)}"
127
+
128
+ # Now cleanup the generated files
129
+ FileUtils.rm_rf File.expand_path(File.dirname(output_dir) + "../../#{GithubExporter::TMP_DIR}")
130
+
131
+ # Also remove the 'vim_printer_#{repo_name}.tar.gz' if we have one
132
+ FileUtils.rm_rf File.expand_path(File.dirname(output_dir) + "../../#{repo_name}/vim_printer_#{repo_name}.tar.gz")
133
+ end
134
+ end
135
+
136
+ private
137
+
138
+ def output_dir
139
+ File.expand_path("#{base_dir}/#{GithubExporter::TMP_DIR}/#{repo_name}")
140
+ end
141
+
142
+ def input_available?
143
+ (exts && !exts.empty?) || (non_exts && !non_exts.empty?)
144
+ end
145
+
146
+ # Extract project name from a given URL
147
+ #
148
+ # @param [String] uri input uri
149
+ #
150
+ # example:
151
+ #
152
+ # project_name('https://github.com/erikhuda/thor.git') #=> 'thor'
153
+ # project_name('https://github.com/erikhuda/thor') #=> 'thor'
154
+ def project_name(uri)
155
+ if uri
156
+ name = URI(uri).path.split(File::SEPARATOR).last
157
+ # strip the '.' if any
158
+ File.basename(name, ".*") if name
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,80 @@
1
+ require "tmpdir"
2
+ require "git"
3
+ require "code_lister"
4
+ require "awesome_print"
5
+ module GithubExporter
6
+ CustomError = Class.new(StandardError)
7
+ class << self
8
+ # Clone the given repository from github
9
+ #
10
+ # @param [String] url the github repository url like 'https://github.com/schacon/ruby-git.git'
11
+ # @param [String] name the output name to be used
12
+ # @param [String] path the output directory
13
+ def clone_repository(url, name, path)
14
+ puts "git clone #{url} #{File.expand_path(path)}/#{name}"
15
+ Git.clone url, name, path: File.expand_path(path)
16
+ end
17
+
18
+ def list_extensions(base_dir = ".")
19
+ extensions = Dir.glob(File.join(File.expand_path(base_dir), "**/*")).reduce([]) do |exts, file|
20
+ exts << File.extname(file)
21
+ end
22
+ extensions.sort.uniq.delete_if { |e| e == "" }
23
+ end
24
+
25
+ def list_files(options = {})
26
+ CodeLister.files(options)
27
+ end
28
+
29
+ def files_to_htmls(opts)
30
+ base_dir = base_dir(opts[:base_dir])
31
+ exts = opts[:exts] || []
32
+ non_exts = opts[:non_exts] || []
33
+ args = [
34
+ "print",
35
+ "--base-dir",
36
+ base_dir,
37
+ "--exts",
38
+ exts,
39
+ "--theme",
40
+ opts.fetch(:theme, "default"),
41
+ "--recursive"
42
+ ]
43
+
44
+ # Add file without the extension if any
45
+ unless non_exts.empty?
46
+ args.concat(["--non-exts"]).concat(non_exts)
47
+ end
48
+ puts "Your input options for VimPrinter : #{args}"
49
+ VimPrinter::CLI.start(args)
50
+ end
51
+
52
+ # Export list of html files to pdfs using `html2pdf` gem
53
+ def htmls_to_pdfs(opts)
54
+ base_dir = base_dir(opts[:base_dir])
55
+ Html2Pdf::CLI.start [
56
+ "export",
57
+ "--base-dir",
58
+ base_dir,
59
+ "--recursive"]
60
+ end
61
+
62
+ # Merge/combine pdfs using `pdfs2pdf` gem
63
+ def pdfs_to_pdf(opts)
64
+ base_dir = base_dir(opts[:base_dir])
65
+ Pdfs2Pdf::CLI.start [
66
+ "merge",
67
+ "--base-dir",
68
+ base_dir,
69
+ "--recursive"
70
+ ]
71
+ end
72
+
73
+ private
74
+
75
+ # Always expand the directory name so that '~' or '.' is expanded correctly
76
+ def base_dir(dir_name)
77
+ File.expand_path(dir_name)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,10 @@
1
+ require "logger"
2
+ module GithubExporter
3
+ class << self
4
+ attr_writer :logger
5
+ # @return [Logger] the logger for the project
6
+ def logger
7
+ @logger ||= Logger.new STDOUT
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module GithubExporter
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "github_exporter/version"
2
+ require_relative "github_exporter/logger"
3
+ require_relative "github_exporter/github_exporter"
4
+ require_relative "github_exporter/exporter"
5
+ require_relative "github_exporter/cli"
6
+ include GithubExporter
metadata ADDED
@@ -0,0 +1,331 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Burin Choomnuan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: agile_utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: code_lister
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.1.2
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.1.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: vim_printer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.7
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.7
97
+ - !ruby/object:Gem::Dependency
98
+ name: html2pdf
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.6
111
+ - !ruby/object:Gem::Dependency
112
+ name: pdfs2pdf
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.1.6
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.1.6
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.5'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: gem-ctags
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '2.6'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '2.6'
167
+ - !ruby/object:Gem::Dependency
168
+ name: guard-minitest
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '2.2'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '2.2'
181
+ - !ruby/object:Gem::Dependency
182
+ name: minitest
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '5.3'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '5.3'
195
+ - !ruby/object:Gem::Dependency
196
+ name: minitest-spec-context
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.0.3
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.0.3
209
+ - !ruby/object:Gem::Dependency
210
+ name: pry
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '0.9'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '0.9'
223
+ - !ruby/object:Gem::Dependency
224
+ name: pry-theme
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: rake
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: '10.1'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: '10.1'
251
+ - !ruby/object:Gem::Dependency
252
+ name: rubocop
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '0.23'
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: '0.23'
265
+ - !ruby/object:Gem::Dependency
266
+ name: yard
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - "~>"
270
+ - !ruby/object:Gem::Version
271
+ version: '0.8'
272
+ type: :development
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - "~>"
277
+ - !ruby/object:Gem::Version
278
+ version: '0.8'
279
+ description: "Export any project from github to a single pdf file.\n Combine
280
+ useful features of the following ruby gems\n (vim_printer,
281
+ html2pdf, pdfs2pdf and others)\n to produce a single pdf
282
+ file that can be view any where\n where pdf is supported.\n
283
+ \ "
284
+ email:
285
+ - agilecreativity@gmail.com
286
+ executables:
287
+ - github_exporter
288
+ extensions: []
289
+ extra_rdoc_files: []
290
+ files:
291
+ - ".gitignore"
292
+ - ".rubocop.yml"
293
+ - CHANGELOG.md
294
+ - Gemfile
295
+ - LICENSE
296
+ - README.md
297
+ - Rakefile
298
+ - bin/github_exporter
299
+ - github_exporter.gemspec
300
+ - lib/github_exporter.rb
301
+ - lib/github_exporter/cli.rb
302
+ - lib/github_exporter/exporter.rb
303
+ - lib/github_exporter/github_exporter.rb
304
+ - lib/github_exporter/logger.rb
305
+ - lib/github_exporter/version.rb
306
+ homepage: https://github.com/agilecreativity/github_exporter
307
+ licenses:
308
+ - MIT
309
+ metadata: {}
310
+ post_install_message:
311
+ rdoc_options: []
312
+ require_paths:
313
+ - lib
314
+ required_ruby_version: !ruby/object:Gem::Requirement
315
+ requirements:
316
+ - - ">="
317
+ - !ruby/object:Gem::Version
318
+ version: '0'
319
+ required_rubygems_version: !ruby/object:Gem::Requirement
320
+ requirements:
321
+ - - ">="
322
+ - !ruby/object:Gem::Version
323
+ version: '0'
324
+ requirements: []
325
+ rubyforge_project:
326
+ rubygems_version: 2.2.2
327
+ signing_key:
328
+ specification_version: 4
329
+ summary: Export any project from github to a single pdf file
330
+ test_files: []
331
+ has_rdoc: