Class: Flott::Parser::State

Inherits:
Object
  • Object
show all
Defined in:
lib/flott.rb

Overview

This class encapsulates the state, that is shared by all parsers that were activated during the parse phase.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeState

Creates a new Flott::Parser::State instance to hold the current parser state.



545
546
547
548
549
550
551
552
553
# File 'lib/flott.rb', line 545

def initialize
  @opened       = 0
  @last_open    = nil
  @text         = []
  @compiled     = []
  @pathes       = []
  @directories  = []
  @skip_cr      = false
end

Instance Attribute Details

#compiledObject (readonly)

An array of the already compiled Ruby code fragments.



565
566
567
# File 'lib/flott.rb', line 565

def compiled
  @compiled
end

#directoriesObject (readonly)

A stack array, that contains the work directories of all active templates (during parsing).



573
574
575
# File 'lib/flott.rb', line 573

def directories
  @directories
end

#last_openObject

The type of the last opened bracket.



559
560
561
# File 'lib/flott.rb', line 559

def last_open
  @last_open
end

#openedObject

The number of current open (unescaped) brackets.



556
557
558
# File 'lib/flott.rb', line 556

def opened
  @opened
end

#pathesObject (readonly)

An array of involved template file pathes, that is, also the statically included template file pathes.



569
570
571
# File 'lib/flott.rb', line 569

def pathes
  @pathes
end

#skip_crObject

Returns the value of attribute skip_cr.



575
576
577
# File 'lib/flott.rb', line 575

def skip_cr
  @skip_cr
end

#textObject (readonly)

An array of all scanned text fragments.



562
563
564
# File 'lib/flott.rb', line 562

def text
  @text
end

Instance Method Details

#compiled_stringObject

Return the whole compiled code as a string.



588
589
590
# File 'lib/flott.rb', line 588

def compiled_string
  compiled.join.untaint
end

#pop_workdirObject

Pops the top directory from the directories stack.



606
607
608
609
610
611
# File 'lib/flott.rb', line 606

def pop_workdir
  directories.empty? and raise CompileError, "state directories were empty"
  directories.pop
  compiled << "@__workdir__ = '#{top_workdir}'\n"
  self
end

#push_workdir(parser) ⇒ Object

Pushs the workdir of parser onto the directories stack.



593
594
595
596
597
598
# File 'lib/flott.rb', line 593

def push_workdir(parser)
  workdir = parser.workdir
  compiled << "@__workdir__ = '#{workdir}'\n"
  directories << workdir
  self
end

#text2compiled(dont_sub = true) ⇒ Object

Transform text mode parts to compiled code parts.



578
579
580
581
582
583
584
585
# File 'lib/flott.rb', line 578

def text2compiled(dont_sub = true)
  return if text.empty?
  text.last.sub!(/[\t ]+$/, '') unless dont_sub
  compiled << '@__output__<<%q['
  compiled.concat(text)
  compiled << "]\n"
  text.clear
end

#top_workdirObject

Returns the top directory from the directories stack.



601
602
603
# File 'lib/flott.rb', line 601

def top_workdir
  directories.last
end