Module: Propaganda
- Defined in:
- lib/propaganda.rb,
lib/propaganda/renderer.rb,
lib/propaganda/fop/shell.rb,
lib/propaganda/formatter.rb,
lib/propaganda/fop/bridge.rb
Defined Under Namespace
Modules: Fop Classes: Formatter, Renderer
Constant Summary collapse
- MODE =
check_dependencies ? 'rjb' : 'shell'
Class Method Summary collapse
- .check_dependencies ⇒ Object
- .convert(input, output, title = nil, template = nil, engine = nil, format = nil, verbose = false) ⇒ Object
- .detect(input) ⇒ Object
Class Method Details
.check_dependencies ⇒ Object
5 6 7 8 9 10 |
# File 'lib/propaganda/renderer.rb', line 5 def self.check_dependencies require 'propaganda/fop/shell' require 'propaganda/fop/bridge' rescue LoadError => e false end |
.convert(input, output, title = nil, template = nil, engine = nil, format = nil, verbose = false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/propaganda.rb', line 5 def self.convert(input, output, title=nil, template=nil, engine=nil, format=nil, verbose=false) title ||= File.basename(input, File.extname(input)) engine ||= detect(input) format ||= 'pdf' text = IO.read(input) formatter = Formatter.new text = formatter.format(text, title, engine) return !File.open(output, 'w') {|f| f.write(text) }.nil? if format == 'html' fop = Renderer.new(verbose) fop.render(text, output, template) end |
.detect(input) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/propaganda.rb', line 17 def self.detect(input) case File.extname(input) when '.textile' 'textile' when '.markdown', '.md' 'markdown' when '.html', '.xhtml' 'none' else raise "Unknown format for #{input}, use .html, .textile or .markdown extension" end end |