sc2epub 0.0.1 → 0.0.2

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.
data/CHANGES ADDED
@@ -0,0 +1,5 @@
1
+ = 0.0.2
2
+ use Makefile. add cover.jpg
3
+
4
+ = 0.0.1
5
+ create
data/README ADDED
@@ -0,0 +1,15 @@
1
+ = sc2epub
2
+ convert sourcecode to epub
3
+
4
+ == install
5
+ $ gem install sc2epub
6
+
7
+ == usage
8
+ $ sc2epub some_directory output_directory project_name
9
+ $ cd output_directory
10
+ $ make
11
+ $ make kindle # if you need mobi file
12
+
13
+ == notice
14
+ sc2epub generate xhtml, xml, and Makefile. You need make for compilation of epub.
15
+ And if you want to generate mobi file, you need kindlegen command.
data/bin/sc2epub CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'kconv'
4
4
  require 'optparse'
5
+ require 'fileutils'
5
6
  TEMPLATE = <<EOS
6
7
  <?xml version="1.0" encoding="UTF-8"?>
7
8
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -29,6 +30,7 @@ TEMPLATE_OPF = <<EOS
29
30
  <?xml version="1.0" encoding="utf-8"?>
30
31
  <package unique-identifier="uid">
31
32
  <metadata>
33
+ <meta name="cover" content="cover" />
32
34
  <dc-metadata xmlns:dc="http://purl.org/metadata/dublin_core"
33
35
  xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
34
36
  <dc:Title>%(title)</dc:Title>
@@ -44,8 +46,9 @@ TEMPLATE_OPF = <<EOS
44
46
  </metadata>
45
47
  <manifest>
46
48
  <item id="index" media-type-"text/x-oeb1-document" href="index.html"></item>
47
- %(items)
49
+ %(items)
48
50
  <item id="toc" media-type="application/x-dtbncx+xml" href="toc.ncx"></item>
51
+ <item id="cover" href="cover.jpg" media-type="image/jpeg" />
49
52
  </manifest>
50
53
  <spine toc="toc">
51
54
  <itemref idref="index" />
@@ -75,7 +78,30 @@ TEMPLATE_NAVITEM = <<EOS
75
78
  <navLabel><text>%(title)</text></navLabel><content src="%(link)"/>
76
79
  </navPoint>
77
80
  EOS
81
+ TEMPLATE_MAKEFILE = <<EOS
82
+ PROJECT = %(title)
83
+ EPUB = $(PROJECT).epub
84
+ MOBI = $(PROJECT).mobi
85
+ KINDLEGEN = kindlegen
78
86
 
87
+ .PHONY: all
88
+ all: $(EPUB)
89
+
90
+ .PHONY: kindle
91
+ kindle: $(MOBI)
92
+
93
+ .PHONY: clean
94
+ clean:
95
+ \tfind ./ -name "*.epub" -exec rm {} \\;
96
+ \tfind ./ -name "*.mobi" -exec rm {} \\;
97
+
98
+ $(EPUB):
99
+ \tzip -Xr9D $(EPUB) mimetype META-INF toc.ncx $(PROJECT).opf
100
+ \tfind ./ -name "*.html" -o -name "*.jpg" | xargs zip -Xr9D $(EPUB)
101
+
102
+ $(MOBI): $(EPUB)
103
+ \t$(KINDLEGEN) $(EPUB)
104
+ EOS
79
105
  $env = {}
80
106
  def local path
81
107
  if path.index($root)==0
@@ -90,14 +116,14 @@ def title path
90
116
  path.gsub(/\//, "_").gsub(/\./, '_')
91
117
  end
92
118
  def dogenerate output, doctitle
93
- contents = ['index.html', 'toc.ncx']
94
119
  indexhtml = ''
95
120
  items = ''; c=0;
96
121
  nvitems = ''
122
+ cover = File::join(File::dirname(__FILE__), '../lib/cover.jpg')
123
+ FileUtils::cp(cover, output)
97
124
  $indexes.each do |data|
98
125
  title = data[:name]
99
126
  link = data[:src]
100
- contents << link
101
127
  if data[:type]==:dir && data[:level]+2<=4
102
128
  tagname = "h" + (data[:level]+2).to_s
103
129
  else
@@ -137,17 +163,9 @@ EOS
137
163
  open(File::join(output, 'mimetype'), 'w') do |io|
138
164
  io.puts('application/epub+zip')
139
165
  end
140
-
141
- epub = "#{doctitle}.epub"
142
- dir = Dir::pwd
143
- begin
144
- Dir::chdir(output)
145
- `zip -Xr9D #{epub} mimetype META-INF #{opfpath}`
146
- contents.each do |c|
147
- `zip -Xr9D #{epub} #{c} -x mimetype`
148
- end
149
- ensure
150
- Dir::chdir(dir)
166
+ makefile = dotemplate(TEMPLATE_MAKEFILE, 'title'=>doctitle)
167
+ open(File::join(output, 'Makefile'), 'w') do |io|
168
+ io.write(makefile)
151
169
  end
152
170
  end
153
171
  def dotemplate template, params
data/lib/cover.jpg ADDED
Binary file
data/lib/sc2epub.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sc2epub
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/sc2epub.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  require 'rubygems'
2
-
2
+ require 'lib/sc2epub'
3
3
  GEMSPEC = Gem::Specification::new do |s|
4
4
  s.name = 'sc2epub'
5
- s.version = '0.0.1'
5
+ s.version = Sc2epub::VERSION
6
6
  s.author = 'takada-at'
7
- s.email = 'takada-at@klab.jp'
7
+ s.email = 'nightly@at-akada.org'
8
8
  s.date = '2010-11-21'
9
9
  s.summary = 'sourcecode to epub'
10
10
  s.platform = Gem::Platform::RUBY
@@ -12,7 +12,7 @@ GEMSPEC = Gem::Specification::new do |s|
12
12
  s.executables = ['sc2epub']
13
13
  s.default_executable = 'sc2epub'
14
14
 
15
- s.files = Dir::glob("{lib,bin}/**/*") + ['sc2epub.gemspec']
15
+ s.files = Dir::glob("{lib,bin}/**/*") + ['sc2epub.gemspec', 'README', 'CHANGES']
16
16
  s.has_rdoc = false
17
17
  s.homepage = 'https://github.com/takada-at/sc2epub'
18
18
  s.rubyforge_project = 'sc2epub'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - takada-at
@@ -21,7 +21,7 @@ dependencies: []
21
21
  description: |
22
22
  convert sourcecode to epub
23
23
 
24
- email: takada-at@klab.jp
24
+ email: nightly@at-akada.org
25
25
  executables:
26
26
  - sc2epub
27
27
  extensions: []
@@ -29,9 +29,12 @@ extensions: []
29
29
  extra_rdoc_files: []
30
30
 
31
31
  files:
32
+ - lib/cover.jpg
32
33
  - lib/sc2epub.rb
33
34
  - bin/sc2epub
34
35
  - sc2epub.gemspec
36
+ - README
37
+ - CHANGES
35
38
  has_rdoc: true
36
39
  homepage: https://github.com/takada-at/sc2epub
37
40
  licenses: []