lib/rbst.rb in RbST-0.4.0 vs lib/rbst.rb in RbST-0.5.1

- old
+ new

@@ -1,26 +1,31 @@ # encoding: UTF-8 class RbST - - @@executable_path = File.expand_path(File.join(File.dirname(__FILE__), "rst2parts")) + @@python_path="python" + @@executable_path = File.expand_path( + File.join(File.dirname(__FILE__), "rst2parts") + ) @@executables = { :html => File.join(@@executable_path, "rst2html.py"), :latex => File.join(@@executable_path, "rst2latex.py") } - - # Takes a string or file path plus any additional options and converts the input. + + # Takes a string or file path plus any additional options and converts the + # input. def self.convert(*args) new(*args).convert end - # Print LaTeX-Specific Options, General Docutils Options and reStructuredText Parser Options. + # Print LaTeX-Specific Options, General Docutils Options and reStructuredText + # Parser Options. def self.latex_options new.print_options(:latex) end - # Print HTML-Specific Options, General Docutils Options and reStructuredText Parser Options. + # Print HTML-Specific Options, General Docutils Options and reStructuredText + # Parser Options. def self.html_options new.print_options(:html) end # Specify custom executables to use instead of the default rst2latex.py and @@ -33,20 +38,31 @@ @@executables = @@executables.merge(exec_paths) end # Return the executable hash. def self.executables; @@executables end - # Takes a string or file path plus any additional options and creates a new converter object. + # Specify a python path or executable. + def self.python_path=(path_to_python) + @@python_path = path_to_python + end + # Return the python path. + def self.python_path; @@python_path end + + # Takes a string or file path plus any additional options and creates a new + # converter object. def initialize(*args) target = args.shift @target = File.exists?(target) ? File.read(target) : target rescue target @options = args end def convert # :nodoc: @output_format ||= :html - execute "python #{@@executables[@output_format]}" + convert_options + execute( + "#{@@python_path} #{@@executables[@output_format]}" + + convert_options + ) end alias_method :to_s, :convert # Converts the object's input to HTML. def to_html(*args) @@ -60,22 +76,24 @@ @output_format = :latex @options += args convert end - # Formats and prints the options from the docutils help in the way they'd be specified in RbST: strings, symbols and hashes. + # Formats and prints the options from the docutils help in the way they'd be + # specified in RbST: strings, symbols and hashes. def print_options(format) - help = execute("python #{@@executables[format]} --help") - # non-hyphenated long options to symbols + help = execute("#{@@python_path} #{@@executables[format]} --help") + # Convert non-hyphenated long options to symbols help.gsub!(/(\-\-)([A-Za-z0-9]+)([=|\s])/, ':\2\3') - # hyphenated long options to quoted strings + # Convert hyphenated long options to quoted strings help.gsub!(/(\-\-)([\w|\-]+)(\n)?[^$|^=|\]]?/, '\'\2\'\3') - # equal to hashrocket + # Convert equal signs to hashrocket help.gsub!(/\=/, ' => ') - # hort options to symbols + # Convert short options to symbols help.gsub!(/([^\w])\-(\w)([^\w])/, '\1:\2\1') - # short options with args get a hashrocket + # Convert short options with args get a hashrocket help.gsub!(/(:\w) </, '\1 => <') + # Print converted help text puts help end protected