Module: Erubis::PrefixedLineEnhancer

### Home Classes Methods

### In Files

- lib/erubis/enhancer.rb

### Methods

- #add_text
- #init_generator

### 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::PrefixedLineEnhancer

regards lines starting with '^[ t]*%' as program code

in addition you can specify prefix character (default '%')

this is language-independent.

### Public Instance Methods

add_text(src, text) click to toggle source

    # File lib/erubis/enhancer.rb, line 454
    def add_text(src, text)
      unless @prefixrexp
        @prefixchar ||= '%'
        @prefixrexp = Regexp.compile("^([ \\t]*)\\#{@prefixchar}(.*?\\r?\\n)")
      end
      pos = 0
      text2 = ''
      text.scan(@prefixrexp) do
        space = $1
        line  = $2
        space, line = '', $1 unless $2
        match = Regexp.last_match
        len   = match.begin(0) - pos
        str   = text[pos, len]
        pos   = match.end(0)
        if text2.empty?
          text2 = str
        else
          text2 << str
        end
        if line[0, 1] == @prefixchar
          text2 << space << line
        else
          super(src, text2)
          text2 = ''
          add_stmt(src, space + line)
        end
      end
      #rest = pos == 0 ? text : $'             # ruby1.8
      rest = pos == 0 ? text : text[pos..-1]   # ruby1.9
      unless text2.empty?
        text2 << rest if rest
        rest = text2
      end
      super(src, rest)
    end

init_generator(properties={}) click to toggle source

    # File lib/erubis/enhancer.rb, line 449
    def init_generator(properties={})
      super
      @prefixchar = properties[:prefixchar]
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.