manbook 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5f2c9c00d580c00257ea87242c31b510a6fd9e4
4
- data.tar.gz: f741230cd8ccd20d1a54f1aa268fae9bb16ff45f
3
+ metadata.gz: 85e4b2dd68f7fb7b8416653cebfa676331f0d275
4
+ data.tar.gz: c2618d98a3e47bed7b0c718274c600b85b4dcd4b
5
5
  SHA512:
6
- metadata.gz: 093fbb8eb2f50b33d333a1405c3fb3c0074d9c5e0ad9a1a160061c6ff77b125809fe6abd5a1d595182e012eca47e89d5300472e9c98ada223bdcd130953d74a9
7
- data.tar.gz: 9bd342b49bb3d9e39f5da97098abd1b6e6282b34890a75e2c1ebeffcaadea1c29bc10c8a7d2727d3acc62f65bcb01afc3b398e5571e37b2cd69ed9a424edb31d
6
+ metadata.gz: b72acd32f82bfcbc5eae9092720be3eb202ee0f07b2efa6e88a977e6e574061d02a0708e6693509f3e2aa53bf422e3f27f1bd8c56eee11e76eeecef8c7810123
7
+ data.tar.gz: 2e3620a64a80aec997379ec923b488ea5b36acc9cb55142af3a34d0e751be4dd5a6db2b4e1f12f3ecf109fd32270cf7750d7e67f3d44650be2b9f0484749fc62
data/Gemfile CHANGED
@@ -9,4 +9,6 @@ group :development do
9
9
  gem 'pry'
10
10
  gem 'bundler', '~> 1.0'
11
11
  gem 'jeweler', '~> 1.8'
12
+ gem 'guard-minitest'#, '~> 0.5'
13
+ gem 'guard-bundler' #, '~> 1.0'
12
14
  end
@@ -13,6 +13,8 @@ GEM
13
13
  coderay (1.0.9)
14
14
  faraday (0.8.7)
15
15
  multipart-post (~> 1.1)
16
+ ffi (1.9.0)
17
+ formatador (0.2.4)
16
18
  git (1.2.5)
17
19
  github_api (0.10.1)
18
20
  addressable
@@ -21,6 +23,17 @@ GEM
21
23
  multi_json (~> 1.4)
22
24
  nokogiri (~> 1.5.2)
23
25
  oauth2
26
+ guard (1.8.1)
27
+ formatador (>= 0.2.4)
28
+ listen (>= 1.0.0)
29
+ lumberjack (>= 1.0.2)
30
+ pry (>= 0.9.10)
31
+ thor (>= 0.14.6)
32
+ guard-bundler (1.0.0)
33
+ bundler (~> 1.0)
34
+ guard (~> 1.1)
35
+ guard-minitest (0.5.0)
36
+ guard (>= 0.4)
24
37
  hashie (2.0.5)
25
38
  highline (1.6.19)
26
39
  httpauth (0.2.0)
@@ -37,6 +50,11 @@ GEM
37
50
  json (1.8.0)
38
51
  jwt (0.1.8)
39
52
  multi_json (>= 1.5)
53
+ listen (1.2.2)
54
+ rb-fsevent (>= 0.9.3)
55
+ rb-inotify (>= 0.9)
56
+ rb-kqueue (>= 0.2)
57
+ lumberjack (1.0.4)
40
58
  method_source (0.8.1)
41
59
  minitest (4.7.5)
42
60
  multi_json (1.7.7)
@@ -57,9 +75,15 @@ GEM
57
75
  slop (~> 3.4)
58
76
  rack (1.5.2)
59
77
  rake (10.1.0)
78
+ rb-fsevent (0.9.3)
79
+ rb-inotify (0.9.0)
80
+ ffi (>= 0.5.0)
81
+ rb-kqueue (0.2.0)
82
+ ffi (>= 0.5.0)
60
83
  rdoc (4.0.1)
61
84
  json (~> 1.4)
62
85
  slop (3.4.5)
86
+ thor (0.18.1)
63
87
  thread_safe (0.1.0)
64
88
  atomic
65
89
  tzinfo (0.3.37)
@@ -70,6 +94,8 @@ PLATFORMS
70
94
  DEPENDENCIES
71
95
  activesupport (~> 4.0)
72
96
  bundler (~> 1.0)
97
+ guard-bundler
98
+ guard-minitest
73
99
  jeweler (~> 1.8)
74
100
  nokogiri (~> 1.5)
75
101
  open4 (~> 1.3)
@@ -0,0 +1,12 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ # Uncomment next line if Gemfile contain `gemspec' command
4
+ # watch(/^.+\.gemspec/)
5
+ end
6
+
7
+ guard 'minitest' do
8
+ # with Minitest::Unit
9
+ watch(%r|^test/(.*)\/?test_(.*)\.rb|)
10
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
11
+ watch(%r|^test/test_helper\.rb|) { "test" }
12
+ end
data/TODO CHANGED
@@ -1,2 +1,2 @@
1
1
  * Do not overwrite existing files unless --force was given
2
- * Prevent the cover image attribution in about.html if no or a custom cover is used
2
+ * Prevent the cover image attribution in about.html if no or a custom cover is used
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/bin/mktoc CHANGED
@@ -36,6 +36,7 @@ GENERATOR = "#{File.basename(__FILE__)} v#{ManBook::VERSION}"
36
36
  @book_title = ManBook::TITLE_DEFAULT
37
37
  @cover_image = ManBook::COVER_IMAGE_DEFAULT
38
38
  @book_author = ManBook::AUTHOR_DEFAULT
39
+ @order = ManBook::ORDER_DEFAULT
39
40
 
40
41
  opts = OptionParser.new do |opts|
41
42
  opts.banner = help
@@ -75,6 +76,11 @@ opts = OptionParser.new do |opts|
75
76
  opts.on("--no-cover-image", "Do not reference a cover image") do
76
77
  @cover_image = nil
77
78
  end
79
+
80
+ opts.on("--sort-by ORDER", "Speficy what attribute is used to determine the sort order of pages") do |order|
81
+ ManBook.logger.info "Chapters will be ordered by page #{order}"
82
+ @order = order.to_sym
83
+ end
78
84
  end
79
85
 
80
86
  def render(template, my_binding = binding)
@@ -113,9 +119,14 @@ begin
113
119
  }
114
120
 
115
121
  # find pages
116
- @pages = Dir.glob(File.join(src_dir, "*.html")).reject{|f| INDEX_HTML == File.basename(f)}.collect{|html_file|
117
- ManBook::Parser.parse(html_file)
118
- }.sort{|l,r| l[:title] <=> r[:title]}
122
+ begin
123
+ @pages = Dir.glob(File.join(src_dir, "*.html")).reject{|f| INDEX_HTML == File.basename(f)}.collect{|html_file|
124
+ ManBook::Parser.parse(html_file)
125
+ }.sort{|l,r| l.send(@order) <=> r.send(@order)}
126
+ rescue NoMethodError
127
+ attributes = (ManBook::Page.new.public_methods - Object.public_methods).reject{|m| m.match(/=$/)}
128
+ raise "#{@order} is not a valid sort order attribute. Value values are #{attributes.join(', ')}."
129
+ end
119
130
 
120
131
  # index.html
121
132
  File.open(File.join(src_dir, INDEX_HTML), 'w') {|f|
@@ -10,15 +10,17 @@ require 'nokogiri'
10
10
  require 'manbook/formatter'
11
11
  require 'manbook/html_formatter'
12
12
  require 'manbook/parser'
13
+ require 'manbook/page'
13
14
 
14
15
  require 'manbook/errors'
15
16
  require 'manbook/log_formatter'
16
17
 
17
18
  module ManBook
18
19
  VERSION = File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION])).chomp
19
- TITLE_DEFAULT = "ManBook - a book of selected man pages"
20
- AUTHOR_DEFAULT = "Multiple Authors"
20
+ TITLE_DEFAULT = 'ManBook - a book of selected man pages'
21
+ AUTHOR_DEFAULT = 'Multiple Authors'
21
22
  COVER_IMAGE_DEFAULT = File.join(File.dirname(__FILE__), '..', 'templates', 'library_books.jpg')
23
+ ORDER_DEFAULT = :title
22
24
 
23
25
  mattr_accessor :logger
24
26
 
@@ -0,0 +1,5 @@
1
+ module ManBook
2
+ class Page
3
+ attr_accessor :file_name, :title, :author
4
+ end
5
+ end
@@ -25,7 +25,11 @@ module ManBook
25
25
  author = doc.xpath("//h2[text() = 'AUTHORS']/following-sibling::p[1]/descendant-or-self::text()").to_s
26
26
  end
27
27
 
28
- {:file_name => File.basename(html_file), :title => title.split("\n").join(' '), :author => author.split("\n").join(' ')}
28
+ Page.new.tap do |page|
29
+ page.file_name = File.basename(html_file)
30
+ page.title = title.split("\n").join(' ')
31
+ page.author = author.split("\n").join(' ')
32
+ end
29
33
  end
30
34
  end
31
35
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "manbook"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nicholas E. Rabenau"]
12
- s.date = "2013-07-22"
12
+ s.date = "2013-07-26"
13
13
  s.description = "The manbook command can be used to produce an eBook from one or more man pages."
14
14
  s.email = "nerab@gmx.net"
15
15
  s.executables = ["manbook", "mktoc", "manbook"]
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  ".document",
23
23
  "Gemfile",
24
24
  "Gemfile.lock",
25
+ "Guardfile",
25
26
  "LICENSE.txt",
26
27
  "README.md",
27
28
  "Rakefile",
@@ -34,6 +35,7 @@ Gem::Specification.new do |s|
34
35
  "lib/manbook/formatter.rb",
35
36
  "lib/manbook/html_formatter.rb",
36
37
  "lib/manbook/log_formatter.rb",
38
+ "lib/manbook/page.rb",
37
39
  "lib/manbook/parser.rb",
38
40
  "manbook.gemspec",
39
41
  "templates/_page.html.erb",
@@ -43,6 +45,7 @@ Gem::Specification.new do |s|
43
45
  "templates/library_books.jpg",
44
46
  "templates/manbook.ncx.erb",
45
47
  "templates/manbook.opf.erb",
48
+ "test/fixtures/about.html",
46
49
  "test/fixtures/alt-cover.jpg",
47
50
  "test/fixtures/bash.html",
48
51
  "test/fixtures/cat.html",
@@ -53,7 +56,8 @@ Gem::Specification.new do |s|
53
56
  "test/fixtures/man.html",
54
57
  "test/helper.rb",
55
58
  "test/unit/test_manbook.rb",
56
- "test/unit/test_mktoc.rb"
59
+ "test/unit/test_mktoc.rb",
60
+ "test/unit/test_page.rb"
57
61
  ]
58
62
  s.homepage = "http://github.com/nerab/manbook"
59
63
  s.licenses = ["MIT"]
@@ -72,6 +76,8 @@ Gem::Specification.new do |s|
72
76
  s.add_development_dependency(%q<pry>, [">= 0"])
73
77
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
74
78
  s.add_development_dependency(%q<jeweler>, ["~> 1.8"])
79
+ s.add_development_dependency(%q<guard-minitest>, [">= 0"])
80
+ s.add_development_dependency(%q<guard-bundler>, [">= 0"])
75
81
  else
76
82
  s.add_dependency(%q<activesupport>, ["~> 4.0"])
77
83
  s.add_dependency(%q<open4>, ["~> 1.3"])
@@ -80,6 +86,8 @@ Gem::Specification.new do |s|
80
86
  s.add_dependency(%q<pry>, [">= 0"])
81
87
  s.add_dependency(%q<bundler>, ["~> 1.0"])
82
88
  s.add_dependency(%q<jeweler>, ["~> 1.8"])
89
+ s.add_dependency(%q<guard-minitest>, [">= 0"])
90
+ s.add_dependency(%q<guard-bundler>, [">= 0"])
83
91
  end
84
92
  else
85
93
  s.add_dependency(%q<activesupport>, ["~> 4.0"])
@@ -89,6 +97,8 @@ Gem::Specification.new do |s|
89
97
  s.add_dependency(%q<pry>, [">= 0"])
90
98
  s.add_dependency(%q<bundler>, ["~> 1.0"])
91
99
  s.add_dependency(%q<jeweler>, ["~> 1.8"])
100
+ s.add_dependency(%q<guard-minitest>, [">= 0"])
101
+ s.add_dependency(%q<guard-bundler>, [">= 0"])
92
102
  end
93
103
  end
94
104
 
@@ -1 +1 @@
1
- <li><a href="<%= page[:file_name] %>"><%= page[:title] %></a></li>
1
+ <li><a href="<%= page.file_name %>"><%= page.title %></a></li>
@@ -13,9 +13,9 @@
13
13
  <navMap>
14
14
  <% i = 0 %>
15
15
  <% @pages.each_with_index{|page, i| %>
16
- <navPoint id="<%= page[:file_name] %>" playOrder="<%= i + 1 %>">
17
- <navLabel><text><%= page[:title] %></text></navLabel>
18
- <content src="<%= page[:file_name] %>" />
16
+ <navPoint id="<%= page.file_name %>" playOrder="<%= i + 1 %>">
17
+ <navLabel><text><%= page.title %></text></navLabel>
18
+ <content src="<%= page.file_name %>" />
19
19
  </navPoint>
20
20
  <% } %>
21
21
  <% unless @cover_image.nil? %>
@@ -17,7 +17,7 @@
17
17
  <item id="index" href="index.html" media-type="text/html" />
18
18
  <item id="toc" href="index.ncx" media-type="application/x-dtbncx+xml"/>
19
19
  <% @pages.each{|page| %>
20
- <item id="<%= page[:file_name] %>" href="<%= page[:file_name] %>" media-type="text/html" />
20
+ <item id="<%= page.file_name %>" href="<%= page.file_name %>" media-type="text/html" />
21
21
  <% } %>
22
22
  </manifest>
23
23
  <spine toc="toc">
@@ -26,7 +26,7 @@
26
26
  <% end %>
27
27
  <itemref idref="index" />
28
28
  <% @pages.each{|page| %>
29
- <itemref idref="<%= page[:file_name] %>" />
29
+ <itemref idref="<%= page.file_name %>" />
30
30
  <% } %>
31
31
  </spine>
32
32
  <guide>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2
+ <html>
3
+ <head>
4
+ <meta name="generator" content="mktoc v0.0.2">
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6
+ <style type="text/css">
7
+ h1 {font-size: 1.5em; margin-bottom: 1em;}
8
+ h2 {font-size: 1.375em; margin: 1.25em 0 0.25em 0;}
9
+ h3 {font-size: 1.25em; margin: 1.25em 0 0.25em 0;}
10
+ h4 {font-size: 1.125em; margin: 1.25em 0 0.25em 0;}
11
+ h5 {font-size: 1em; font-weight: bold; margin: 1.25em 0 0.25em 0;}
12
+ h6 {font-size: 1.375em; font-weight: bold; margin: 1.25em 0 0.25em 0;}
13
+ table {margin-top: 0.75em;}
14
+ p {margin: .125em 0 .5em 0; text-indent: 0;}
15
+ ul, ol, blockquote, pre, dl, hr {margin-top: .125em; margin-bottom: .5em;}
16
+ .toc ul {list-style: none; padding-left: 0; margin-left: 20px;}
17
+ </style>
18
+ <title>About this book</title>
19
+ </head>
20
+ <body>
21
+ <h1 style="font-size: 2em; margin-top: 2em;" align="center">ManBook - a book of selected man pages</h1>
22
+
23
+ <p>This book was created using the <a href='http://github.com/nerab/manbook'>mktoc v0.0.2</a> tool.</p>
24
+
25
+ <p>The cover image was published by CCAC North Library under CC BY 2.0. It can be found at <a href='http://www.flickr.com/photos/ccacnorthlib/4131076795/'>flickr</a>.</p>
26
+ </body>
27
+ </html>
@@ -2,6 +2,7 @@ require 'bundler'
2
2
  require 'tmpdir'
3
3
  require 'fileutils'
4
4
  require 'active_support/core_ext/string'
5
+ require 'active_support/core_ext/hash/reverse_merge'
5
6
 
6
7
  begin
7
8
  Bundler.setup(:default, :development)
@@ -37,6 +37,8 @@ module ManBookTest
37
37
 
38
38
  COVER_IMAGE_ALT = File.join(FIXTURES_DIR, 'alt-cover.jpg')
39
39
 
40
+ SPECIAL_TITLE_FIXTURES = ['about.html', 'bash.html', 'git.html', 'gunzip.html', 'less.html', 'man.html']
41
+
40
42
  def setup
41
43
  super
42
44
  fixtures = Dir.glob(File.join(FIXTURES_DIR, '*.html'))
@@ -50,38 +52,53 @@ module ManBookTest
50
52
 
51
53
  def test_defaults
52
54
  assert_exec("#{app_script} #{output_dir}")
53
- test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, File.basename(ManBook::COVER_IMAGE_DEFAULT))
55
+ test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, :cover_image => File.basename(ManBook::COVER_IMAGE_DEFAULT))
54
56
  end
55
57
 
56
58
  def test_overridden_title
57
59
  title = "Foo42Bar"
58
60
  assert_exec("#{app_script} #{output_dir} --title \"#{title}\"")
59
- test_all_workproducts(title, ManBook::AUTHOR_DEFAULT, File.basename(ManBook::COVER_IMAGE_DEFAULT))
61
+ test_all_workproducts(title, ManBook::AUTHOR_DEFAULT, :cover_image => File.basename(ManBook::COVER_IMAGE_DEFAULT))
60
62
  end
61
63
 
62
64
  def test_overridden_author
63
65
  author = "James Born"
64
66
  assert_exec("#{app_script} #{output_dir} --author \"#{author}\"")
65
- test_all_workproducts(ManBook::TITLE_DEFAULT, author, File.basename(ManBook::COVER_IMAGE_DEFAULT))
67
+ test_all_workproducts(ManBook::TITLE_DEFAULT, author, :cover_image => File.basename(ManBook::COVER_IMAGE_DEFAULT))
66
68
  end
67
69
 
68
70
  def test_overridden_title_and_author
69
71
  title = "Foo42Bar42"
70
72
  author = "James F. Born"
71
73
  assert_exec("#{app_script} #{output_dir} --title \"#{title}\" --author \"#{author}\"")
72
- test_all_workproducts(title, author, File.basename(ManBook::COVER_IMAGE_DEFAULT))
74
+ test_all_workproducts(title, author, :cover_image => File.basename(ManBook::COVER_IMAGE_DEFAULT))
73
75
  end
74
76
 
75
77
  def test_no_cover_image
76
78
  assert_exec("#{app_script} #{output_dir} --no-cover-image")
77
- test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, nil)
79
+ test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT)
80
+ end
81
+
82
+ def test_order_by_title
83
+ assert_exec("#{app_script} #{output_dir} --no-cover-image --sort-by=title")
84
+ test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, :order => :title)
85
+ end
86
+
87
+ def test_order_by_author
88
+ assert_exec("#{app_script} #{output_dir} --no-cover-image --sort-by=author")
89
+ test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, :order => :author)
90
+ end
91
+
92
+ def test_order_by_unknown_attribute
93
+ order = "DOES_NOT_EXIST"
94
+ assert_exec("#{app_script} #{output_dir} --no-cover-image --sort-by=#{order}", false, nil, /ERROR: #{order} is not a valid sort order attribute/)
78
95
  end
79
96
 
80
97
  def test_alt_cover_image
81
98
  cover_image = COVER_IMAGE_ALT
82
99
  assert(File.exist?(cover_image))
83
100
  assert_exec("#{app_script} #{output_dir} --cover-image #{cover_image}")
84
- test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, File.basename(cover_image))
101
+ test_all_workproducts(ManBook::TITLE_DEFAULT, ManBook::AUTHOR_DEFAULT, :cover_image => File.basename(cover_image))
85
102
  end
86
103
 
87
104
  def test_alt_cover_image_not_found
@@ -91,11 +108,13 @@ module ManBookTest
91
108
  end
92
109
 
93
110
  private
94
- def test_all_workproducts(title, author, cover_image = nil)
95
- if cover_image.nil?
111
+ def test_all_workproducts(title, author, options = {})
112
+ options.reverse_merge!({:cover_image => nil, :order => ManBook::ORDER_DEFAULT})
113
+
114
+ if options[:cover_image].nil?
96
115
  workproducts = WORKPRODUCTS
97
116
  else
98
- workproducts = WORKPRODUCTS.merge({:cover => cover_image})
117
+ workproducts = WORKPRODUCTS.merge({:cover => options[:cover_image]})
99
118
  end
100
119
 
101
120
  expected = @fixtures + workproducts.values
@@ -109,7 +128,7 @@ module ManBookTest
109
128
  # dispatch to test that is specific to the work product
110
129
  wp_test = WORK_PRODUCT_TESTS[k]
111
130
  raise "No test defined for work product #{k}" if wp_test.nil?
112
- send(wp_test, title, author, cover_image)
131
+ send(wp_test, title, author, options)
113
132
  }
114
133
  end
115
134
 
@@ -143,9 +162,12 @@ module ManBookTest
143
162
  "#{APP_SCRIPT}"
144
163
  end
145
164
 
146
- def test_workproduct_html(title, author, cover_image = nil)
165
+ def test_workproduct_html(title, author, options)
166
+ options.reverse_merge!({:cover_image => nil, :order => ManBook::ORDER_DEFAULT})
167
+
147
168
  doc = Nokogiri::HTML(File.read(File.join(output_dir, 'index.html')))
148
- assert_workproduct(['about.html'].concat(@fixtures), doc, '/html/body/ul/li', 'a/@href')
169
+
170
+ assert_workproduct(@fixtures, doc, '/html/body/ul/li', 'a/@href')
149
171
 
150
172
  # index.html does not use the book title, but "Table Of Contents"
151
173
  assert_equal("Table Of Contents", doc.xpath('/html/head/title/text()').to_s)
@@ -153,36 +175,49 @@ module ManBookTest
153
175
 
154
176
  assert_equal(GENERATOR, doc.xpath("/html/head/meta[@name='generator']/@content").to_s)
155
177
  assert_equal("About this book", doc.xpath('/html/body/ul/li[1]/a/text()').to_s)
178
+
179
+ sorted_pages = pages.sort{|l,r| l.send(options[:order]) <=> r.send(options[:order])}
180
+
181
+ # Test href in content and in order
182
+ expected_files = sorted_pages.map{|p| p.file_name}
183
+ actual_files = doc.xpath('/html/body/ul/li/a/@href').map{|a| a.value}
184
+ assert_equal(expected_files, actual_files)
185
+
186
+ # Test titles in content and in order
187
+ expected_titles = sorted_pages.map{|p| p.title.upcase}
188
+ actual_titles = doc.xpath("/html/body/ul/li").map{|li| li.inner_text.upcase}
189
+ assert_equal(expected_titles, actual_titles)
156
190
  end
157
191
 
158
- def test_workproduct_ncx(title, author, cover_image = nil)
192
+ def test_workproduct_ncx(title, author, options)
193
+ options.reverse_merge!({:cover_image => nil, :order => ManBook::ORDER_DEFAULT})
194
+
159
195
  doc = Nokogiri::XML(File.read(File.join(output_dir, 'index.ncx')))
160
196
 
161
- fixtures = ['about.html'].concat(@fixtures)
162
- fixtures << cover_image unless cover_image.nil?
163
- assert_workproduct(fixtures, doc, '/xmlns:ncx/xmlns:navMap/xmlns:navPoint', 'xmlns:content/@src')
197
+ @fixtures << options[:cover_image] unless options[:cover_image].nil?
198
+ assert_workproduct(@fixtures, doc, '/xmlns:ncx/xmlns:navMap/xmlns:navPoint', 'xmlns:content/@src')
164
199
 
165
200
  assert_equal(title, doc.xpath("/xmlns:ncx/xmlns:head/xmlns:meta[@name='dtb:title']/@content").to_s)
166
201
  assert_equal(title, doc.xpath("/xmlns:ncx/xmlns:docTitle/xmlns:text/text()").to_s)
167
202
  assert_equal(GENERATOR, doc.xpath("/xmlns:ncx/xmlns:head/xmlns:meta[@name='dtb:generator']/@content").to_s)
168
203
 
169
- # TODO id and order
204
+ # TODO id and order of members as specified in playOrder
170
205
  # navPoint
171
206
  # @id="bash.html"
172
207
  # @playOrder="0"
173
208
  end
174
209
 
175
- def test_workproduct_opf(title, author, cover_image = nil)
210
+ def test_workproduct_opf(title, author, options)
211
+ options.reverse_merge!({:cover_image => nil, :order => ManBook::ORDER_DEFAULT})
176
212
  doc = Nokogiri::XML(File.read(File.join(output_dir, 'index.opf')))
177
213
 
178
214
  # the opf must include links to index.html and index.ncx
179
- item_fixtures = ['index.html', 'index.ncx', 'about.html'].concat(@fixtures)
180
- item_fixtures << cover_image unless cover_image.nil?
215
+ item_fixtures = ['index.html', 'index.ncx'].concat(@fixtures)
181
216
  assert_workproduct(item_fixtures, doc, '//xmlns:manifest/xmlns:item', '@href')
182
217
 
183
- # cross-references within the document
184
- xref_fixtures = ['index', 'about.html'].concat(@fixtures)
185
- xref_fixtures << 'cover-image' unless cover_image.nil?
218
+ # cross-references within the document, but only include *.html fixtures
219
+ xref_fixtures = ['index'].concat(@fixtures.select{|f| f.match(/.*\.html/)})
220
+ xref_fixtures << 'cover-image' unless options[:cover_image].nil?
186
221
  assert_workproduct(xref_fixtures, doc, '//xmlns:spine/xmlns:itemref', '@idref')
187
222
 
188
223
  assert_equal(title, doc.xpath('/xmlns:package/xmlns:metadata/dc:title/text()',
@@ -194,16 +229,25 @@ module ManBookTest
194
229
  'xmlns' => 'http://www.idpf.org/2007/opf'}).first.to_s)
195
230
 
196
231
  # reference to cover image in meta data. The other two references were already tested above
197
- unless cover_image.nil?
232
+ unless options[:cover_image].nil?
198
233
  assert_equal('cover-image', doc.xpath("/xmlns:package/xmlns:metadata/xmlns:meta[@name='cover']/@content").to_s)
199
234
  end
235
+
236
+ # TODO id and href. Order does not matter.
237
+ # <item id="less.html" href="less.html" media-type="text/html" />
238
+
239
+ # TODO Assert than members present in the manifest are also present in the spine
200
240
  end
201
241
 
202
- def test_workproduct_about(title, author, cover_image = nil)
242
+ def test_workproduct_about(title, author, options)
243
+ options.reverse_merge!({:cover_image => nil, :order => ManBook::ORDER_DEFAULT})
244
+
203
245
  # no further tests
204
246
  end
205
247
 
206
- def test_workproduct_cover(title, author, cover_image = nil)
248
+ def test_workproduct_cover(title, author, options)
249
+ options.reverse_merge!({:cover_image => nil, :order => ManBook::ORDER_DEFAULT})
250
+
207
251
  # no further tests
208
252
  end
209
253
 
@@ -229,5 +273,11 @@ module ManBookTest
229
273
  assert(fixtures.include?(li), "Could not find '#{li}' in #{fixtures.inspect}")
230
274
  }
231
275
  end
276
+
277
+ def pages
278
+ @fixtures.map do |fixture|
279
+ ManBook::Parser.parse(File.join(FIXTURES_DIR, fixture))
280
+ end
281
+ end
232
282
  end
233
283
  end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ module ManBookTest
4
+ class TestPage < ManBookTest::TestCase
5
+ def test_about
6
+ file_name = 'about.html'
7
+ page = ManBook::Parser.parse(fixture(file_name))
8
+ refute_nil(page)
9
+ assert_equal('About this book', page.title)
10
+ assert_equal('', page.author)
11
+ assert_equal(file_name, page.file_name)
12
+ end
13
+
14
+ def test_cat
15
+ file_name = 'cat.html'
16
+ page = ManBook::Parser.parse(fixture(file_name))
17
+ refute_nil(page)
18
+ assert_equal('cat — concatenate and print files', page.title)
19
+ assert_equal('', page.author)
20
+ assert_equal(file_name, page.file_name)
21
+ end
22
+
23
+ def test_git
24
+ file_name = 'git.html'
25
+ page = ManBook::Parser.parse(fixture(file_name))
26
+ refute_nil(page)
27
+ assert_equal('git − the stupid content tracker', page.title)
28
+ assert_match(/Linus Torvalds/, page.author)
29
+ assert_equal(file_name, page.file_name)
30
+ end
31
+
32
+ private
33
+
34
+ def fixture(basename)
35
+ File.join(FIXTURES_DIR, basename)
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manbook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas E. Rabenau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-22 00:00:00.000000000 Z
11
+ date: 2013-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.8'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-minitest
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: The manbook command can be used to produce an eBook from one or more
112
140
  man pages.
113
141
  email: nerab@gmx.net
@@ -123,6 +151,7 @@ files:
123
151
  - .document
124
152
  - Gemfile
125
153
  - Gemfile.lock
154
+ - Guardfile
126
155
  - LICENSE.txt
127
156
  - README.md
128
157
  - Rakefile
@@ -135,6 +164,7 @@ files:
135
164
  - lib/manbook/formatter.rb
136
165
  - lib/manbook/html_formatter.rb
137
166
  - lib/manbook/log_formatter.rb
167
+ - lib/manbook/page.rb
138
168
  - lib/manbook/parser.rb
139
169
  - manbook.gemspec
140
170
  - templates/_page.html.erb
@@ -144,6 +174,7 @@ files:
144
174
  - templates/library_books.jpg
145
175
  - templates/manbook.ncx.erb
146
176
  - templates/manbook.opf.erb
177
+ - test/fixtures/about.html
147
178
  - test/fixtures/alt-cover.jpg
148
179
  - test/fixtures/bash.html
149
180
  - test/fixtures/cat.html
@@ -155,6 +186,7 @@ files:
155
186
  - test/helper.rb
156
187
  - test/unit/test_manbook.rb
157
188
  - test/unit/test_mktoc.rb
189
+ - test/unit/test_page.rb
158
190
  homepage: http://github.com/nerab/manbook
159
191
  licenses:
160
192
  - MIT