Class: Erubis::Main

### Home Classes Methods

### In Files

- lib/erubis/main.rb

### Parent

Object

### Methods

- ::main
- ::new
- #execute

### Class/Module Index

Quicksearch

- Erubis
- Erubis::ArrayBufferEnhancer
- Erubis::ArrayBufferEruby
- Erubis::ArrayEnhancer
- Erubis::ArrayEruby
- Erubis::Basic
- Erubis::Basic::Converter
- Erubis::Basic::Engine
- Erubis::BiPatternEnhancer
- Erubis::BiPatternEruby
- Erubis::CGenerator
- Erubis::CommandOptionError
- Erubis::Context
- Erubis::Converter
- Erubis::CppGenerator
- Erubis::DeleteIndentEnhancer
- Erubis::DeleteIndentEruby
- Erubis::Ec
- Erubis::Ecpp
- Erubis::Ejava
- Erubis::Ejavascript
- Erubis::Ejs
- Erubis::Engine
- Erubis::Eperl
- Erubis::Ephp
- Erubis::ErboutEnhancer
- Erubis::ErboutEruby
- Erubis::ErubisError
- Erubis::Eruby
- Erubis::EscapeEnhancer
- Erubis::EscapedEc
- Erubis::EscapedEcpp
- Erubis::EscapedEjava
- Erubis::EscapedEjavascript
- Erubis::EscapedEjs
- Erubis::EscapedEperl
- Erubis::EscapedEphp
- Erubis::EscapedEruby
- Erubis::EscapedEscheme
- Erubis::Escheme
- Erubis::Evaluator
- Erubis::FastEruby
- Erubis::Generator
- Erubis::HeaderFooterEnhancer
- Erubis::HeaderFooterEruby
- Erubis::Helpers
- Erubis::Helpers::RailsFormHelper
- Erubis::Helpers::RailsHelper
- Erubis::Helpers::RailsHelper::TemplateConverter
- Erubis::InterpolationEnhancer
- Erubis::InterpolationEruby
- Erubis::JavaGenerator
- Erubis::JavascriptGenerator
- Erubis::Main
- Erubis::NoCodeEnhancer
- Erubis::NoCodeEruby
- Erubis::NoTextEnhancer
- Erubis::NoTextEruby
- Erubis::NotSupportedError
- Erubis::OptimizedEruby
- Erubis::OptimizedGenerator
- Erubis::OptimizedXmlEruby
- Erubis::PI
- Erubis::PI::Converter
- Erubis::PI::Ec
- Erubis::PI::Ecpp
- Erubis::PI::Ejava
- Erubis::PI::Ejavascript
- Erubis::PI::Engine
- Erubis::PI::Eperl
- Erubis::PI::Ephp
- Erubis::PI::Eruby
- Erubis::PI::Escheme
- Erubis::PI::TinyEruby
- Erubis::PercentLineEnhancer
- Erubis::PercentLineEruby
- Erubis::PerlGenerator
- Erubis::PhpGenerator
- Erubis::PrefixedLineEnhancer
- Erubis::PrefixedLineEruby
- Erubis::PreprocessingEruby
- Erubis::PreprocessingHelper
- Erubis::PrintEnabledEnhancer
- Erubis::PrintEnabledEruby
- Erubis::PrintOutEnhancer
- Erubis::PrintOutEruby
- Erubis::PrintOutSimplifiedEruby
- Erubis::RubyEvaluator
- Erubis::RubyGenerator
- Erubis::SchemeGenerator
- Erubis::SimplifiedEruby
- Erubis::SimplifyEnhancer
- Erubis::StdoutEnhancer
- Erubis::StdoutEruby
- Erubis::StdoutSimplifiedEruby
- Erubis::StringBufferEnhancer
- Erubis::StringBufferEruby
- Erubis::StringIOEruby
- Erubis::TinyEruby
- Erubis::XmlEruby
- Erubis::XmlHelper
- ActionView
- ActionView::TemplateHandlers
- ActionView::TemplateHandlers::ErubisHandler
- ERB
- Kernel

No matching classes.

# Erubis::Main

main class of command

ex.

    Main.main(ARGV)

### Public Class Methods

main(argv=ARGV) click to toggle source

    # File lib/erubis/main.rb, line 40
    def self.main(argv=ARGV)
      status = 0
      begin
        Main.new.execute(ARGV)
      rescue CommandOptionError => ex
        $stderr.puts ex.message
        status = 1
      end
      exit(status)
    end

new() click to toggle source

    # File lib/erubis/main.rb, line 51
    def initialize
      @single_options = "hvxztTSbeBXNUC"
      @arg_options    = "pcrfKIlaE" #C
      @option_names   = {
        'h' => :help,
        'v' => :version,
        'x' => :source,
        'z' => :syntax,
        'T' => :unexpand,
        't' => :untabify,      # obsolete
        'S' => :intern,
        'b' => :bodyonly,
        'B' => :binding,
        'p' => :pattern,
        'c' => :context,
        #'C' => :class,
        'e' => :escape,
        'r' => :requires,
        'f' => :datafiles,
        'K' => :kanji,
        'I' => :includes,
        'l' => :lang,
        'a' => :action,
        'E' => :enhancers,
        'X' => :notext,
        'N' => :linenum,
        'U' => :unique,
        'C' => :compact,
      }
      assert unless @single_options.length + @arg_options.length == @option_names.length
      (@single_options + @arg_options).each_byte do |ch|
        assert unless @option_names.key?(ch.chr)
      end
    end

### Public Instance Methods

execute(argv=ARGV) click to toggle source

    # File lib/erubis/main.rb, line 87
    def execute(argv=ARGV)
      ## parse command-line options
      options, properties = parse_argv(argv, @single_options, @arg_options)
      filenames = argv
      options['h'] = true if properties[:help]
      opts = Object.new
      arr = @option_names.collect {|ch, name| "def #{name}; @#{name}; end\n" }
      opts.instance_eval arr.join
      options.each do |ch, val|
        name = @option_names[ch]
        opts.instance_variable_set("@#{name}", val)
      end

      ## help, version, enhancer list
      if opts.help || opts.version
        puts version()         if opts.version
        puts usage()           if opts.help
        puts show_properties() if opts.help
        puts show_enhancers()  if opts.help
        return
      end

      ## include path
      opts.includes.split(/,/).each do |path|
        $: << path
      end if opts.includes

      ## require library
      opts.requires.split(/,/).each do |library|
        require library
      end if opts.requires

      ## action
      action = opts.action
      action ||= 'syntax'  if opts.syntax
      action ||= 'convert' if opts.source || opts.notext

      ## lang
      lang = opts.lang || 'ruby'
      action ||= 'convert' if opts.lang

      ## class name of Eruby
      #classname = opts.class
      classname = nil
      klass = get_classobj(classname, lang, properties[:pi])

      ## kanji code
      $KCODE = opts.kanji if opts.kanji

      ## read context values from yaml file
      datafiles = opts.datafiles
      context = load_datafiles(datafiles, opts)

      ## parse context data
      if opts.context
        context = parse_context_data(opts.context, opts)
      end

      ## properties for engine
      properties[:escape]   = true         if opts.escape && !properties.key?(:escape)
      properties[:pattern]  = opts.pattern if opts.pattern
      #properties[:trim]     = false        if opts.notrim
      properties[:preamble] = properties[:postamble] = false if opts.bodyonly
      properties[:pi]       = nil          if properties[:pi] == true

      ## create engine and extend enhancers
      engine = klass.new(nil, properties)
      enhancers = get_enhancers(opts.enhancers)
      #enhancers.push(Erubis::EscapeEnhancer) if opts.escape
      enhancers.each do |enhancer|
        engine.extend(enhancer)
        engine.bipattern = properties[:bipattern] if enhancer == Erubis::BiPatternEnhancer
      end

      ## no-text
      engine.extend(Erubis::NoTextEnhancer) if opts.notext

      ## convert and execute
      val = nil
      msg = "Syntax OK\n"
      if filenames && !filenames.empty?
        filenames.each do |filename|
          File.file?(filename)  or
            raise CommandOptionError.new("#{filename}: file not found.")
          engine.filename = filename
          engine.convert!(File.read(filename))
          val = do_action(action, engine, context, filename, opts)
          msg = nil if val
        end
      else
        engine.filename = filename = '(stdin)'
        engine.convert!($stdin.read())
        val = do_action(action, engine, context, filename, opts)
        msg = nil if val
      end
      print msg if action == 'syntax' && msg

    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.