source2epub 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: 2f299d11976795d47690cece2efa4bc4ea9316ff
4
+ data.tar.gz: bb336cc7e6ae40e84932e7858ceeb73cbe46336d
5
+ SHA512:
6
+ metadata.gz: 36bf6a16682d5465af14894c65dff2c8e02213cc215603c094d105b049c2079136b8993e9a13bc34c1e426fca2d73d9424f5569c652f52f641db4177919b991a
7
+ data.tar.gz: 826b9269ca56d14cf32310a9527e80627ae6d36f405b719c7173e6099e3b8ee709f87a7fe1d1ff7f6dcb45adf6ec3508f082fde6d11e5ad8fc1eabe71b07be64
data/.gitignore ADDED
@@ -0,0 +1,20 @@
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
20
+ .epub
data/.rubocop.yml ADDED
@@ -0,0 +1,78 @@
1
+ AllCops:
2
+ Include:
3
+ - Gemfile
4
+ - Rakefile
5
+ - bin/*
6
+ - source2epub.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,3 @@
1
+ #### 0.2.0
2
+
3
+ - Initial public release
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,170 @@
1
+ ## source2epub
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/source2epub.svg)][gem]
4
+ [![Dependency Status](https://gemnasium.com/agilecreativity/source2epub.png)][gemnasium]
5
+ [![Code Climate](https://codeclimate.com/github/agilecreativity/source2epub.png)][codeclimate]
6
+
7
+ [gem]: http://badge.fury.io/rb/source2epub
8
+ [gemnasium]: https://gemnasium.com/agilecreativity/source2epub
9
+ [codeclimate]: https://codeclimate.com/github/agilecreativity/source2epub
10
+
11
+ - Export/print content of any git repositores (or local project directory) to single epub file for quick review offline.
12
+
13
+ - Work with [Github][] or [BitBucket][] project or your own git servers
14
+
15
+ - Thanks to the power of [eeepub gem][] and `:TOhtml` feature of [Vim][].
16
+
17
+ - Support by your favourite reading devices that support 'epub' format (computer, phone, tablet, etc) that
18
+
19
+ - Support unlimited color scheme as it is based on output from [Vim][] editor
20
+
21
+ - Here is the [sample epub file](/samples/source2epub_default_colorscheme.epub) of [source2epub][] produced by `source2epub`
22
+
23
+ ### Related projects
24
+
25
+ - [source2pdf][] generate the output of the git or local project to a pdf file
26
+ - [code_rippa][] gererate pdf file with the help of LaTeX
27
+
28
+ ### Requirements
29
+
30
+ - Valid installation of [Vim][] required by [vim_printer][] gem
31
+
32
+ ### Installation
33
+
34
+ ```
35
+ gem install source2epub
36
+ ```
37
+
38
+ ### Synopsis/Usage
39
+
40
+ ```
41
+
42
+ Usage:
43
+
44
+ $source2epub -e, --exts=EXT1 EXT2 EXT3 -u, --url=URL -theme=theme_name
45
+
46
+ Example:
47
+
48
+ # Export the *.rb from the given repository
49
+
50
+ $source2epub -u https://github.com/agilecreativity/source2epub.git -e rb
51
+
52
+ # Export the *.rb and also 'Gemfile' from a local directory 'source2epub'
53
+ # Note: must be one directory directly above the current directory
54
+
55
+ $source2epub -u source2epub -e rb -f Gemfile
56
+
57
+ # Export the *.rb and also 'Gemfile' from a given directory 'source2epub'
58
+ # using 'solarized' theme
59
+ # Note: 'source2epub' must be exactly one level above current directory
60
+
61
+ $source2epub -u source2epub -e rb -f Gemfile -t solarized
62
+
63
+ Options:
64
+
65
+ -u, --url=URL # The full url of the github project to be cloned or local directory name (mandatory)
66
+ # e.g. -u https://github.com/agilecreativity/source2epub
67
+ # Or if used with the project already exist locally
68
+ # -u source2epub
69
+
70
+ -e, --exts=EXT1 EXT2 EXT3 .. # The list of extension names to be exported (mandatory)
71
+ # e.g. -e md rb
72
+
73
+ -f, [--non-exts=one two three] # The list of file without extension to be exported (optional)
74
+ # e.g. -f Gemfile LICENSE
75
+
76
+ -t, [--theme=theme_name] # The theme to be used with vim_printer see :help :colorscheme from inside Vim
77
+ # default: 'default'
78
+ # e.g. -t solarized
79
+
80
+ -p, [--epub-title=title] # The title of the epub output, if not specified the project_name will be used
81
+ # e.g. -p 'My Cool Project'
82
+ #
83
+ -s, [--command] # Use the input file list from the result of the given shell command
84
+ # Note: the command must return the list of file to be valid
85
+ # e.g. --command 'find . -type f -iname "*.rb" | grep -v test | grep -v _spec'
86
+
87
+ Export a given github URL or local project directory to an epub file"
88
+
89
+ ```
90
+
91
+ ### Sample Usage:
92
+
93
+ ```shell
94
+ source2epub -u https://github.com/agilecreativity/source2epub.git -e rb
95
+ ```
96
+
97
+ Should result in something similar to this in the console
98
+
99
+ ```
100
+ FYI: list of extensions: ["gem", "gemspec", "lock", "md", "rb"]
101
+ FYI: list of all files : ["./config/initializers/source2epub.rb", "./lib/source2epub.rb", "./lib/source2epub/cli.rb", "./lib/source2epub/configuration.rb", "./lib/source2epub/exporter.rb", "./lib/source2epub/logger.rb", "./lib/source2epub/source2epub.rb", "./lib/source2epub/version.rb", "./test/lib/source2epub/test_source2epub.rb", "./test/test_helper.rb"]
102
+ FYI: process file 1 of 10 : ./config/initializers/source2epub.rb
103
+ FYI: process file 2 of 10 : ./lib/source2epub.rb
104
+ FYI: process file 3 of 10 : ./lib/source2epub/cli.rb
105
+ FYI: process file 4 of 10 : ./lib/source2epub/configuration.rb
106
+ FYI: process file 5 of 10 : ./lib/source2epub/exporter.rb
107
+ FYI: process file 6 of 10 : ./lib/source2epub/logger.rb
108
+ FYI: process file 7 of 10 : ./lib/source2epub/source2epub.rb
109
+ FYI: process file 8 of 10 : ./lib/source2epub/version.rb
110
+ FYI: process file 9 of 10 : ./test/lib/source2epub/test_source2epub.rb
111
+ FYI: process file 10 of 10 : ./test/test_helper.rb
112
+ Your output file is './source2epub/vim_printer_source2epub.tar.gz'
113
+ Your final output is ./source2epub.epub
114
+ ```
115
+
116
+ ### Sample Output
117
+
118
+ #### Using the 'default' theme/colorscheme for Vim
119
+
120
+ ```shell
121
+ source2epub -u https://github.com/agilecreativity/code2epub.git --exts rb
122
+ ```
123
+
124
+ Which generated the following [epub output file](/samples/source2epub_default_colorscheme.epub)
125
+
126
+ The example screenshot:
127
+
128
+ ![](/samples/source2epub_default_colorscheme.png)
129
+
130
+ #### Use non-default colorscheme/theme for Vim
131
+
132
+ Use my personal favourite [seoul256][] colorscheme
133
+
134
+ ```shell
135
+ source2epub -u https://github.com/agilecreativity/source2epub.git --exts rb --theme seoul256
136
+ ```
137
+
138
+ Which generated the following [pdf output file](/samples/source2epub_seoul256_colorscheme.epub)
139
+
140
+ The example screenshot:
141
+
142
+ ![](/samples/source2epub_seoul256_colorscheme.png)
143
+
144
+ ### Contributing
145
+
146
+ 1. Fork it
147
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
148
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
149
+ 4. Push to the branch (`git push origin my-new-feature`)
150
+ 5. Create new Pull Request
151
+
152
+ [thor]: https://github.com/erikhuda/thor
153
+ [minitest]: https://github.com/seattlerb/minitest
154
+ [yard]: https://github.com/lsegal/yard
155
+ [pry]: https://github.com/pry/pry
156
+ [rubocop]: https://github.com/bbatsov/rubocop
157
+ [grit]: https://github.com/mojombo/grit
158
+ [Ghostscript]: http://todo.com/
159
+ [Wkhtmltopdf]: http://todo.com/
160
+ [Vim]: http://www.vim.org
161
+ [vim_printer]: https://github.com/agilecreativity/vim_printer
162
+ [pdfs2pdf]: https://github.com/agilecreativity/pdfs2pdf
163
+ [html2pdf]: https://github.com/agilecreativity/html2pdf
164
+ [monokai]: https://github.com/lsdr/monokai
165
+ [seoul256]: https://github.com/junegunn/seoul256.vim
166
+ [Github]: http://www.github.com
167
+ [BitBucket]: http://www.bitbucket.org
168
+ [source2pdf]: https://github.com/agilecreativity/source2pdf
169
+ [source2epub]: https://github.com/agilecreativity/source2epub
170
+ [code_rippa]: https://github.com/benjamintanweihao/code_rippa
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ project_name = "source2epub"
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/source2epub"
16
+ include Source2Epub
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/source2epub ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/source2epub"
3
+ require_relative "../config/initializers/source2epub"
4
+ include Source2Epub
5
+ if ARGV.empty?
6
+ Source2Epub::CLI.start(%w[usage])
7
+ else
8
+ Source2Epub::CLI.start(%w[export].concat(ARGV))
9
+ end
@@ -0,0 +1,13 @@
1
+ module Source2Epub
2
+ class << self
3
+ # ./lib/source2epub/configuration.rb
4
+ def update_config
5
+ Source2Epub.configure do |config|
6
+ config.creator = "Burin C"
7
+ config.publisher = "Burin C"
8
+ config.published_date = "2014-06-23" # TODO: get the current date
9
+ config.identifier = "https://agilecreativity.com/"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "source2epub/version"
2
+ require_relative "source2epub/logger"
3
+ require_relative "source2epub/source2epub"
4
+ require_relative "source2epub/exporter"
5
+ require_relative "source2epub/cli"
6
+ include Source2Epub
@@ -0,0 +1,97 @@
1
+ require "thor"
2
+ require "vim_printer"
3
+ require_relative "source2epub"
4
+
5
+ module Source2Epub
6
+ class CLI < Thor
7
+ desc "export", "Export a given github URL or local project directory to an epub file"
8
+ method_option "url",
9
+ aliases: "-u",
10
+ desc: "The full url of the github project to be cloned or a directory name (mandtory)",
11
+ required: true
12
+ method_option "exts",
13
+ type: :array,
14
+ aliases: "-e",
15
+ desc: "The list of file extension to be exported",
16
+ default: []
17
+ method_option "non_exts",
18
+ type: :array,
19
+ aliases: "-f",
20
+ desc: "The list of file without extension to be exported",
21
+ default: []
22
+ method_option "theme",
23
+ aliases: "-t",
24
+ desc: "The theme to be used with vim_printer",
25
+ default: "default"
26
+ method_option "command",
27
+ aliases: "-s",
28
+ desc: "Use input file list from the result of the given shell command"
29
+ method_option "epub_title",
30
+ aliases: "-p",
31
+ desc: "Title to be used for output epub (default to project_name)"
32
+ def export
33
+ exporter = Source2Epub::Exporter.new options[:url],
34
+ exts: options[:exts],
35
+ non_exts: options[:non_exts],
36
+ theme: options[:theme],
37
+ command: options[:command],
38
+ epub_title: options[:epub_title]
39
+ exporter.export
40
+ end
41
+
42
+ desc "usage", "Display help screen"
43
+ def usage
44
+ puts <<-EOS
45
+ Usage:
46
+
47
+ $source2epub -u, --url=URL -e, --exts=EXT1 EXT2 EXT3 -t, -theme=theme_name
48
+
49
+ Example:
50
+
51
+ # Export the *.rb from the given repository
52
+
53
+ $source2epub -u https://github.com/agilecreativity/source2epub.git -e rb
54
+
55
+ # Export the *.rb and also 'Gemfile' from a local directory 'source2epub'
56
+ # Note: must be one directory directly above the current directory
57
+
58
+ $source2epub -u source2epub -e rb -f Gemfile
59
+
60
+ # Export the *.rb and also 'Gemfile' from a given directory 'source2epub'
61
+ # using 'solarized' theme
62
+ # Note: 'source2epub' must be exactly one level above current directory
63
+
64
+ $source2epub -u source2epub -e rb -f Gemfile -t solarized
65
+
66
+ Options:
67
+
68
+ -u, --url=URL # The full url of the github project to be cloned or local directory name (mandatory)
69
+ # e.g. -u https://github.com/agilecreativity/source2epub
70
+ # Or if used with the project already exist locally
71
+ # -u source2epub
72
+
73
+ -e, --exts=EXT1 EXT2 EXT3 .. # The list of extension names to be exported (mandatory)
74
+ # e.g. -e md rb
75
+
76
+ -f, [--non-exts=one two three] # The list of file without extension to be exported (optional)
77
+ # e.g. -f Gemfile LICENSE
78
+
79
+ -t, [--theme=theme_name] # The theme to be used with vim_printer see :help :colorscheme from inside Vim
80
+ # default: 'default'
81
+ # e.g. -t solarized
82
+
83
+ -p, [--epub-title=title] # The title of the epub output, if not specified the project_name will be used
84
+ # e.g. -p 'My Cool Project'
85
+ #
86
+ -s, [--command] # Use the input file list from the result of the given shell command
87
+ # Note: the command must return the list of file to be valid
88
+ # e.g. --command 'find . -type f -iname "*.rb" | grep -v test | grep -v _spec'
89
+
90
+ Export a given git URL or local project directory to an epub file"
91
+
92
+ EOS
93
+ end
94
+
95
+ default_task :usage
96
+ end
97
+ end
@@ -0,0 +1,33 @@
1
+ module Source2Epub
2
+ class Configuration
3
+ attr_accessor :creator,
4
+ :publisher,
5
+ :published_date,
6
+ :identifier,
7
+ def initialize
8
+ @creator = "https://github.com/agilecreativity/source2epub"
9
+ @publisher = "http://agilecreativity.com"
10
+ @published_date = Time.now.strftime("%Y-%m-%d %H:%M:%S")
11
+ @identifier = "https://agilecreativity.com/"
12
+ end
13
+ end
14
+
15
+ class << self
16
+ attr_accessor :configuration
17
+
18
+ # Configure Source2Epub someplace sensible, like
19
+ #
20
+ # 'config/initializers/source2epub.rb'
21
+ #
22
+ # Source2Epub.configure do |config|
23
+ # config.creator = ".."
24
+ # end
25
+ def configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def configure
30
+ yield(configuration)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env ruby
2
+ require "uri"
3
+ require "agile_utils"
4
+ require "eeepub"
5
+ require_relative "../source2epub"
6
+ module Source2Epub
7
+ TMP_DIR = "source2epub_tmp"
8
+ class Exporter
9
+ attr_reader :url,
10
+ :exts,
11
+ :non_exts,
12
+ :theme,
13
+ :command,
14
+ :epub_title
15
+ attr_reader :base_dir,
16
+ :repo_name,
17
+ :output_path
18
+
19
+ # Constructor for Executor
20
+ #
21
+ # @param [String] url the input URL like
22
+ # https://github.com/opal/opal.git or just the immediat folder name
23
+ # @param [Hash<Symbol,Object>] opts the option hash
24
+ #
25
+ # @option opts [Array<String>] :exts the list of file extension to be used
26
+ # @option opts [Array<String>] :non_exts the list of file without extension to be used
27
+ # @option opts [String] :theme the theme to use for `vim_printer`
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
+ @command = opts[:command]
35
+ @repo_name = project_name(url)
36
+ @epub_title = opts[:epub_title] || @repo_name
37
+ @output_path = File.expand_path([base_dir, repo_name].join(File::SEPARATOR))
38
+ end
39
+
40
+ # Print and export the source from a given URL to an epub file
41
+ def export
42
+ clone
43
+ puts "FYI: list of extensions: #{all_extensions}"
44
+ # Note: if we are using the '--command', it will be empty list by default
45
+ puts "FYI: list of all files : #{all_files}" unless all_files.empty?
46
+ files2htmls
47
+ htmls2epub
48
+ copy_output
49
+ cleanup
50
+ end
51
+
52
+ private
53
+
54
+ def clone
55
+ if File.exist?(output_path)
56
+ puts "The project #{output_path} already exist, no git clone needed!"
57
+ return
58
+ end
59
+ Source2Epub.clone_repository(url, repo_name, base_dir)
60
+ end
61
+
62
+ # List all extensions
63
+ def all_extensions
64
+ all_exts = Source2Epub.list_extensions(output_path)
65
+ # Strip off the '.' in the output if any.
66
+ all_exts.map! { |e| e.gsub(/^\./, "") }
67
+ all_exts
68
+ end
69
+
70
+ # List all files base on simple criteria
71
+ def all_files
72
+ files = []
73
+ if input_available?
74
+ files = Source2Epub.list_files base_dir: output_path,
75
+ exts: exts,
76
+ non_exts: non_exts,
77
+ recursive: true
78
+ end
79
+ files
80
+ end
81
+
82
+ # Convert files to htmls
83
+ def files2htmls
84
+ if command
85
+ Source2Epub.files_to_htmls base_dir: output_path,
86
+ theme: theme,
87
+ command: command
88
+ elsif input_available?
89
+ Source2Epub.files_to_htmls base_dir: output_path,
90
+ exts: exts,
91
+ non_exts: non_exts,
92
+ theme: theme
93
+ end
94
+ end
95
+
96
+ # Convert list of html to list of epub file
97
+ def htmls2epub
98
+ input_file = File.expand_path("#{output_path}/vim_printer_#{repo_name}.tar.gz")
99
+
100
+ if File.exist?(input_file)
101
+ FileUtils.mkdir_p output_dir
102
+ AgileUtils::FileUtil.gunzip input_file, output_dir
103
+ xhtml_files = CodeLister.files base_dir: output_dir,
104
+ recursive: true,
105
+ exts: %w[xhtml],
106
+ non_exts: []
107
+ project_dir = File.expand_path(File.dirname(output_dir) + "../../#{Source2Epub::TMP_DIR}/#{repo_name}")
108
+
109
+ xhtml_files.map! do |f|
110
+ File.expand_path(f.gsub(/^\./, project_dir))
111
+ end
112
+
113
+ nav_list = nav_index(xhtml_files, project_dir)
114
+ # Note: need to assign the local varaiable for this to work
115
+ title = epub_title
116
+ epub = EeePub.make do
117
+ title title
118
+ creator Source2Epub.configuration.creator
119
+ publisher Source2Epub.configuration.publisher
120
+ date Source2Epub.configuration.published_date
121
+ identifier Source2Epub.configuration.identifier, scheme: "URL"
122
+ files(xhtml_files)
123
+ nav nav_list
124
+ end
125
+ epub.save(output_filename)
126
+ end
127
+ end
128
+
129
+ # Create the navigation list from list of file
130
+ #
131
+ # @param [Array<String>] files list of input file
132
+ # @param [String] prefix_dir the prefix directory
133
+ # @return [List<Hash<Symbol, String>>] list of navigation content hash
134
+ def nav_index(files = [], prefix_dir)
135
+ nav_list = []
136
+ padding = files.size.to_s.length
137
+ files.each_with_index do |file, index|
138
+ # still we have "somfile.ext.xhtml" at this point
139
+ formatted_name = file.gsub("#{prefix_dir}/", "")
140
+ nav_list << {
141
+ label: format("%0#{padding}d : %s", index + 1, File.basename(formatted_name, ".*")),
142
+ content: File.basename(file)
143
+ }
144
+ end
145
+ nav_list
146
+ end
147
+
148
+ def output_dir
149
+ File.expand_path("#{base_dir}/#{Source2Epub::TMP_DIR}/#{repo_name}")
150
+ end
151
+
152
+ def output_filename
153
+ File.expand_path([File.dirname(output_dir), "#{repo_name}.epub"].join(File::SEPARATOR))
154
+ end
155
+
156
+ def input_available?
157
+ (exts && !exts.empty?) || (non_exts && !non_exts.empty?)
158
+ end
159
+
160
+ # Extract project name from a given URL
161
+ #
162
+ # @param [String] uri input uri
163
+ # e.g.
164
+ # project_name('https://github.com/erikhuda/thor.git') #=> 'thor'
165
+ # project_name('https://github.com/erikhuda/thor') #=> 'thor'
166
+ def project_name(uri)
167
+ if uri
168
+ name = URI(uri).path.split(File::SEPARATOR).last
169
+ # strip the '.' if any
170
+ File.basename(name, ".*") if name
171
+ end
172
+ end
173
+
174
+ def copy_output
175
+ if File.exist?(output_filename)
176
+ destination_file = File.expand_path(File.dirname(output_dir) + "../../#{repo_name}.epub")
177
+ FileUtils.mv output_filename, destination_file
178
+ puts "Your final output is #{File.expand_path(destination_file)}"
179
+ end
180
+ end
181
+
182
+ def cleanup
183
+ FileUtils.rm_rf File.expand_path(File.dirname(output_dir) + "../../#{Source2Epub::TMP_DIR}")
184
+ # Also remove the 'vim_printer_#{repo_name}.tar.gz' if we have one
185
+ FileUtils.rm_rf File.expand_path(File.dirname(output_dir) + "../../#{repo_name}/vim_printer_#{repo_name}.tar.gz")
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,10 @@
1
+ require "logger"
2
+ module Source2Epub
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,73 @@
1
+ require "git"
2
+ require "code_lister"
3
+ require_relative "./configuration"
4
+ module Source2Epub
5
+ CustomError = Class.new(StandardError)
6
+ class << self
7
+ # Clone the given repository from github
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
+ unless File.exist?(base_dir) && File.directory?(base_dir)
31
+ fail "Starting directory must be valid, and exist"
32
+ end
33
+
34
+ exts = opts[:exts] || []
35
+ non_exts = opts[:non_exts] || []
36
+ theme = opts.fetch(:theme, "default")
37
+ command = opts[:command]
38
+
39
+ if command
40
+ args = [
41
+ "print",
42
+ "--base-dir",
43
+ base_dir,
44
+ "--command",
45
+ command,
46
+ "--theme",
47
+ theme
48
+ ]
49
+ else
50
+ args = [
51
+ "print",
52
+ "--base-dir",
53
+ base_dir,
54
+ "--exts",
55
+ exts,
56
+ "--theme",
57
+ theme,
58
+ "--recursive"
59
+ ]
60
+ args.concat(["--non-exts"]).concat(non_exts) unless non_exts.empty?
61
+ end
62
+ # puts "FYI: input options for vim_printer #{args}"
63
+ VimPrinter::CLI.start(args)
64
+ end
65
+
66
+ private
67
+
68
+ # Always expand the directory name so that '~' or '.' is expanded correctly
69
+ def base_dir(dir_name)
70
+ File.expand_path(dir_name)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module Source2Epub
2
+ VERSION = "0.2.0"
3
+ end
@@ -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 "source2epub/version"
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "source2epub"
7
+ spec.version = Source2Epub::VERSION
8
+ spec.authors = ["Burin Choomnuan"]
9
+ spec.email = ["agilecreativity@gmail.com"]
10
+ spec.summary = %q(Export any project from git repository or local directory to a single epub file)
11
+ spec.description = %q{Export any project from git repository or local directory to a single epub file.
12
+ Combine useful features of the following ruby gems
13
+ (vim_printer, eeepub and others)
14
+ to produce a single epub file that can be view by any device where epub is supported.
15
+ }
16
+ spec.homepage = "https://github.com/agilecreativity/source2epub"
17
+ spec.license = "MIT"
18
+ spec.files = Dir.glob("{bin,lib,config}/**/*") + %w[Gemfile
19
+ Rakefile
20
+ source2epub.gemspec
21
+ README.md
22
+ CHANGELOG.md
23
+ LICENSE
24
+ .rubocop.yml
25
+ .gitignore]
26
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
28
+ spec.require_paths = ["lib"]
29
+ spec.add_runtime_dependency "thor", "~> 0.19.1"
30
+ spec.add_runtime_dependency "git", "~> 1.2.7"
31
+ spec.add_runtime_dependency "awesome_print", "~> 1.2.0"
32
+ spec.add_runtime_dependency "agile_utils", "~> 0.2.0"
33
+ spec.add_runtime_dependency "code_lister", "~> 0.2.0"
34
+ spec.add_runtime_dependency "vim_printer", "~> 0.2.0"
35
+ spec.add_runtime_dependency "eeepub", "~> 0.8.1"
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.0"
40
+ spec.add_development_dependency "minitest", "~> 5.3.5"
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-byebug", "~> 1.3.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,320 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: source2epub
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-31 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: awesome_print
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.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: 1.2.0
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.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: code_lister
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: vim_printer
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: eeepub
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.8.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.8.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.6.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.6.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: gem-ctags
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 1.0.6
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.0.6
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 2.6.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 2.6.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: guard-minitest
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.3.0
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.3.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: minitest
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 5.3.5
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 5.3.5
181
+ - !ruby/object:Gem::Dependency
182
+ name: minitest-spec-context
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.0.3
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.0.3
195
+ - !ruby/object:Gem::Dependency
196
+ name: pry
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 0.10.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 0.10.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: pry-byebug
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 1.3.3
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 1.3.3
223
+ - !ruby/object:Gem::Dependency
224
+ name: rake
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 10.3.2
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 10.3.2
237
+ - !ruby/object:Gem::Dependency
238
+ name: rubocop
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: 0.24.1
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: 0.24.1
251
+ - !ruby/object:Gem::Dependency
252
+ name: yard
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: 0.8.7
258
+ type: :development
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - "~>"
263
+ - !ruby/object:Gem::Version
264
+ version: 0.8.7
265
+ description: "Export any project from git repository or local directory to a single
266
+ epub file.\n Combine useful features of the following ruby
267
+ gems\n (vim_printer, eeepub and others)\n to
268
+ produce a single epub file that can be view by any device where epub is supported.\n
269
+ \ "
270
+ email:
271
+ - agilecreativity@gmail.com
272
+ executables:
273
+ - source2epub
274
+ extensions: []
275
+ extra_rdoc_files: []
276
+ files:
277
+ - ".gitignore"
278
+ - ".rubocop.yml"
279
+ - CHANGELOG.md
280
+ - Gemfile
281
+ - LICENSE
282
+ - README.md
283
+ - Rakefile
284
+ - bin/source2epub
285
+ - config/initializers/source2epub.rb
286
+ - lib/source2epub.rb
287
+ - lib/source2epub/cli.rb
288
+ - lib/source2epub/configuration.rb
289
+ - lib/source2epub/exporter.rb
290
+ - lib/source2epub/logger.rb
291
+ - lib/source2epub/source2epub.rb
292
+ - lib/source2epub/version.rb
293
+ - source2epub.gemspec
294
+ homepage: https://github.com/agilecreativity/source2epub
295
+ licenses:
296
+ - MIT
297
+ metadata: {}
298
+ post_install_message:
299
+ rdoc_options: []
300
+ require_paths:
301
+ - lib
302
+ required_ruby_version: !ruby/object:Gem::Requirement
303
+ requirements:
304
+ - - ">="
305
+ - !ruby/object:Gem::Version
306
+ version: '0'
307
+ required_rubygems_version: !ruby/object:Gem::Requirement
308
+ requirements:
309
+ - - ">="
310
+ - !ruby/object:Gem::Version
311
+ version: '0'
312
+ requirements: []
313
+ rubyforge_project:
314
+ rubygems_version: 2.2.2
315
+ signing_key:
316
+ specification_version: 4
317
+ summary: Export any project from git repository or local directory to a single epub
318
+ file
319
+ test_files: []
320
+ has_rdoc: