Class: Guard::Gimli::Converter
- Inherits:
-
Object
- Object
- Guard::Gimli::Converter
- Defined in:
- lib/guard/gimli/converter.rb
Instance Attribute Summary collapse
-
#stylesheet ⇒ Object
readonly
Returns the value of attribute stylesheet.
Instance Method Summary collapse
- #base_dir(path) ⇒ Object
- #command(path) ⇒ Object
- #escape(path) ⇒ Object
- #filename(path) ⇒ Object
-
#initialize(options) ⇒ Converter
constructor
A new instance of Converter.
- #outputdir(path) ⇒ Object
- #outputinfo(path) ⇒ Object
- #reload(paths = []) ⇒ Object
Constructor Details
#initialize(options) ⇒ Converter
Returns a new instance of Converter.
7 8 9 10 |
# File 'lib/guard/gimli/converter.rb', line 7 def initialize() @outputdir = [:outputdir] @stylesheet = [:stylesheet] end |
Instance Attribute Details
#stylesheet ⇒ Object (readonly)
Returns the value of attribute stylesheet.
5 6 7 |
# File 'lib/guard/gimli/converter.rb', line 5 def stylesheet @stylesheet end |
Instance Method Details
#base_dir(path) ⇒ Object
49 50 51 52 |
# File 'lib/guard/gimli/converter.rb', line 49 def base_dir(path) dir = File.dirname path dir unless dir == '.' end |
#command(path) ⇒ Object
21 22 23 24 25 |
# File 'lib/guard/gimli/converter.rb', line 21 def command(path) command = "gimli -f #{escape(path)}" command += outputdir(escape(path)).nil? ? '' : " -o #{outputdir(escape(path))}" command += stylesheet.nil? ? '' : " -s #{stylesheet}" end |
#escape(path) ⇒ Object
54 55 56 |
# File 'lib/guard/gimli/converter.rb', line 54 def escape(path) path.gsub(' ', '\ ') end |
#filename(path) ⇒ Object
45 46 47 |
# File 'lib/guard/gimli/converter.rb', line 45 def filename(path) File.basename(path).gsub(/\..+$/, '') end |
#outputdir(path) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/guard/gimli/converter.rb', line 27 def outputdir(path) if @outputdir.nil? base_dir path else if base_dir(path).nil? @outputdir else File.join(base_dir(path), @outputdir) end end end |
#outputinfo(path) ⇒ Object
39 40 41 42 43 |
# File 'lib/guard/gimli/converter.rb', line 39 def outputinfo(path) info = outputdir(path) info += '/' unless info.nil? info = info.to_s + "#{filename(path)}.pdf" end |
#reload(paths = []) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/guard/gimli/converter.rb', line 12 def reload(paths = []) UI.info "Building pdfs for #{paths.join(' ')}" start_at = Time.now paths.each do |path| system(command(path)) UI.info "#{outputinfo(path)} built" end end |