git2epub 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org/'
2
+
3
+ gem 'eeepub'
4
+ gem 'mime-types'
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ builder (2.1.2)
5
+ eeepub (0.5.1)
6
+ builder
7
+ mime-types (1.16)
8
+
9
+ PLATFORMS
10
+ ruby
11
+
12
+ DEPENDENCIES
13
+ eeepub
14
+ mime-types
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 jugyo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = git2epub
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 jugyo. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "git2epub"
8
+ gem.summary = %Q{git2epub}
9
+ gem.description = %Q{The tool that generate epub from git repository}
10
+ gem.email = "jugyo.org@gmail.com"
11
+ gem.homepage = "http://github.com/jugyo/git2epub"
12
+ gem.authors = ["jugyo"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "eeepub"
15
+ gem.add_dependency "mime-types"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "git2epub #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
data/bin/git2epub ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ unless ARGV.size >= 1
3
+ puts "Usage: #{File.basename($0)} GIT_URL [EPUB_FILE]"
4
+ exit!
5
+ end
6
+
7
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
8
+ require 'git2epub'
9
+ Git2Epub.run(ARGV[0], ARGV[1])
data/lib/git2epub.rb ADDED
@@ -0,0 +1,89 @@
1
+ require 'bundler/setup'
2
+ Bundler.require :default
3
+
4
+ require 'cgi'
5
+ require 'mime/types'
6
+ require 'tmpdir'
7
+ require 'fileutils'
8
+
9
+ module Git2Epub
10
+
11
+ def self.run(git_url, epub_file = nil)
12
+ dir = git_clone(git_url)
13
+
14
+ epub = EeePub::Easy.new do
15
+ title git_url
16
+ creator `whoami`
17
+ identifier git_url, :scheme => 'URL'
18
+ uid git_url
19
+ end
20
+
21
+ add_contents(epub, dir, git_url)
22
+
23
+ unless epub_file
24
+ epub_file = git_url.match(/:(.*)/)[1].gsub('/', '-') + '.epub'
25
+ end
26
+ puts "\e[32m => #{epub_file}\e[0m"
27
+ epub.save(epub_file)
28
+ end
29
+
30
+ def self.git_clone(git_url)
31
+ dir = File.join(Dir.tmpdir, 'git2epub', File.basename(git_url))
32
+ FileUtils.rm_rf dir
33
+ FileUtils.mkdir_p dir
34
+ system 'git', 'clone', git_url, dir
35
+ dir
36
+ end
37
+
38
+ def self.add_contents(epub, dir, git_url)
39
+ contents = Dir[File.join(dir, '**', '*')].
40
+ select { |f| File.file?(f) && MIME::Types.of(f).first.ascii? rescue false }
41
+
42
+ lis = []
43
+ contents.each_with_index do |content, index|
44
+ label = content.sub(File.join(dir, '/'), '')
45
+ lis << "<li><a href='section_#{index + 1}.html'>#{label}</a></li>"
46
+ end
47
+
48
+ epub.sections << ['Index', <<-HTML]
49
+ <?xml version="1.0" encoding="UTF-8"?>
50
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
51
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
52
+ <head>
53
+ <title>#{git_url}</title>
54
+ </head>
55
+ <body>
56
+ <h1>#{git_url}</h1>
57
+ <ul>
58
+ #{lis.join("\n")}
59
+ </ul>
60
+ </body>
61
+ </html>
62
+ HTML
63
+
64
+ contents.each do |content|
65
+ label = content.sub(File.join(dir, '/'), '')
66
+
67
+ puts "\e[35m#{label}\e[0m"
68
+
69
+ epub.sections << [label, <<-HTML]
70
+ <?xml version="1.0" encoding="UTF-8"?>
71
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
72
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
73
+ <head>
74
+ <title>#{label}</title>
75
+ <style>
76
+ body {font-size: 76%;}
77
+ </style>
78
+ </head>
79
+ <body>
80
+ <h1>#{label}</h1>
81
+ <pre><code>
82
+ #{CGI.escapeHTML(File.read(content))}
83
+ </code></pre>
84
+ </body>
85
+ </html>
86
+ HTML
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git2epub
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 1
9
+ version: 0.1.1
10
+ platform: ruby
11
+ authors:
12
+ - jugyo
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-23 00:00:00 +09:00
18
+ default_executable: git2epub
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: eeepub
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: mime-types
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ type: :runtime
60
+ version_requirements: *id003
61
+ description: The tool that generate epub from git repository
62
+ email: jugyo.org@gmail.com
63
+ executables:
64
+ - git2epub
65
+ extensions: []
66
+
67
+ extra_rdoc_files:
68
+ - LICENSE
69
+ - README.rdoc
70
+ files:
71
+ - .document
72
+ - .gitignore
73
+ - Gemfile
74
+ - Gemfile.lock
75
+ - LICENSE
76
+ - README.rdoc
77
+ - Rakefile
78
+ - VERSION
79
+ - bin/git2epub
80
+ - lib/git2epub.rb
81
+ has_rdoc: true
82
+ homepage: http://github.com/jugyo/git2epub
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options:
87
+ - --charset=UTF-8
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project:
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: git2epub
113
+ test_files: []
114
+