Class: PanHandler
- Inherits:
-
Object
- Object
- PanHandler
- Defined in:
- lib/pan_handler/source.rb,
lib/pan_handler/version.rb,
lib/pan_handler/middleware.rb,
lib/pan_handler/pan_handler.rb,
lib/pan_handler/configuration.rb
Defined Under Namespace
Classes: Configuration, ImproperSourceError, Middleware, NoExecutableError, Source
Constant Summary collapse
- VERSION =
"0.0.2"
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #command(path = nil) ⇒ Object
- #executable ⇒ Object
-
#initialize(url_file_or_html, options = {}) ⇒ PanHandler
constructor
A new instance of PanHandler.
- #to_file(path) ⇒ Object
- #to_odt(path = nil) ⇒ Object
Constructor Details
#initialize(url_file_or_html, options = {}) ⇒ PanHandler
Returns a new instance of PanHandler.
22 23 24 25 26 27 28 |
# File 'lib/pan_handler/pan_handler.rb', line 22 def initialize(url_file_or_html, = {}) @source = Source.new(url_file_or_html) = PanHandler.configuration..merge() = () raise NoExecutableError.new unless File.exists?(PanHandler.configuration.pandoc) end |
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
20 21 22 |
# File 'lib/pan_handler/configuration.rb', line 20 def configuration @configuration end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/pan_handler/pan_handler.rb', line 20 def end |
#source ⇒ Object
Returns the value of attribute source.
19 20 21 |
# File 'lib/pan_handler/pan_handler.rb', line 19 def source @source end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
27 28 29 |
# File 'lib/pan_handler/configuration.rb', line 27 def self.configure yield(configuration) end |
Instance Method Details
#command(path = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/pan_handler/pan_handler.rb', line 30 def command(path = nil) args = [executable] args += .to_a.flatten.compact args << '--output' args << (path || '-') # Write to file or stdout unless @source.html? args << @source.to_s end args.map {|arg| %Q{"#{arg.gsub('"', '\"')}"}} end |
#executable ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/pan_handler/pan_handler.rb', line 44 def executable default = PanHandler.configuration.pandoc return default if default !~ /^\// # its not a path, so nothing we can do if File.exist?(default) default else default.split('/').last end end |
#to_file(path) ⇒ Object
74 75 76 77 |
# File 'lib/pan_handler/pan_handler.rb', line 74 def to_file(path) self.to_odt(path) File.new(path) end |
#to_odt(path = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pan_handler/pan_handler.rb', line 54 def to_odt(path=nil) if path.nil? tempfile = Tempfile.new('panhandler') path = tempfile.path end args = command(path) invoke = args.join(' ') result = IO.popen(invoke, "wb+") do |odt| odt.puts(@source.to_s) if @source.html? odt.close_write odt.gets(nil) end result = File.read(path) if path tempfile.unlink if tempfile raise "command failed: #{invoke}" if result.empty? return result end |