Parent

Class/Module Index [+]

Quicksearch

RGen::TemplateLanguage::OutputHandler

Attributes

indent[W]
noIndentNextLine[RW]

Public Class Methods

new(indent=0, indentString=" ", mode=:explicit) click to toggle source
# File lib/rgen/template_language/output_handler.rb, line 12
def initialize(indent=0, indentString="   ", mode=:explicit)
  self.mode = mode
  @indent = indent
  @indentString = indentString
  @state = :wait_for_nonws
  @output = ""
end

Public Instance Methods

<<(s) click to toggle source
Alias for: concat
concat(s) click to toggle source

ERB will call this method for every string s which is part of the template file in between %> and <%. If s contains a newline, it will call this method for every part of s which is terminated by a n

# File lib/rgen/template_language/output_handler.rb, line 24
def concat(s)
  return @output.concat(s) if s.is_a? OutputHandler
  #puts [object_id, noIndentNextLine, @state, @output.to_s, s].inspect
  s = s.to_str.gsub(/^[\t ]*\r?\n/,'') if @ignoreNextNL
  s = s.to_str.gsub(/^\s+/,'') if @ignoreNextWS
  @ignoreNextNL = @ignoreNextWS = false if s =~ /\S/
  if @mode == :direct
    @output.concat(s)
  elsif @mode == :explicit
    while s.size > 0
      if @state == :wait_for_nl
        if s =~ /\A([^\r\n]*\r?\n)(.*)/
          rest = $2
          @output.concat($1.gsub(/[\t ]+(?=\r|\n)/,''))
          s = rest || ""
          @state = :wait_for_nonws
        else
          @output.concat(s)
          s = ""
        end
      elsif @state == :wait_for_nonws
        if s =~ /\A\s*(\S+.*)/
          s = $1 || ""
          if !@noIndentNextLine && !(@output.to_s.size > 0 && @output.to_s[-1] != "\n"[0])
            @output.concat(@indentString * @indent)
          else
            @noIndentNextLine = false
          end
          @state = :wait_for_nl
        else
          s = ""
        end
      end
    end
  end
end
Also aliased as: <<
direct_concat(s) click to toggle source
# File lib/rgen/template_language/output_handler.rb, line 67
def direct_concat(s)
  @output.concat(s)
end
ignoreNextNL() click to toggle source
# File lib/rgen/template_language/output_handler.rb, line 71
def ignoreNextNL
  @ignoreNextNL = true
end
ignoreNextWS() click to toggle source
# File lib/rgen/template_language/output_handler.rb, line 75
def ignoreNextWS
  @ignoreNextWS = true
end
mode=(m) click to toggle source
# File lib/rgen/template_language/output_handler.rb, line 79
def mode=(m)
  raise StandardError.new("Unknown mode: #{m}") unless [:direct, :explicit].include?(m)
  @mode = m
end
to_s() click to toggle source
Alias for: to_str
to_str() click to toggle source
# File lib/rgen/template_language/output_handler.rb, line 62
def to_str
  @output
end
Also aliased as: to_s

[Validate]

Generated with the Darkfish Rdoc Generator 2.