kristin 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kristin.rb +3 -2
- data/lib/kristin/version.rb +1 -1
- data/spec/kristin_spec.rb +13 -31
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0fefe426acb7a04297008f20d984da8399a11be
|
4
|
+
data.tar.gz: ebf8d9a58e27cd3149230a84ac718638f990c85a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5aa4b3dc4f38ec7e6e708d2e973223cf703d7c61921f1ad4fa1f49ed0a8eecd72e53b29516991c61f234ec54367f8032a27bd0d28ad9cb8c7da1b5212c31089
|
7
|
+
data.tar.gz: d4be95ab1995cf82b7ef2991df528796f88a802bb1a358b8bc1750dd3d111f34ec7a7c78c4d4dbae0d5d3fb9eded77aa95ead963a970af9c4d777fe13bad661e
|
data/lib/kristin.rb
CHANGED
@@ -76,8 +76,9 @@ module Kristin
|
|
76
76
|
|
77
77
|
def determine_source(source)
|
78
78
|
is_file = File.exists?(source) && !File.directory?(source)
|
79
|
-
is_http =
|
80
|
-
|
79
|
+
is_http = URI(source).scheme == "http"
|
80
|
+
is_https = URI(source).scheme == "https"
|
81
|
+
raise IOError, "Source (#{source}) is neither a file nor an URL." unless is_file || is_http || is_https
|
81
82
|
|
82
83
|
is_file ? source : download_file(source)
|
83
84
|
end
|
data/lib/kristin/version.rb
CHANGED
data/spec/kristin_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'webrick'
|
3
|
-
include WEBrick
|
4
2
|
|
5
3
|
describe Kristin do
|
6
4
|
|
@@ -12,13 +10,6 @@ describe Kristin do
|
|
12
10
|
@target_path = "tmp/kristin"
|
13
11
|
@target_file = @target_path + "/output.html"
|
14
12
|
@fast_opts = { process_outline: false, vdpi: 1, hdpi: 1, first_page: 1, last_page: 1 }
|
15
|
-
dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
16
|
-
port = 50510
|
17
|
-
@url = "http://#{Socket.gethostname}:#{port}"
|
18
|
-
@t1 = Thread.new do
|
19
|
-
@server = HTTPServer.new(:Port => port, :DocumentRoot => dir, :AccessLog => [], :Logger => WEBrick::Log::new("/dev/null", 7))
|
20
|
-
@server.start
|
21
|
-
end
|
22
13
|
end
|
23
14
|
|
24
15
|
before(:each) do
|
@@ -29,10 +20,6 @@ describe Kristin do
|
|
29
20
|
FileUtils.rm_rf @target_path
|
30
21
|
end
|
31
22
|
|
32
|
-
after(:all) do
|
33
|
-
@t1.exit
|
34
|
-
end
|
35
|
-
|
36
23
|
describe "#convert" do
|
37
24
|
describe "with no options" do
|
38
25
|
it "should raise error if source file does not exists" do
|
@@ -55,47 +42,42 @@ describe Kristin do
|
|
55
42
|
end
|
56
43
|
|
57
44
|
it "should convert a pdf from an URL" do
|
58
|
-
|
45
|
+
url = "http://kristin-test.s3.amazonaws.com/one.pdf"
|
46
|
+
Kristin::Converter.new(url, @target_file, @fast_opts).convert
|
59
47
|
File.exists?(@target_file).should == true
|
60
48
|
end
|
61
49
|
|
62
50
|
it "should raise an error if URL does not exist" do
|
63
|
-
|
51
|
+
url = "http://kristin-test.s3.amazonaws.com/image.png"
|
52
|
+
lambda { Kristin::Converter.new(url, @target_file).convert }.should raise_error(IOError)
|
64
53
|
end
|
65
54
|
|
66
55
|
it "should raise an error if URL file is not a real pdf" do
|
67
|
-
|
56
|
+
url = "http://kristin-test.s3.amazonaws.com/image.png"
|
57
|
+
lambda { Kristin::Converter.new(url, @target_file).convert }.should raise_error(IOError)
|
68
58
|
end
|
69
59
|
end
|
70
60
|
|
71
61
|
describe "options" do
|
72
|
-
it "should be possible to disable
|
62
|
+
it "should be possible to disable sidebar" do
|
73
63
|
Kristin::Converter.new(@large_pdf, @target_file, { process_outline: false }).convert
|
74
64
|
doc = Nokogiri::HTML(File.open(@target_file))
|
75
|
-
el = doc.css("#
|
65
|
+
el = doc.css("#sidebar").first
|
76
66
|
el.children.first.text.strip.should be_empty
|
77
67
|
end
|
78
68
|
|
79
69
|
it "should be possible to specify first page" do
|
80
70
|
Kristin::Converter.new(@multi_page_pdf, @target_file, { first_page: 2 }).convert
|
81
71
|
doc = Nokogiri::HTML(File.open(@target_file))
|
82
|
-
#
|
83
|
-
|
84
|
-
# Content only present on page 2
|
85
|
-
content_from_page_2 = doc.search("//span").map(&:content).select {|c| c.include? "Generating functions"}
|
86
|
-
content_from_page_1.should be_empty
|
87
|
-
content_from_page_2.should_not be_empty
|
72
|
+
doc.css("#pf1").should be_empty
|
73
|
+
doc.css("#pf2").should_not be_empty
|
88
74
|
end
|
89
75
|
|
90
76
|
it "should be possible to specify last page" do
|
91
77
|
Kristin::Converter.new(@multi_page_pdf, @target_file, { last_page: 9 }).convert
|
92
78
|
doc = Nokogiri::HTML(File.open(@target_file))
|
93
|
-
#
|
94
|
-
|
95
|
-
# Content only present on page 10
|
96
|
-
content_from_page_10 = doc.search("//span").map(&:content).select {|c| c.include? "William Blake"}
|
97
|
-
content_from_page_1.should_not be_empty
|
98
|
-
content_from_page_10.should be_empty
|
79
|
+
doc.css("#pf1").should_not be_empty
|
80
|
+
doc.css("#pf10").should be_empty
|
99
81
|
end
|
100
82
|
|
101
83
|
it "should be possible to specify hdpi and vdpi" do
|
@@ -113,7 +95,7 @@ describe Kristin do
|
|
113
95
|
it "should be possible to specify fit_width and fit_height" do
|
114
96
|
Kristin::Converter.new(@one_page_pdf, @target_file, { fit_width: 1024, fit_height: 1024 }).convert
|
115
97
|
doc = IO.read(@target_file)
|
116
|
-
doc.should include("1.
|
98
|
+
doc.should include("1.293109")
|
117
99
|
end
|
118
100
|
end
|
119
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kristin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Nyström
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spoon
|