source2pdf 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4bc32d6aef760e36fbce5d5ce3c8930a7e037966
4
+ data.tar.gz: 3a0489be411d220b1705b80b076dfd362a6d83f5
5
+ SHA512:
6
+ metadata.gz: acc7a07dec0d07f1217abfa52a72de50668e6917daf5eb80c34a866a3c3e058c19c8864263ff839ef9d0046a10e4624a6ba43598faf6be73b811c1b046769e1b
7
+ data.tar.gz: 7cf77c0b0fec48cbd4f2e1aabbfc4bd52d505a237075b3c0dd15e5c042e62c45daed6d09647924425979f4c31cfec8e3fd0dfce041bc57aa6b8acdbb57a63b06
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,78 @@
1
+ AllCops:
2
+ Include:
3
+ - Gemfile
4
+ - Rakefile
5
+ - bin/*
6
+ - source2pdf.gemspec
7
+ - lib/**/*.rb
8
+ - test/**/*.rb
9
+
10
+ # Avoid long parameter lists
11
+ ParameterLists:
12
+ Max: 5
13
+ CountKeywordArgs: true
14
+
15
+ MethodLength:
16
+ CountComments: false
17
+ Max: 15
18
+
19
+ # Avoid more than `Max` levels of nesting.
20
+ BlockNesting:
21
+ Max: 4
22
+
23
+ AccessModifierIndentation:
24
+ Enabled: false
25
+
26
+ # Limit line length
27
+ LineLength:
28
+ Enabled: false
29
+
30
+ # Disable documentation checking until a class needs to be documented once
31
+ Documentation:
32
+ Enabled: false
33
+
34
+ # Enforce Ruby 1.8-compatible hash syntax
35
+ HashSyntax:
36
+ Enabled: true
37
+
38
+ # Use spaces inside hash literals
39
+ SpaceInsideHashLiteralBraces:
40
+ EnforcedStyle: space
41
+
42
+ # Allow dots at the end of lines
43
+ DotPosition:
44
+ Enabled: false
45
+
46
+ # Don't require magic comment at the top of every file
47
+ Encoding:
48
+ Enabled: false
49
+
50
+ EmptyLinesAroundAccessModifier:
51
+ Enabled: true
52
+
53
+ # Align ends correctly
54
+ EndAlignment:
55
+ AlignWith: variable
56
+
57
+ # Indentation of when/else
58
+ CaseIndentation:
59
+ IndentWhenRelativeTo: end
60
+ IndentOneStep: false
61
+
62
+ DoubleNegation:
63
+ Enabled: false
64
+
65
+ PercentLiteralDelimiters:
66
+ PreferredDelimiters:
67
+ '%': ()
68
+ '%i': ()
69
+ '%q': ()
70
+ '%Q': ()
71
+ '%r': '{}'
72
+ '%s': ()
73
+ '%w': '[]'
74
+ '%W': '[]'
75
+ '%x': ()
76
+
77
+ StringLiterals:
78
+ EnforcedStyle: double_quotes
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ #### 0.2.0
2
+
3
+ - First public release as `source2pdf` gem
4
+ - Rename the gem from `github_exporter` to `source2pdf`
5
+ - Support Github/BitBucket or any git hosting services (your private hosting included)
6
+ - Only support ruby 2.0.0+ upward to use new refinement feature instead of monkeypatching
7
+ - Use precise gem version for gemspec file
8
+
9
+ #### 0.1.0 - 0.1.5
10
+
11
+ - Release as 'github_exporter' gem
12
+
13
+ [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,157 @@
1
+ ## source2pdf
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/source2pdf.svg)][gem]
4
+ [![Dependency Status](https://gemnasium.com/agilecreativity/source2pdf.png)][gemnasium]
5
+ [![Code Climate](https://codeclimate.com/github/agilecreativity/source2pdf.png)][codeclimate]
6
+
7
+ [gem]: http://badge.fury.io/rb/source2pdf
8
+ [gemnasium]: https://gemnasium.com/agilecreativity/source2pdf
9
+ [codeclimate]: https://codeclimate.com/github/agilecreativity/source2pdf
10
+
11
+ Export/print content of a given git repository (or local project directory) to a 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 source2pdf
23
+ ```
24
+
25
+ ## Synopsis/Usage
26
+
27
+ ### Basic Usage
28
+
29
+ ```shell
30
+ Usage:
31
+
32
+ $source2pdf -e, --exts=EXT1 EXT2 EXT3 -u, --url=URL -theme=theme_name --output-name=output_file.pdf
33
+
34
+ Example:
35
+
36
+ # Export the *.rb from the given repository
37
+
38
+ $source2pdf -e rb -u https://github.com/agilecreativity/source2pdf.git
39
+
40
+ # Export the *.rb and also 'Gemfile' from a 'source2pdf' directory
41
+ # Note: this directory must be directly below the current directory
42
+
43
+ $source2pdf -e rb -f Gemfile -u source2pdf
44
+
45
+ # Same as previous command with the 'solarized' instead of 'default' colorscheme
46
+ $source2pdf -e rb -f Gemfile -u filename_cleaner -t solarized
47
+
48
+ Options:
49
+
50
+ -u, --url=URL # The full url of the github project to be cloned OR local directory name
51
+
52
+ -e, --exts=EXT1 EXT2 EXT3 .. # The list of extension names to be exported
53
+ # e.g. -e md rb java
54
+
55
+ -f, [--non-exts=one two three] # The list of file without extension to be exported
56
+ # e.g. -f Gemfile LICENSE
57
+
58
+ -t, [--theme=theme_name] # The theme/colorscheme to be used with vim_printer see :help :colorscheme from inside Vim
59
+ # default: 'default'
60
+ # e.g. -t solarized
61
+
62
+ -o, [--output-name=output.pdf] # The output pdf filename (will default to 'repository_name'.pdf)
63
+ # e.g. -o repository_name.pdf
64
+
65
+ Export a given Github project or a local project directory to a single pdf file
66
+
67
+ ```
68
+
69
+ ### Sample Usage:
70
+
71
+ ```shell
72
+ source2pdf -u https://github.com/agilecreativity/source2pdf.git -e rb
73
+ ```
74
+
75
+ Should result in something similar to this in the console
76
+
77
+ ```
78
+ The project /Users/agilecreativity/Desktop/source2pdf already exist, no git clone needed!
79
+ FYI: list of extensions: ["gem", "gemspec", "lock", "md", "pdf", "png", "rb"]
80
+ FYI: list of all files : ["./lib/source2pdf.rb", "./lib/source2pdf/cli.rb", "./lib/source2pdf/source2pdf.rb", "./lib/source2pdf/exporter.rb", "./lib/source2pdf/logger.rb", "./lib/source2pdf/version.rb", "./test/lib/github_exporter/test_github_exporter.rb", "./test/test_helper.rb"]
81
+ FYI: input options for VimPrinter : ["print", "--base-dir", "/Users/agilecreativity/Desktop/source2pdf", "--exts", ["rb"], "--theme", "seoul256", "--recursive"]
82
+ FYI: process file 1 of 8 : ./lib/source2pdf.rb
83
+ FYI: process file 2 of 8 : ./lib/source2pdf/cli.rb
84
+ FYI: process file 3 of 8 : ./lib/source2pdf/source2pdf.rb
85
+ FYI: process file 4 of 8 : ./lib/source2pdf/exporter.rb
86
+ FYI: process file 5 of 8 : ./lib/source2pdf/logger.rb
87
+ FYI: process file 6 of 8 : ./lib/source2pdf/version.rb
88
+ FYI: process file 7 of 8 : ./test/lib/github_exporter/test_github_exporter.rb
89
+ FYI: process file 8 of 8 : ./test/test_helper.rb
90
+ Your output file is '/Users/agilecreativity/Desktop/source2pdf/vim_printer_source2pdf.tar.gz'
91
+ Convert file 1 of 9 : ./index.html
92
+ Convert file 2 of 9 : ./lib/source2pdf.rb.xhtml
93
+ Convert file 3 of 9 : ./lib/source2pdf/cli.rb.xhtml
94
+ Convert file 4 of 9 : ./lib/source2pdf/source2pdf.rb.xhtml
95
+ Convert file 5 of 9 : ./lib/source2pdf/exporter.rb.xhtml
96
+ Convert file 6 of 9 : ./lib/source2pdf/logger.rb.xhtml
97
+ Convert file 7 of 9 : ./lib/source2pdf/version.rb.xhtml
98
+ Convert file 8 of 9 : ./test/lib/github_exporter/test_github_exporter.rb.xhtml
99
+ Convert file 9 of 9 : ./test/test_helper.rb.xhtml
100
+ Convert files to pdfs took 8.01304 ms
101
+ Your final output is '/Users/agilecreativity/Desktop/source2pdf_tmp/source2pdf/html2pdf_source2pdf.tar.gz'
102
+ Create pdfmarks took 0.026689 ms
103
+ Combine pdf files took 0.463659 ms
104
+ Your combined pdf is available at /Users/agilecreativity/Desktop/source2pdf_tmp/source2pdf/pdfs2pdf_source2pdf.pdf
105
+ Your final output is /Users/agilecreativity/Desktop/source2pdf.pdf
106
+ ```
107
+
108
+ ### Sample Output
109
+
110
+ #### Using the 'default' theme/colorscheme for Vim
111
+
112
+ ```shell
113
+ source2pdf -u https://github.com/agilecreativity/source2pdf.git --exts rb
114
+ ```
115
+
116
+ Which generated the following [pdf output file](https://github.com/agilecreativity/source2pdf/raw/master/samples/source2pdf_default_colorscheme.pdf)
117
+
118
+ The example screenshot:
119
+
120
+ ![](https://github.com/agilecreativity/source2pdf/raw/master/samples/source2pdf_default_colorscheme.png)
121
+
122
+ #### Use non-default colorscheme/theme for Vim
123
+
124
+ Use my favourite [seoul256][] colorscheme
125
+
126
+ ```shell
127
+ source2pdf -u https://github.com/agilecreativity/source2pdf.git --exts rb --theme seoul256
128
+ ```
129
+
130
+ Which generated the following [pdf output file](https://github.com/agilecreativity/source2pdf/raw/master/samples/source2pdf_seoul256_colorscheme.pdf)
131
+
132
+ The example screenshot:
133
+
134
+ ![](https://github.com/agilecreativity/source2pdf/raw/master/samples/source2pdf_seoul256_colorscheme.png)
135
+
136
+ ### Contributing
137
+
138
+ 1. Fork it
139
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
140
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
141
+ 4. Push to the branch (`git push origin my-new-feature`)
142
+ 5. Create new Pull Request
143
+
144
+ [thor]: https://github.com/erikhuda/thor
145
+ [minitest]: https://github.com/seattlerb/minitest
146
+ [yard]: https://github.com/lsegal/yard
147
+ [pry]: https://github.com/pry/pry
148
+ [rubocop]: https://github.com/bbatsov/rubocop
149
+ [grit]: https://github.com/mojombo/grit
150
+ [Ghostscript]: http://ghostscript.com/doc/current/Install.htm
151
+ [Wkhtmltopdf]: https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF
152
+ [Vim]: http://www.vim.org
153
+ [vim_printer]: https://github.com/agilecreativity/vim_printer
154
+ [pdfs2pdf]: https://github.com/agilecreativity/pdfs2pdf
155
+ [html2pdf]: https://github.com/agilecreativity/html2pdf
156
+ [monokai]: https://github.com/lsdr/monokai
157
+ [seoul256]: https://github.com/junegunn/seoul256.vim
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ project_name = "source2pdf"
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/source2pdf"
16
+ include Source2Pdf
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
+ task.formatters = ["files"]
26
+ task.fail_on_error = false
27
+ end
data/bin/source2pdf ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/source2pdf"
3
+ include Source2Pdf
4
+ if ARGV.empty?
5
+ Source2Pdf::CLI.start(%w[usage])
6
+ else
7
+ Source2Pdf::CLI.start(%w[export].concat(ARGV))
8
+ end
@@ -0,0 +1,92 @@
1
+ require "thor"
2
+ require "vim_printer"
3
+ require "html2pdf"
4
+ require "pdfs2pdf"
5
+ require "agile_utils"
6
+ require_relative "source2pdf"
7
+ module Source2Pdf
8
+ class CLI < Thor
9
+ using AgileUtils::HashExt
10
+
11
+ desc "export", "Export a given Git's project or a local project to a single pdf file"
12
+ method_option "url",
13
+ aliases: "-u",
14
+ desc: "The full url of the git project to be cloned or local project directory (mandatory)",
15
+ required: true
16
+ method_option "exts",
17
+ type: :array,
18
+ aliases: "-e",
19
+ desc: "The list of file extension to be exported (mandatory)",
20
+ required: true
21
+ method_option "non_exts",
22
+ type: :array,
23
+ aliases: "-f",
24
+ desc: "The list of file without extension to be exported (optional)",
25
+ default: []
26
+ method_option "theme",
27
+ type: :string,
28
+ aliases: "-t",
29
+ desc: "The theme to be used with vim_printer (optional)",
30
+ default: "default"
31
+ method_option "output_name",
32
+ type: :string,
33
+ aliases: "-o",
34
+ desc: "The output filename (optional)"
35
+ def export
36
+ #opts = options.symbolize_keys(options)
37
+ opts = options
38
+ exporter = Source2Pdf::Exporter.new opts[:url],
39
+ exts: opts[:exts],
40
+ non_exts: opts[:non_exts],
41
+ theme: opts[:theme],
42
+ output_name: opts[:output_name]
43
+
44
+ exporter.export
45
+ end
46
+
47
+ desc "usage", "Display help screen"
48
+ def usage
49
+ puts <<-EOS
50
+ Usage:
51
+
52
+ $source2pdf -u, --url=URL -e, --exts=EXT1 EXT2 EXT3 -t, --theme=theme_name -o, --output-name=output_file.pdf
53
+
54
+ Example:
55
+
56
+ # Export the *.rb from the given repository
57
+
58
+ $source2pdf -u https://github.com/agilecreativity/source2pdf.git -e rb
59
+
60
+ # Export the *.rb and also 'Gemfile' from a 'source2pdf' directory
61
+ # Note: this directory must be directly below the current directory
62
+
63
+ $source2pdf -u source2pdf -e rb -f Gemfile
64
+
65
+ # Same as previous command with the 'solarized' instead of 'default' colorscheme
66
+ $source2pdf -u source2pdf -e rb -f Gemfile -t solarized
67
+
68
+ Options:
69
+
70
+ -u, --url=URL # The full url of the git repository to be cloned OR local directory name
71
+
72
+ -e, --exts=EXT1 EXT2 EXT3 .. # The list of extension names to be exported
73
+ # e.g. -e md rb java
74
+
75
+ -f, [--non-exts=one two three] # The list of file without extension to be exported
76
+ # e.g. -f Gemfile LICENSE
77
+
78
+ -t, [--theme=theme_name] # The theme/colorscheme to be used with vim_printer see :help :colorscheme from inside Vim
79
+ # default: 'default'
80
+ # e.g. -t solarized
81
+
82
+ -o, [--output-name=output.pdf] # The output pdf filename (will default to 'repository_name'.pdf)
83
+ # e.g. -o repository_name.pdf
84
+
85
+ Export a given Git's repository or a local project directory to a single pdf file
86
+
87
+ EOS
88
+ end
89
+
90
+ default_task :usage
91
+ end
92
+ end
@@ -0,0 +1,169 @@
1
+ require "uri"
2
+ require "agile_utils"
3
+ require_relative "../source2pdf"
4
+ module Source2Pdf
5
+ TMP_DIR = "source2pdf_tmp"
6
+ # rubocop:disable ClassLength, MethodLength
7
+ class Exporter
8
+ attr_reader :url,
9
+ :exts,
10
+ :non_exts,
11
+ :theme,
12
+ :output_name
13
+
14
+ attr_reader :base_dir,
15
+ :repo_name,
16
+ :output_path
17
+
18
+ # The initializer for Exporter
19
+ #
20
+ # @param [String] url the input URL like
21
+ # https://github.com/opal/opal.git or just the immediate folder name
22
+ # @param [Hash<Symbol,Object>] opts the option hash
23
+ #
24
+ # @option opts [Array<String>] :exts the list of file extension to be used
25
+ # @option opts [Array<String>] :non_exts the list of file without extension to be used
26
+ # @option opts [String] :theme the colorscheme to use with `vim_printer`
27
+ # @option opts [String] :output_name the output filename if any
28
+ def initialize(url, opts = {})
29
+ @url = url
30
+ @base_dir = Dir.pwd
31
+ @exts = opts[:exts] || []
32
+ @non_exts = opts[:non_exts] || []
33
+ @theme = opts[:theme] || "default"
34
+ @repo_name = project_name(url)
35
+ @output_path = File.expand_path([base_dir, repo_name].join(File::SEPARATOR))
36
+ @output_name = pdf_filename(opts[:output_name]) || "#{@repo_name}.pdf"
37
+ end
38
+
39
+ # Print and export the source from a given URL to a pdf
40
+ def export
41
+ clone
42
+ puts "FYI: list of extensions: #{all_extensions}"
43
+ puts "FYI: list of all files : #{all_files}"
44
+ files2htmls
45
+ htmls2pdfs
46
+ pdfs2pdf
47
+ copy_output
48
+ cleanup
49
+ end
50
+
51
+ def to_s
52
+ <<-EOT
53
+ url : #{url}
54
+ base_dir : #{base_dir}
55
+ exts : #{exts}
56
+ non_exts : #{non_exts}
57
+ repo_name : #{repo_name}
58
+ theme : #{theme}
59
+ output_path : #{output_path}
60
+ output_name : #{output_name}
61
+ EOT
62
+ end
63
+
64
+ private
65
+
66
+ def clone
67
+ if File.exist?(output_path)
68
+ puts "The project #{output_path} already exist, no git clone needed!"
69
+ return
70
+ end
71
+ Source2Pdf.clone_repository(url, repo_name, base_dir)
72
+ end
73
+
74
+ # List all extensions
75
+ def all_extensions
76
+ all_exts = Source2Pdf.list_extensions(output_path)
77
+ # Strip off the '.' in the output if any.
78
+ all_exts.map! { |e| e.gsub(/^\./, "") }
79
+ all_exts
80
+ end
81
+
82
+ # List all files base on simple criteria
83
+ def all_files
84
+ files = []
85
+ if input_available?
86
+ files = Source2Pdf.list_files base_dir: output_path,
87
+ exts: exts,
88
+ non_exts: non_exts,
89
+ recursive: true
90
+ end
91
+ files
92
+ end
93
+
94
+ # Convert files to htmls
95
+ def files2htmls
96
+ Source2Pdf.files_to_htmls base_dir: output_path,
97
+ exts: exts,
98
+ non_exts: non_exts,
99
+ theme: theme if input_available?
100
+ end
101
+
102
+ # Convert list of html to list of pdf files
103
+ def htmls2pdfs
104
+ input_file = File.expand_path("#{output_path}/vim_printer_#{repo_name}.tar.gz")
105
+ FileUtils.mkdir_p output_dir
106
+ AgileUtils::FileUtil.gunzip input_file, output_dir if File.exist?(input_file)
107
+ Source2Pdf.htmls_to_pdfs base_dir: output_dir
108
+ end
109
+
110
+ # Merge/join multiple pdf files into single pdf
111
+ def pdfs2pdf
112
+ input_file = File.expand_path("#{output_dir}/html2pdf_#{repo_name}.tar.gz")
113
+ AgileUtils::FileUtil.gunzip input_file, output_dir if File.exist?(input_file)
114
+ Source2Pdf.pdfs_to_pdf base_dir: output_dir,
115
+ recursive: true
116
+ end
117
+
118
+ def copy_output
119
+ generated_file = "#{output_dir}/pdfs2pdf_#{repo_name}.pdf"
120
+ destination_file = File.expand_path(File.dirname(output_dir) + "../../#{output_name}")
121
+ FileUtils.mv generated_file, destination_file if File.exist?(generated_file)
122
+ puts "Your final output is #{File.expand_path(destination_file)}"
123
+ end
124
+
125
+ def cleanup
126
+ FileUtils.rm_rf File.expand_path(File.dirname(output_dir) + "../../#{Source2Pdf::TMP_DIR}")
127
+ FileUtils.rm_rf File.expand_path(File.dirname(output_dir) + "../../#{repo_name}/vim_printer_#{repo_name}.tar.gz")
128
+ end
129
+
130
+ def output_dir
131
+ File.expand_path("#{base_dir}/#{Source2Pdf::TMP_DIR}/#{repo_name}")
132
+ end
133
+
134
+ def input_available?
135
+ (exts && !exts.empty?) || (non_exts && !non_exts.empty?)
136
+ end
137
+
138
+ # Extract project name from a given URL
139
+ #
140
+ # @param [String] uri input uri
141
+ #
142
+ # example:
143
+ #
144
+ # project_name('https://github.com/erikhuda/thor.git') #=> 'thor'
145
+ # project_name('https://github.com/erikhuda/thor') #=> 'thor'
146
+ def project_name(uri)
147
+ name = URI(uri).path.split(File::SEPARATOR).last if uri
148
+ File.basename(name, ".*") if name
149
+ end
150
+
151
+ # Add/rename the file extension to pdf
152
+ #
153
+ # @param [String] filename input file
154
+ # @return [String,NilClass] output file with .pdf as extension or nil
155
+ def pdf_filename(filename)
156
+ return nil unless filename
157
+ extname = File.extname(filename)
158
+ basename = File.basename(filename, ".*")
159
+ if extname == ""
160
+ "#{filename}.pdf"
161
+ elsif extname != ".pdf"
162
+ "#{basename}.pdf"
163
+ else
164
+ filename
165
+ end
166
+ end
167
+ end
168
+ # robocop:enable All
169
+ end
@@ -0,0 +1,10 @@
1
+ require "logger"
2
+ module Source2Pdf
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,76 @@
1
+ require "tmpdir"
2
+ require "git"
3
+ require "code_lister"
4
+ module Source2Pdf
5
+ CustomError = Class.new(StandardError)
6
+ class << self
7
+ # Clone the given repository from git repository
8
+ #
9
+ # @param [String] url the github repository url like 'https://github.com/schacon/ruby-git.git'
10
+ # @param [String] name the output name to be used
11
+ # @param [String] path the output directory
12
+ def clone_repository(url, name, path)
13
+ puts "git clone #{url} #{File.expand_path(path)}/#{name}"
14
+ Git.clone url, name, path: File.expand_path(path)
15
+ end
16
+
17
+ def list_extensions(base_dir = ".")
18
+ extensions = Dir.glob(File.join(File.expand_path(base_dir), "**/*")).reduce([]) do |exts, file|
19
+ exts << File.extname(file)
20
+ end
21
+ extensions.sort.uniq.delete_if { |e| e == "" }
22
+ end
23
+
24
+ def list_files(options = {})
25
+ CodeLister.files(options)
26
+ end
27
+
28
+ def files_to_htmls(opts)
29
+ base_dir = base_dir(opts[:base_dir])
30
+ exts = opts[:exts] || []
31
+ non_exts = opts[:non_exts] || []
32
+ args = [
33
+ "print",
34
+ "--base-dir",
35
+ base_dir,
36
+ "--exts",
37
+ exts,
38
+ "--theme",
39
+ opts.fetch(:theme, "default"),
40
+ "--recursive"
41
+ ]
42
+ args.concat(["--non-exts"]).concat(non_exts) unless non_exts.empty?
43
+
44
+ puts "FYI: input options for VimPrinter : #{args}"
45
+ VimPrinter::CLI.start(args)
46
+ end
47
+
48
+ # Export list of html files to pdfs using `html2pdf` gem
49
+ def htmls_to_pdfs(opts)
50
+ base_dir = base_dir(opts[:base_dir])
51
+ Html2Pdf::CLI.start [
52
+ "export",
53
+ "--base-dir",
54
+ base_dir,
55
+ "--recursive"]
56
+ end
57
+
58
+ # Merge/combine pdfs using `pdfs2pdf` gem
59
+ def pdfs_to_pdf(opts)
60
+ base_dir = base_dir(opts[:base_dir])
61
+ Pdfs2Pdf::CLI.start [
62
+ "merge",
63
+ "--base-dir",
64
+ base_dir,
65
+ "--recursive"
66
+ ]
67
+ end
68
+
69
+ private
70
+
71
+ # Always expand the directory name so that '~' or '.' is expanded correctly
72
+ def base_dir(dir_name)
73
+ File.expand_path(dir_name)
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module Source2Pdf
2
+ VERSION = "0.2.0"
3
+ end
data/lib/source2pdf.rb ADDED
@@ -0,0 +1,6 @@
1
+ require_relative "source2pdf/version"
2
+ require_relative "source2pdf/logger"
3
+ require_relative "source2pdf/source2pdf"
4
+ require_relative "source2pdf/exporter"
5
+ require_relative "source2pdf/cli"
6
+ include Source2Pdf
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "source2pdf/version"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "source2pdf"
7
+ spec.version = Source2Pdf::VERSION
8
+ spec.authors = ["Burin Choomnuan"]
9
+ spec.email = ["agilecreativity@gmail.com"]
10
+ spec.summary = "Export any project from a given git repository or a local project directory to a single pdf file"
11
+ spec.description = "Export any project from a given git repository (or a local directory) to a single pdf file.
12
+ Combine useful features of vim_printer, html2pdf, pdfs2pdf and others
13
+ to produce a single pdf file for quick review."
14
+ spec.homepage = "https://github.com/agilecreativity/source2pdf"
15
+ spec.license = "MIT"
16
+ spec.files = Dir.glob("{bin,lib,templates}/**/*") + %w[Gemfile
17
+ Rakefile
18
+ source2pdf.gemspec
19
+ README.md
20
+ CHANGELOG.md
21
+ LICENSE
22
+ .rubocop.yml
23
+ .gitignore]
24
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
25
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_runtime_dependency "thor", "~> 0.19.1"
29
+ spec.add_runtime_dependency "git", "~> 1.2.7"
30
+ spec.add_runtime_dependency "agile_utils", "~> 0.2.0"
31
+ spec.add_runtime_dependency "code_lister", "~> 0.2.0"
32
+ spec.add_runtime_dependency "vim_printer", "~> 0.2.0"
33
+ spec.add_runtime_dependency "html2pdf", "~> 0.2.0"
34
+ spec.add_runtime_dependency "pdfs2pdf", "~> 0.2.0"
35
+ spec.add_development_dependency "awesome_print", "~> 1.2.0"
36
+ spec.add_development_dependency "bundler", "~> 1.6.2"
37
+ spec.add_development_dependency "gem-ctags", "~> 1.0.6"
38
+ spec.add_development_dependency "guard", "~> 2.6.1"
39
+ spec.add_development_dependency "guard-minitest", "~> 2.3.1"
40
+ spec.add_development_dependency "minitest", "~> 5.3"
41
+ spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
42
+ spec.add_development_dependency "pry", "~> 0.10.0"
43
+ spec.add_development_dependency "pry-theme", "~> 1.1.3"
44
+ spec.add_development_dependency "rake", "~> 10.3.2"
45
+ spec.add_development_dependency "rubocop", "~> 0.24.1"
46
+ spec.add_development_dependency "yard", "~> 0.8.7"
47
+ end
metadata ADDED
@@ -0,0 +1,331 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: source2pdf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Burin Choomnuan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-30 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.1
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.1
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.7
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.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: agile_utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: code_lister
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: vim_printer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: html2pdf
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.2.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: pdfs2pdf
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: awesome_print
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.2.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.2.0
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.6.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.6.2
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.6
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.6
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.1
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.1
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.3.1
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 2.3.1
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.10.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 0.10.0
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: 1.1.3
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 1.1.3
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.3.2
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 10.3.2
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.24.1
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: 0.24.1
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.7
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.7
279
+ description: |-
280
+ Export any project from a given git repository (or a local directory) to a single pdf file.
281
+ Combine useful features of vim_printer, html2pdf, pdfs2pdf and others
282
+ to produce a single pdf file for quick review.
283
+ email:
284
+ - agilecreativity@gmail.com
285
+ executables:
286
+ - source2pdf
287
+ extensions: []
288
+ extra_rdoc_files: []
289
+ files:
290
+ - ".gitignore"
291
+ - ".rubocop.yml"
292
+ - CHANGELOG.md
293
+ - Gemfile
294
+ - LICENSE
295
+ - README.md
296
+ - Rakefile
297
+ - bin/source2pdf
298
+ - lib/source2pdf.rb
299
+ - lib/source2pdf/cli.rb
300
+ - lib/source2pdf/exporter.rb
301
+ - lib/source2pdf/logger.rb
302
+ - lib/source2pdf/source2pdf.rb
303
+ - lib/source2pdf/version.rb
304
+ - source2pdf.gemspec
305
+ homepage: https://github.com/agilecreativity/source2pdf
306
+ licenses:
307
+ - MIT
308
+ metadata: {}
309
+ post_install_message:
310
+ rdoc_options: []
311
+ require_paths:
312
+ - lib
313
+ required_ruby_version: !ruby/object:Gem::Requirement
314
+ requirements:
315
+ - - ">="
316
+ - !ruby/object:Gem::Version
317
+ version: '0'
318
+ required_rubygems_version: !ruby/object:Gem::Requirement
319
+ requirements:
320
+ - - ">="
321
+ - !ruby/object:Gem::Version
322
+ version: '0'
323
+ requirements: []
324
+ rubyforge_project:
325
+ rubygems_version: 2.2.2
326
+ signing_key:
327
+ specification_version: 4
328
+ summary: Export any project from a given git repository or a local project directory
329
+ to a single pdf file
330
+ test_files: []
331
+ has_rdoc: