gepub 0.3.0 → 0.4.0

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/README.rdoc CHANGED
@@ -79,7 +79,7 @@ a good-enough EPUB generator library.
79
79
 
80
80
  (The New BSD License)
81
81
 
82
- Copyright (c) 2010, KOJIMA Satoshi
82
+ Copyright (c) 2010-2011, KOJIMA Satoshi
83
83
  All rights reserved.
84
84
 
85
85
  Redistribution and use in source and binary forms, with or without
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
data/bin/gepuber CHANGED
@@ -43,7 +43,7 @@ Dir.chdir(srcdir)
43
43
  begin
44
44
  File.open('gepuber.conf', 'rb') {
45
45
  |io|
46
- gepuber = GEPUB::Gepuber.new(io.read)
46
+ gepuber = GEPUB::Gepuber.new(eval("#{io.read}"))
47
47
  gepuber.create destbasedir
48
48
  }
49
49
  end
data/gepub.gemspec CHANGED
@@ -5,12 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gepub}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["KOJIMA Satoshi"]
12
- s.date = %q{2011-04-15}
13
- s.default_executable = %q{gepuber}
12
+ s.date = %q{2011-04-21}
14
13
  s.description = %q{an easy-to-use (and easy-to-implement) EPUB generator.}
15
14
  s.email = %q{skoji@skoji.jp}
16
15
  s.executables = ["gepuber"]
@@ -31,16 +30,20 @@ Gem::Specification.new do |s|
31
30
  "lib/gepub/generator.rb",
32
31
  "lib/gepub/gepuber.rb",
33
32
  "lib/gepub/item.rb",
33
+ "spec/fixtures/testdata/0.html",
34
+ "spec/fixtures/testdata/1.html",
34
35
  "spec/gepub_spec.rb",
36
+ "spec/gepuber_spec.rb",
35
37
  "spec/spec_helper.rb"
36
38
  ]
37
39
  s.homepage = %q{http://github.com/skoji/gepub}
38
40
  s.require_paths = ["lib"]
39
- s.rubygems_version = %q{1.5.2}
41
+ s.rubygems_version = %q{1.7.2}
40
42
  s.summary = %q{a good-enough EPUB generator.}
41
43
  s.test_files = [
42
44
  "examples/example.rb",
43
45
  "spec/gepub_spec.rb",
46
+ "spec/gepuber_spec.rb",
44
47
  "spec/spec_helper.rb"
45
48
  ]
46
49
 
data/lib/gepub/gepuber.rb CHANGED
@@ -1,63 +1,54 @@
1
1
  require 'rubygems'
2
2
 
3
3
  module GEPUB
4
- class Gepuber
5
-
6
- def self.book_setter(*namelist)
7
- namelist.each {
8
- |name|
9
- define_method (name.to_sym) {
10
- |arg|
11
- @book.send(name.to_s + "=" , arg)
12
- }
13
- }
14
- end
4
+ class Gepuber < GEPUB::Book
5
+ class FileProvider
6
+ include Enumerable
7
+ def initialize(pattern)
8
+ @list = Dir.glob(pattern)
9
+ end
15
10
 
16
- def self.attr_setter(*namelist)
17
- namelist.each {
18
- |name|
19
- define_method (name.to_sym) {
20
- |arg|
21
- instance_variable_set("@" + name.to_s, arg)
11
+ def each (&block)
12
+ @list.each {
13
+ |f|
14
+ File.open(f, 'rb') {
15
+ |fio|
16
+ yield f, fio
17
+ }
22
18
  }
23
- }
19
+ end
24
20
  end
25
21
 
26
- attr_setter :texts, :resources, :epubname, :coverimg, :book, :toc
27
- book_setter :title, :author, :publisher, :date, :identifier, :locale
28
-
29
- def initialize(str)
30
- @book = GEPUB::Book.new('', 'OEBPS')
31
- @book.locale = 'ja'
32
- instance_eval(str)
33
- @texts ||= Dir.glob('[0-9]*.html')
34
- @resources ||= Dir.glob('*.css') + Dir.glob(File.join('img', '*'))
22
+ attr_accessor :texts, :resources, :epubname, :coverimg, :table_of_contents, :provider
23
+
24
+ def initialize(param)
25
+ super('', 'OEBPS')
26
+ param.each {
27
+ |k,v|
28
+ self.send "#{k}=", v
29
+ }
30
+ @texts ||= ['[0-9]*.html']
31
+ @resources ||= ['*.css', 'img/*']
35
32
  @coverimg ||= 'cover.jpg'
36
- @toc ||= {}
33
+ @table_of_contents ||= {}
37
34
  @epubname ||= 'gepuber_generated'
35
+ @provider ||= FileProvider
38
36
  end
39
37
 
40
38
  def create(destbasedir = ".")
41
-
42
- @texts.each {
43
- |f|
44
- File.open(f,'rb') {
45
- |fio|
46
- item = @book.add_item(f, fio)
47
- @book.spine << item
48
- @book.add_nav(item, @toc[f]) if !@toc[f].nil?
49
- }
39
+ @provider.new(@texts).each {
40
+ |f, fio|
41
+ item = add_item(f, fio)
42
+ @spine << item
43
+ add_nav(item, @toc[f]) if !@toc[f].nil?
50
44
  }
51
45
 
52
- @resources.each {
53
- |f|
54
- File.open(f,'rb') {
55
- |fio|
56
- item = @book.add_item(f, fio)
57
- @book.specify_cover_image(item) if File.basename(f) == @coverimg
58
- }
46
+ @provider.new(@resources).each {
47
+ |f, fio|
48
+ item = add_item(f, fio)
49
+ specify_cover_image(item) if File.basename(f) == @coverimg
59
50
  }
60
- @book.generate_epub(File.join(destbasedir, @epubname + '.epub'))
51
+ generate_epub(File.join(destbasedir, @epubname + '.epub'))
61
52
  end
62
53
  end
63
54
  end
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <title>gepuber test book</title>
5
+ <link rel="stylesheet" type="text/css" href="gepuber.css"></link>
6
+ </head>
7
+ <body>
8
+ <div>
9
+ <img class="cover" src="img/cover.jpg" alt="cover" />
10
+ </div>
11
+ </body>
12
+ </html>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+ <title>gepuber test book: page 1</title>
5
+ <link rel="stylesheet" type="text/css" href="gepuber.css"></link>
6
+ </head>
7
+ <body>
8
+ <p>contents comes here</p>
9
+ </body>
10
+ </html>
@@ -0,0 +1,52 @@
1
+ # -*- coding: utf-8 -*-
2
+ # need to install 'epubcheck'.
3
+
4
+ require File.dirname(__FILE__) + '/spec_helper.rb'
5
+ require 'rubygems'
6
+ require 'xml/libxml'
7
+
8
+
9
+ describe GEPUB::Gepuber do
10
+ it "should be initialized with empty conf" do
11
+ gepuber = GEPUB::Gepuber.new({})
12
+ gepuber.texts.should == ['[0-9]*.html']
13
+ gepuber.resources.should == ['*.css', 'img/*']
14
+ gepuber.title.should == ""
15
+ gepuber.table_of_contents.should == {}
16
+ end
17
+
18
+ it "should read config hash" do
19
+ conf =
20
+ {
21
+ locale: 'ja',
22
+ title: 'theTitle',
23
+ author: 'theAuthor',
24
+ publisher: 'thePublisher',
25
+ date: '2011-03-11',
26
+ identifier: 'http://skoji.jp/gepuber/2011-03-11.0.0',
27
+ epubname: 'gepub_00',
28
+ table_of_contents: {
29
+ '1_.html' => '1st toc',
30
+ '3_.html' => '3rd toc',
31
+ '9_.html' => 'last toc'
32
+ },
33
+ coverimg: 'cover.gif',
34
+ texts: [ '*.html' ],
35
+ resources: ['*.css','*.gif']
36
+ }
37
+
38
+ gepuber = GEPUB::Gepuber.new(conf )
39
+ gepuber.title.should == "theTitle"
40
+ gepuber.locale.should == "ja"
41
+ gepuber.author.should == "theAuthor"
42
+ gepuber.publisher.should == "thePublisher"
43
+ gepuber.date.should == "2011-03-11"
44
+ gepuber.identifier.should == 'http://skoji.jp/gepuber/2011-03-11.0.0'
45
+ gepuber.epubname.should == 'gepub_00'
46
+ gepuber.coverimg.should == 'cover.gif'
47
+ gepuber.table_of_contents.should == { '1_.html' => '1st toc', '3_.html' => '3rd toc', '9_.html' => 'last toc'}
48
+ gepuber.texts.should == ['*.html']
49
+ gepuber.resources.should == ['*.css', '*.gif']
50
+
51
+ end
52
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gepub
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - KOJIMA Satoshi
@@ -10,8 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-15 00:00:00 +09:00
14
- default_executable: gepuber
13
+ date: 2011-04-21 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: libxml-ruby
@@ -101,9 +100,11 @@ files:
101
100
  - lib/gepub/generator.rb
102
101
  - lib/gepub/gepuber.rb
103
102
  - lib/gepub/item.rb
103
+ - spec/fixtures/testdata/0.html
104
+ - spec/fixtures/testdata/1.html
104
105
  - spec/gepub_spec.rb
106
+ - spec/gepuber_spec.rb
105
107
  - spec/spec_helper.rb
106
- has_rdoc: true
107
108
  homepage: http://github.com/skoji/gepub
108
109
  licenses: []
109
110
 
@@ -127,11 +128,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
128
  requirements: []
128
129
 
129
130
  rubyforge_project:
130
- rubygems_version: 1.5.2
131
+ rubygems_version: 1.7.2
131
132
  signing_key:
132
133
  specification_version: 3
133
134
  summary: a good-enough EPUB generator.
134
135
  test_files:
135
136
  - examples/example.rb
136
137
  - spec/gepub_spec.rb
138
+ - spec/gepuber_spec.rb
137
139
  - spec/spec_helper.rb