dauphin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.idea/dauphin.iml +56 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +23 -0
- data/.idea/modules.xml +9 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +56 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/dauphin.gemspec +24 -0
- data/lib/dauphin.rb +32 -0
- data/lib/dauphin/logging.rb +16 -0
- data/lib/dauphin/pdf.rb +87 -0
- data/lib/dauphin/platform.rb +31 -0
- data/lib/dauphin/runtime.rb +33 -0
- data/lib/dauphin/stdout_logger.rb +7 -0
- data/lib/dauphin/version.rb +3 -0
- data/spec/dauphin/pdf_spec.rb +60 -0
- data/spec/dauphin_spec.rb +6 -0
- data/spec/spec_helper.rb +9 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDllZmIwODVjNWY2NDNhMTY2YzU3MTUxYWZjOGRmMWY3MzU0NzU3NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDYxMGY3M2Y5NmI0YmM1MjExMmMzODhlOGJhMDYyNzFhOTBlODkzZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDVkNGJiNTY2OGFlNDRiOGEwYjJhOTFhYmNiOWQ2ZGY5NjFhOGI2ODQ4MTk1
|
10
|
+
MmE3MzkyNmM4MTE4NGQwZGI2NWUxZTExY2ZkYjVmMTM5MTE1MTI1YWIyOTgx
|
11
|
+
OTYwMzI0NThhMjBjNWUyOWQ2ZjA4OTFlMjlmMWEwNmYyMGNmNDE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OGQ1YTIyODNkNzYwMDQ4NzI0YWZmZDlkMmZkYzlkM2Y2NTBhNjYxNDM2MGEx
|
14
|
+
NjZjYzQ3M2E0ZTVkOTQwODQ5NzczMDBhODA1NzY1MTE3NjEzOTJhMDQ2YWEw
|
15
|
+
ZWE3MmQzZWFkM2M4ZGJmMDY1MjQ5ZGMyZDk4MDlkNTg0YjQzMWM=
|
data/.gitignore
ADDED
data/.idea/dauphin.iml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="ModuleRunConfigurationManager">
|
13
|
+
<configuration default="false" name="Dauphin::Pdf logger defaults to STDOUT: dauphin" type="RSpecRunConfigurationType" factoryName="RSpec" temporary="true">
|
14
|
+
<predefined_log_file id="RUBY_RSPEC" enabled="true" />
|
15
|
+
<module name="dauphin" />
|
16
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
17
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
18
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
|
19
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
|
20
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
|
21
|
+
<envs>
|
22
|
+
<env name="JRUBY_OPTS" value="-X+O" />
|
23
|
+
</envs>
|
24
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
25
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
26
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov">
|
27
|
+
<COVERAGE_PATTERN ENABLED="true">
|
28
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
29
|
+
</COVERAGE_PATTERN>
|
30
|
+
</EXTENSION>
|
31
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
32
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TESTS_FOLDER_PATH" VALUE="" />
|
33
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_SCRIPT_PATH" VALUE="$MODULE_DIR$/spec/dauphin/pdf_spec.rb" />
|
34
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_RUNNER_PATH" VALUE="" />
|
35
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_FILE_MASK" VALUE="**/*_spec.rb" />
|
36
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_EXAMPLE_NAME" VALUE="Dauphin::Pdf logger defaults to STDOUT" />
|
37
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="TEST_TEST_TYPE" VALUE="TEST_SCRIPT" />
|
38
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="SPEC_ARGS" VALUE="" />
|
39
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="RUNNER_VERSION" VALUE="" />
|
40
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="USE_CUSTOM_SPEC_RUNNER" VALUE="false" />
|
41
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="DRB" VALUE="false" />
|
42
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="ZEUS" VALUE="false" />
|
43
|
+
<RSPEC_RUN_CONFIG_SETTINGS_ID NAME="FULL_BACKTRACE" VALUE="false" />
|
44
|
+
<RunnerSettings RunnerId="RubyDebugRunner" />
|
45
|
+
<ConfigurationWrapper RunnerId="RubyDebugRunner" />
|
46
|
+
<method />
|
47
|
+
</configuration>
|
48
|
+
</component>
|
49
|
+
<component name="NewModuleRootManager">
|
50
|
+
<content url="file://$MODULE_DIR$" />
|
51
|
+
<orderEntry type="jdk" jdkName="RVM: ruby-1.9.3-p545" jdkType="RUBY_SDK" />
|
52
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
53
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v0.9.2.2, RVM: ruby-1.9.3-p545) [gem]" level="application" />
|
54
|
+
</component>
|
55
|
+
</module>
|
56
|
+
|
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectDictionaryState">
|
4
|
+
<dictionary name="lambdasix" />
|
5
|
+
</component>
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.1-p431" project-jdk-type="RUBY_SDK" />
|
7
|
+
<component name="masterDetails">
|
8
|
+
<states>
|
9
|
+
<state key="ScopeChooserConfigurable.UI">
|
10
|
+
<settings>
|
11
|
+
<splitter-proportions>
|
12
|
+
<option name="proportions">
|
13
|
+
<list>
|
14
|
+
<option value="0.2" />
|
15
|
+
</list>
|
16
|
+
</option>
|
17
|
+
</splitter-proportions>
|
18
|
+
</settings>
|
19
|
+
</state>
|
20
|
+
</states>
|
21
|
+
</component>
|
22
|
+
</project>
|
23
|
+
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/dauphin.iml" filepath="$PROJECT_DIR$/.idea/dauphin.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
9
|
+
|
data/.idea/vcs.xml
ADDED
data/.idea/workspace.xml
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ChangeListManager">
|
4
|
+
<option name="TRACKING_ENABLED" value="true" />
|
5
|
+
<option name="SHOW_DIALOG" value="false" />
|
6
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
7
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
8
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
9
|
+
</component>
|
10
|
+
<component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
|
11
|
+
<component name="CreatePatchCommitExecutor">
|
12
|
+
<option name="PATCH_PATH" value="" />
|
13
|
+
</component>
|
14
|
+
<component name="DaemonCodeAnalyzer">
|
15
|
+
<disable_hints />
|
16
|
+
</component>
|
17
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
18
|
+
<OptionsSetting value="true" id="Add" />
|
19
|
+
<OptionsSetting value="true" id="Remove" />
|
20
|
+
<OptionsSetting value="true" id="Checkout" />
|
21
|
+
<OptionsSetting value="true" id="Update" />
|
22
|
+
<OptionsSetting value="true" id="Status" />
|
23
|
+
<OptionsSetting value="true" id="Edit" />
|
24
|
+
<ConfirmationsSetting value="0" id="Add" />
|
25
|
+
<ConfirmationsSetting value="0" id="Remove" />
|
26
|
+
</component>
|
27
|
+
<component name="ProjectReloadState">
|
28
|
+
<option name="STATE" value="0" />
|
29
|
+
</component>
|
30
|
+
<component name="PropertiesComponent">
|
31
|
+
<property name="options.lastSelected" value="preferences.sourceCode.Yaml" />
|
32
|
+
<property name="options.splitter.main.proportions" value="0.3" />
|
33
|
+
<property name="options.splitter.details.proportions" value="0.2" />
|
34
|
+
<property name="options.searchVisible" value="true" />
|
35
|
+
</component>
|
36
|
+
<component name="RunManager">
|
37
|
+
<list size="0" />
|
38
|
+
</component>
|
39
|
+
<component name="ShelveChangesManager" show_recycled="false" />
|
40
|
+
<component name="TaskManager">
|
41
|
+
<task active="true" id="Default" summary="Default task" />
|
42
|
+
<servers />
|
43
|
+
</component>
|
44
|
+
<component name="VcsContentAnnotationSettings">
|
45
|
+
<option name="myLimit" value="2678400000" />
|
46
|
+
</component>
|
47
|
+
<component name="VcsManagerConfiguration">
|
48
|
+
<option name="myTodoPanelSettings">
|
49
|
+
<TodoPanelSettings />
|
50
|
+
</option>
|
51
|
+
</component>
|
52
|
+
<component name="XDebuggerManager">
|
53
|
+
<breakpoint-manager />
|
54
|
+
</component>
|
55
|
+
</project>
|
56
|
+
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 LambdaSix
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Dauphin
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'dauphin'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install dauphin
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/dauphin/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/dauphin.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dauphin/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'dauphin'
|
8
|
+
spec.version = Dauphin::VERSION
|
9
|
+
spec.authors = ['LambdaSix']
|
10
|
+
spec.email = ['alexander.somerville.cox@gmail.com']
|
11
|
+
spec.summary = 'Library for accessing the Prince XML 9 command line tool'
|
12
|
+
spec.description = 'Provides a nice wrapper around the command line tool invocation'
|
13
|
+
spec.homepage = 'http://github.com/LambdaSix/dauphin'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.5'
|
22
|
+
spec.add_development_dependency 'rspec', '~> 2', '>= 2.14.1'
|
23
|
+
spec.add_development_dependency 'rake'
|
24
|
+
end
|
data/lib/dauphin.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Prince 9 Ruby interface
|
2
|
+
# http://princexml.com
|
3
|
+
#
|
4
|
+
# USAGE
|
5
|
+
# --
|
6
|
+
# dauphin = Dauphin.new
|
7
|
+
# pdf = dauphin.mkpdf_stream(html) # pdf is now PDF data
|
8
|
+
|
9
|
+
require 'dauphin/version'
|
10
|
+
require 'logger'
|
11
|
+
require 'pathname'
|
12
|
+
|
13
|
+
module Dauphin
|
14
|
+
autoload :StdoutLogger, 'dauphin/stdout_logger'
|
15
|
+
autoload :Pdf, 'dauphin/pdf'
|
16
|
+
autoload :Logging, 'dauphin/logging'
|
17
|
+
autoload :Runtime, 'dauphin/runtime'
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def runtime
|
21
|
+
@default_runtime || Dauphin::Runtime.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def runtime=(custom_exe)
|
25
|
+
@default_runtime = custom_exe
|
26
|
+
end
|
27
|
+
|
28
|
+
def root
|
29
|
+
Pathname.new(File.expand_path('../', __FILE__))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/dauphin/pdf.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
module Dauphin
|
2
|
+
class Pdf
|
3
|
+
attr_accessor :executable, :stylesheets, :logger, :log_file
|
4
|
+
|
5
|
+
def initialize(opt={})
|
6
|
+
options = {
|
7
|
+
:path => nil,
|
8
|
+
:executable => Dauphin.runtime,
|
9
|
+
:log_file => nil,
|
10
|
+
:logger => nil
|
11
|
+
}.merge(opt)
|
12
|
+
|
13
|
+
@executable = options[:path] ? Dauphin::Runtime.new(options[:path]) : options[:executable]
|
14
|
+
@stylesheets = ''
|
15
|
+
@log_file = options[:log_file]
|
16
|
+
@logger = options[:logger]
|
17
|
+
end
|
18
|
+
|
19
|
+
def logger
|
20
|
+
@logger || Dauphin::Logging.logger
|
21
|
+
end
|
22
|
+
|
23
|
+
def log_file
|
24
|
+
@log_file || Dauphin::Logging.file
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_style_sheet(*sheets)
|
28
|
+
@stylesheets << sheets.map { |sheet| " -s #{sheet} " }.join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
def exe
|
32
|
+
@executable.join(executable_options)
|
33
|
+
puts "@executable: #{@executable.inspect}"
|
34
|
+
@executable.join(executable_options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def executable_options
|
38
|
+
options = []
|
39
|
+
options << "--input=html"
|
40
|
+
options << "--log=#{log_file}"
|
41
|
+
options << @stylesheets
|
42
|
+
options
|
43
|
+
end
|
44
|
+
|
45
|
+
def mkpdf_stream(string, output_file = '-')
|
46
|
+
pdf = create_pdf string, output_file, {:output_to_log_file => false}
|
47
|
+
pdf.close_write
|
48
|
+
|
49
|
+
result = pdf.gets
|
50
|
+
pdf.close_read
|
51
|
+
|
52
|
+
result.force_encoding(Encoding::BINARY) if RUBY_VERSION >= '1.9'
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
def mkpdf_file(string, output_file)
|
57
|
+
pdf = create_pdf string, output_file
|
58
|
+
pdf.close
|
59
|
+
end
|
60
|
+
|
61
|
+
protected
|
62
|
+
def create_pdf(string, output_file, opt={})
|
63
|
+
options = {
|
64
|
+
:log_command => true,
|
65
|
+
:output_log => true
|
66
|
+
}.merge(opt)
|
67
|
+
|
68
|
+
path = exe
|
69
|
+
|
70
|
+
path << " --silent - -o #{output_file}"
|
71
|
+
path << " >> '#{log_file}' 2>> '#{log_file}'" if options[:output_to_log_file]
|
72
|
+
puts "Path: #{path.inspect}"
|
73
|
+
|
74
|
+
log path if options[:log_command]
|
75
|
+
|
76
|
+
pdf = IO.popen(path, 'w+')
|
77
|
+
pdf.puts string
|
78
|
+
pdf
|
79
|
+
end
|
80
|
+
|
81
|
+
def log(path)
|
82
|
+
logger.info "\n\nPRINCE PDF:"
|
83
|
+
logger.info path
|
84
|
+
logger.info ''
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
module Dauphin
|
4
|
+
class Platform
|
5
|
+
def self.os
|
6
|
+
@os ||= (
|
7
|
+
host_os = RbConfig::CONFIG['host_os']
|
8
|
+
case host_os
|
9
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
10
|
+
:windows
|
11
|
+
when /darwin|mac os/
|
12
|
+
:macosx
|
13
|
+
when /linux/
|
14
|
+
:linux
|
15
|
+
when /solaris|bsd/
|
16
|
+
:unix
|
17
|
+
else
|
18
|
+
raise Exception, "Unknown OS: #{host_os.inspect}"
|
19
|
+
end
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.windows?
|
24
|
+
os == :windows
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.linux?
|
28
|
+
os == :linux
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'platform'
|
2
|
+
|
3
|
+
module Dauphin
|
4
|
+
class Runtime
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
def initialize(exepath=nil)
|
8
|
+
puts "Making new Runtime(#{self.inspect}), path: #{exepath.inspect}"
|
9
|
+
@path = exepath || default_executable_path
|
10
|
+
puts "default_executable_path: #{path}"
|
11
|
+
puts "Path: #{@path}"
|
12
|
+
check_for_binary
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_for_binary
|
16
|
+
raise 'Cannot find prince command-line app in $PATH' if !path || path.length == 0
|
17
|
+
raise "Cannot run executable at #{path}" unless File.executable? path
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_executable_path
|
21
|
+
if Platform.windows?
|
22
|
+
return 'C:/Program Files/Prince/Engine/bin/prince'
|
23
|
+
end
|
24
|
+
if Platform.linux?
|
25
|
+
`which prince`.chomp
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def join(options)
|
30
|
+
([@path] + Array(options)).join(' ')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dauphin::Pdf do
|
4
|
+
let(:html_doc) { '<html><body>Hello World</body></html>'}
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
Dauphin::Runtime.any_instance.stub(:check_for_binary).and_return(true)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'generates a PDF from HTML' do
|
11
|
+
dauphin = Dauphin::Pdf.new
|
12
|
+
pdf = dauphin.mkpdf_stream(html_doc) rescue Errno::ENOENT
|
13
|
+
fail "You likely don't have prince installed"
|
14
|
+
pdf.should start_with('%PDF-1.4')
|
15
|
+
pdf.rstrip.should end_with('%%EOF')
|
16
|
+
pdf.length > 100
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'logger' do
|
20
|
+
it 'defaults to STDOUT' do
|
21
|
+
dauphin = Dauphin::Pdf.new
|
22
|
+
dauphin.logger.should == Dauphin::StdoutLogger
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'can be set' do
|
26
|
+
LoggerClass = Class.new
|
27
|
+
dauphin = Dauphin::Pdf.new(:logger => LoggerClass.new)
|
28
|
+
dauphin.logger.should be_an_instance_of LoggerClass
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'log_file' do
|
33
|
+
it 'defaults to a known path' do
|
34
|
+
Dauphin::Logging.file = nil
|
35
|
+
|
36
|
+
path = Pathname.new 'log_path'
|
37
|
+
Dauphin.should_receive(:root).and_return(path)
|
38
|
+
dauphin = Dauphin::Pdf.new
|
39
|
+
|
40
|
+
dauphin.log_file.should == path.join('log/prince.log')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'exe_path' do
|
45
|
+
let(:dauphin) { Dauphin::Pdf.new(:path => '/bin/true') }
|
46
|
+
|
47
|
+
before :each do
|
48
|
+
dauphin.stub(:log_file).and_return('/tmp/test_log')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'appends default options' do
|
52
|
+
dauphin.exe.should == '/bin/true --input=html --log=/tmp/test_log '
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'adds stylesheet paths' do
|
56
|
+
dauphin.stylesheets = ' -s test.css '
|
57
|
+
dauphin.exe.should == '/bin/true --input=html --log=/tmp/test_log -s test.css '
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dauphin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- LambdaSix
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2'
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.14.1
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2'
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.14.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
description: Provides a nice wrapper around the command line tool invocation
|
62
|
+
email:
|
63
|
+
- alexander.somerville.cox@gmail.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- .idea/dauphin.iml
|
70
|
+
- .idea/encodings.xml
|
71
|
+
- .idea/misc.xml
|
72
|
+
- .idea/modules.xml
|
73
|
+
- .idea/scopes/scope_settings.xml
|
74
|
+
- .idea/vcs.xml
|
75
|
+
- .idea/workspace.xml
|
76
|
+
- Gemfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- dauphin.gemspec
|
81
|
+
- lib/dauphin.rb
|
82
|
+
- lib/dauphin/logging.rb
|
83
|
+
- lib/dauphin/pdf.rb
|
84
|
+
- lib/dauphin/platform.rb
|
85
|
+
- lib/dauphin/runtime.rb
|
86
|
+
- lib/dauphin/stdout_logger.rb
|
87
|
+
- lib/dauphin/version.rb
|
88
|
+
- spec/dauphin/pdf_spec.rb
|
89
|
+
- spec/dauphin_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: http://github.com/LambdaSix/dauphin
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Library for accessing the Prince XML 9 command line tool
|
115
|
+
test_files:
|
116
|
+
- spec/dauphin/pdf_spec.rb
|
117
|
+
- spec/dauphin_spec.rb
|
118
|
+
- spec/spec_helper.rb
|