git2epub 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,5 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ .bundle
23
+ *.gemspec
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'http://rubygems.org/'
2
2
 
3
3
  gem 'eeepub'
4
- gem 'mime-types'
4
+ gem 'ptools'
5
+ gem 'haml'
6
+ gem 'tilt'
data/Gemfile.lock CHANGED
@@ -4,11 +4,15 @@ GEM
4
4
  builder (2.1.2)
5
5
  eeepub (0.5.1)
6
6
  builder
7
- mime-types (1.16)
7
+ haml (3.0.18)
8
+ ptools (1.1.9)
9
+ tilt (1.1)
8
10
 
9
11
  PLATFORMS
10
12
  ruby
11
13
 
12
14
  DEPENDENCIES
13
15
  eeepub
14
- mime-types
16
+ haml
17
+ ptools
18
+ tilt
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/lib/git2epub.rb CHANGED
@@ -1,87 +1,53 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.require :default
3
3
 
4
- require 'cgi'
5
- require 'mime/types'
6
4
  require 'tmpdir'
7
5
  require 'fileutils'
8
6
 
9
7
  module Git2Epub
8
+ class << self
9
+ def run(git_url, epub_file = nil)
10
+ dir = git_clone(git_url)
10
11
 
11
- def self.run(git_url, epub_file = nil)
12
- dir = git_clone(git_url)
12
+ epub = EeePub::Easy.new do
13
+ title git_url
14
+ identifier git_url, :scheme => 'URL'
15
+ uid git_url
16
+ end
13
17
 
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
18
+ add_contents(epub, dir, git_url)
20
19
 
21
- add_contents(epub, dir, git_url)
20
+ epub_file = File.basename(git_url) + '.epub' unless epub_file
21
+ puts "\e[32m => #{epub_file}\e[0m"
22
+ epub.save(epub_file)
23
+ end
22
24
 
23
- epub_file = File.basename(git_url) + '.epub' unless epub_file
24
- puts "\e[32m => #{epub_file}\e[0m"
25
- epub.save(epub_file)
26
- end
25
+ def git_clone(git_url)
26
+ dir = File.join(Dir.tmpdir, 'git2epub', File.basename(git_url))
27
+ FileUtils.rm_rf dir
28
+ FileUtils.mkdir_p dir
29
+ system 'git', 'clone', git_url, dir
30
+ dir
31
+ end
27
32
 
28
- def self.git_clone(git_url)
29
- dir = File.join(Dir.tmpdir, 'git2epub', File.basename(git_url))
30
- FileUtils.rm_rf dir
31
- FileUtils.mkdir_p dir
32
- system 'git', 'clone', git_url, dir
33
- dir
34
- end
33
+ def add_contents(epub, dir, git_url)
34
+ contents = Dir[File.join(dir, '**', '*')].select { |f| File.file?(f) && !File.binary?(f) }
35
35
 
36
- def self.add_contents(epub, dir, git_url)
37
- contents = Dir[File.join(dir, '**', '*')].
38
- select { |f| File.file?(f) && MIME::Types.of(f).first.ascii? rescue false }
36
+ epub.sections << ['Index', render('index.haml', :git_url => git_url, :contents => contents, :dir => dir)]
39
37
 
40
- lis = []
41
- contents.each_with_index do |content, index|
42
- label = content.sub(File.join(dir, '/'), '')
43
- lis << "<li><a href='section_#{index + 1}.html'>#{label}</a></li>"
38
+ contents.each do |content|
39
+ label = content.sub(File.join(dir, '/'), '')
40
+ epub.sections << [label, render('section.haml', :label => label, :content => content)]
41
+ puts "\e[35m#{label}\e[0m"
42
+ end
44
43
  end
45
44
 
46
- epub.sections << ['Index', <<-HTML]
47
- <?xml version="1.0" encoding="UTF-8"?>
48
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
49
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
50
- <head>
51
- <title>#{git_url}</title>
52
- </head>
53
- <body>
54
- <h1>#{git_url}</h1>
55
- <ul>
56
- #{lis.join("\n")}
57
- </ul>
58
- </body>
59
- </html>
60
- HTML
61
-
62
- contents.each do |content|
63
- label = content.sub(File.join(dir, '/'), '')
64
-
65
- puts "\e[35m#{label}\e[0m"
45
+ def render(template_name, locals)
46
+ Tilt.new(template(template_name), :escape_html => true).render(self, locals)
47
+ end
66
48
 
67
- epub.sections << [label, <<-HTML]
68
- <?xml version="1.0" encoding="UTF-8"?>
69
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
70
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
71
- <head>
72
- <title>#{label}</title>
73
- <style>
74
- body {font-size: 76%;}
75
- </style>
76
- </head>
77
- <body>
78
- <h1>#{label}</h1>
79
- <pre><code>
80
- #{CGI.escapeHTML(File.read(content))}
81
- </code></pre>
82
- </body>
83
- </html>
84
- HTML
49
+ def template(name)
50
+ File.join(File.dirname(__FILE__), 'templates', name)
85
51
  end
86
52
  end
87
53
  end
@@ -0,0 +1,15 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title= git_url
5
+ %style{:type => 'text/css'}
6
+ :css
7
+ h1 {font-size: 120%; color: #666; margin: 4px 0;}
8
+ ul {font-size: 80%;}
9
+ %body
10
+ %h1= git_url
11
+ %ul
12
+ - contents.each_with_index do |content, index|
13
+ %li
14
+ %a{:href => "section_#{index + 1}.html"}
15
+ = content.sub(File.join(dir, '/'), '')
@@ -0,0 +1,13 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title= label
5
+ %style{:type => 'text/css'}
6
+ :css
7
+ h1 {font-size: 120%; color: #666; margin: 4px 0;}
8
+ pre {font-size: 76%; border: solid 1px #CCC;}
9
+ %body
10
+ %h1= label
11
+ %pre
12
+ %code
13
+ = File.read(content)
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
8
7
  - 2
9
- version: 0.1.2
8
+ - 0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jugyo
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-23 00:00:00 +09:00
17
+ date: 2010-10-24 00:00:00 +09:00
18
18
  default_executable: git2epub
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -78,6 +78,8 @@ files:
78
78
  - VERSION
79
79
  - bin/git2epub
80
80
  - lib/git2epub.rb
81
+ - lib/templates/index.haml
82
+ - lib/templates/section.haml
81
83
  has_rdoc: true
82
84
  homepage: http://github.com/jugyo/git2epub
83
85
  licenses: []