htmldoc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +3 -0
- data/History.txt +2 -0
- data/LICENSE.txt +20 -0
- data/Manifest.txt +13 -0
- data/README.txt +96 -0
- data/Rakefile +54 -0
- data/init.rb +1 -0
- data/lib/htmldoc.rb +202 -0
- data/lib/htmldoc/version.rb +17 -0
- data/setup.rb +1585 -0
- data/test/basic_test.rb +98 -0
- data/test/generation_test.rb +92 -0
- data/test/test_helper.rb +2 -0
- metadata +59 -0
data/test/basic_test.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class BasicTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_options
|
6
|
+
all_options = PDF::HTMLDoc.class_eval do
|
7
|
+
class_variable_get(:@@all_options)
|
8
|
+
end
|
9
|
+
all_options.each do |option|
|
10
|
+
pdf = PDF::HTMLDoc.new
|
11
|
+
pdf.set_option option, :default
|
12
|
+
assert_equal :default, pdf.instance_variable_get(:@options)[option]
|
13
|
+
assert_equal 1, pdf.instance_variable_get(:@options).size
|
14
|
+
pdf.set_option option, nil
|
15
|
+
assert_equal 0, pdf.instance_variable_get(:@options).size
|
16
|
+
end
|
17
|
+
pdf = PDF::HTMLDoc.new
|
18
|
+
i = 0
|
19
|
+
all_options.each do |option|
|
20
|
+
pdf.set_option option, i
|
21
|
+
assert_equal i, pdf.instance_variable_get(:@options)[option]
|
22
|
+
assert_equal i + 1, pdf.instance_variable_get(:@options).size
|
23
|
+
i += 1
|
24
|
+
end
|
25
|
+
assert_raise(PDF::HTMLDocException) { pdf.set_option :test, :value }
|
26
|
+
assert_raise(PDF::HTMLDocException) { pdf.set_option "test", "value" }
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_header
|
30
|
+
pdf = PDF::HTMLDoc.new
|
31
|
+
pdf.header ".t."
|
32
|
+
assert_equal ".t.", pdf.instance_variable_get(:@options)[:header]
|
33
|
+
assert_equal 1, pdf.instance_variable_get(:@options).size
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_footer
|
37
|
+
pdf = PDF::HTMLDoc.new
|
38
|
+
pdf.footer ".t."
|
39
|
+
assert_equal ".t.", pdf.instance_variable_get(:@options)[:footer]
|
40
|
+
assert_equal 1, pdf.instance_variable_get(:@options).size
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_get_final_value
|
44
|
+
# Those tests are not exhaustive, but will ensure a reasonable
|
45
|
+
# level of functionality
|
46
|
+
pdf = PDF::HTMLDoc.new
|
47
|
+
tests = [["--webpage", :webpage, true],
|
48
|
+
["--no-encryption", :encryption, :none],
|
49
|
+
["--no-encryption", :encryption, :no],
|
50
|
+
["--no-encryption", :encryption, false],
|
51
|
+
["--encryption", :encryption, true],
|
52
|
+
["--no-encryption", :encryption, :none],
|
53
|
+
["--no-jpeg", :jpeg, :no],
|
54
|
+
["--jpeg 80", :jpeg, 80],
|
55
|
+
["--bodycolor black", :bodycolor, :black],
|
56
|
+
["--left 12in", :left, "12in"],
|
57
|
+
["--cookies 'name=value;other=test'", :cookies, { :name => "value", :other => "test" }]]
|
58
|
+
tests.each do |test|
|
59
|
+
assert_equal test.first, pdf.send(:get_final_value, *test[1,2])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_get_command_options
|
64
|
+
# Those tests are not exhaustive, but should ensure a reasonable
|
65
|
+
# level of functionality.
|
66
|
+
pdf = PDF::HTMLDoc.new
|
67
|
+
tests = [["--webpage", :webpage, true],
|
68
|
+
["--no-encryption", :encryption, :none],
|
69
|
+
["--jpeg 80", :jpeg, 80],
|
70
|
+
["--bodycolor black", :bodycolor, :black],
|
71
|
+
["--left 12in", :left, "12in"],
|
72
|
+
["--cookies 'name=value;other=test'", :cookies, { :name => "value", :other => "test" }]]
|
73
|
+
tests.each do |test|
|
74
|
+
pdf.send(:set_option, *test[1,2])
|
75
|
+
end
|
76
|
+
command_options = tests.collect { |test| test.first }
|
77
|
+
command_options = (command_options + ["--format " + PDF::PDF]).sort.join(" ")
|
78
|
+
assert_equal command_options, pdf.send(:get_command_options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_get_command_pages
|
82
|
+
# Those tests are not exhaustive, but should ensure a reasonable
|
83
|
+
# level of functionality.
|
84
|
+
pdf = PDF::HTMLDoc.new
|
85
|
+
tempfile = Tempfile.new("htmldoc.test")
|
86
|
+
pages = ["http://example.org/", tempfile.path, "Test"]
|
87
|
+
pages.each do |page|
|
88
|
+
pdf << page
|
89
|
+
end
|
90
|
+
command_pages = pdf.send(:get_command_pages)
|
91
|
+
pages[2] = pdf.instance_variable_get(:@tempfiles)[0].path
|
92
|
+
assert_equal pages.join(" "), command_pages
|
93
|
+
ensure
|
94
|
+
tempfiles = pdf.instance_variable_get(:@tempfiles)
|
95
|
+
tempfiles.each { |t| t.close }
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
class GenerationTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
# If you are using a different program path, you should configure
|
7
|
+
# it here.
|
8
|
+
@program_path = PDF::HTMLDoc.program_path
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_program_path
|
12
|
+
data = IO.popen(@program_path + " --version 2>&1") { |s| s.read }
|
13
|
+
assert_equal 0, $?.exitstatus
|
14
|
+
assert_match(/^1.((8.2\d)|9-current)/, data)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_generation
|
18
|
+
# Those tests are not exhaustive, but will ensure a reasonable
|
19
|
+
# level of functionality. Output to directories is not tested for
|
20
|
+
# now.
|
21
|
+
basic_test(PDF::HTML)
|
22
|
+
basic_test(PDF::PS)
|
23
|
+
basic_test(PDF::PDF)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def basic_test(format)
|
29
|
+
path1, path2 = (1..2).collect { |i| Dir.tmpdir + "/#{i}.#{format}" }
|
30
|
+
Tempfile.open("htmldoc.test") do |tempfile|
|
31
|
+
page = "<h1>Page 1</h1><p>Test.</p><h1>Page 2</h1><p>Test.</p>"
|
32
|
+
tempfile.binmode
|
33
|
+
tempfile.write(page)
|
34
|
+
tempfile.flush
|
35
|
+
begin
|
36
|
+
pdf = PDF::HTMLDoc.new(format)
|
37
|
+
pdf.set_option :outfile, path1
|
38
|
+
pdf.add_page tempfile.path
|
39
|
+
assert_equal true, pdf.generate
|
40
|
+
assert_equal pdf.result, execute_htmldoc(path2, tempfile.path, "--format #{format}")
|
41
|
+
ensure
|
42
|
+
File.delete(path1)
|
43
|
+
File.delete(path2)
|
44
|
+
end
|
45
|
+
begin
|
46
|
+
pdf = PDF::HTMLDoc.new(format)
|
47
|
+
pdf.set_option :outfile, path1
|
48
|
+
pdf.set_option :webpage, true
|
49
|
+
pdf.add_page tempfile.path
|
50
|
+
assert_equal true, pdf.generate
|
51
|
+
assert_equal pdf.result, execute_htmldoc(path2, tempfile.path, "--webpage --format #{format}")
|
52
|
+
ensure
|
53
|
+
File.delete(path1)
|
54
|
+
File.delete(path2)
|
55
|
+
end
|
56
|
+
begin
|
57
|
+
pdf = PDF::HTMLDoc.new(format)
|
58
|
+
pdf.set_option :outfile, path1
|
59
|
+
pdf.set_option :bodycolor, :black
|
60
|
+
pdf.add_page tempfile.path
|
61
|
+
assert_equal true, pdf.generate
|
62
|
+
assert_equal pdf.result, execute_htmldoc(path2, tempfile.path, "--bodycolor black --format #{format}")
|
63
|
+
ensure
|
64
|
+
File.delete(path1)
|
65
|
+
File.delete(path2)
|
66
|
+
end
|
67
|
+
begin
|
68
|
+
pdf = PDF::HTMLDoc.new(format)
|
69
|
+
pdf.add_page page
|
70
|
+
pdf.generate
|
71
|
+
assert_equal pdf.result, execute_htmldoc(path2, tempfile.path, "--format #{format}")
|
72
|
+
ensure
|
73
|
+
File.delete(path2)
|
74
|
+
end
|
75
|
+
begin
|
76
|
+
result = PDF::HTMLDoc.create(format) do |p|
|
77
|
+
p.set_option :outfile, path1
|
78
|
+
p.set_option :bodycolor, :black
|
79
|
+
p.add_page tempfile.path
|
80
|
+
end
|
81
|
+
assert_equal true, result
|
82
|
+
ensure
|
83
|
+
File.delete(path1)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def execute_htmldoc(output, input, options)
|
89
|
+
IO.popen("#{@program_path} #{options} -f #{output} #{input} 2>&1") { |s| s.read }
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: htmldoc
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-03-05 00:00:00 -03:00
|
8
|
+
summary: A wrapper around HTMLDOC, a PDF generation utility
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ronaldo@reflectivesurface.com
|
12
|
+
homepage: http://htmldoc.rubyforge.org
|
13
|
+
rubyforge_project: htmldoc
|
14
|
+
description: PDF::HTMLDoc is a wrapper around HTMLDOC, an open-source application that converts HTML input files into formatted HTML, PDF or PostScript output.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Ronaldo M. Ferraz
|
31
|
+
files:
|
32
|
+
- CHANGELOG.txt
|
33
|
+
- History.txt
|
34
|
+
- LICENSE.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- README.txt
|
37
|
+
- Rakefile
|
38
|
+
- init.rb
|
39
|
+
- lib/htmldoc.rb
|
40
|
+
- lib/htmldoc/version.rb
|
41
|
+
- setup.rb
|
42
|
+
- test/basic_test.rb
|
43
|
+
- test/generation_test.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
test_files:
|
46
|
+
- test/basic_test.rb
|
47
|
+
- test/generation_test.rb
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
extra_rdoc_files: []
|
51
|
+
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
dependencies: []
|
59
|
+
|