Class: Tzispa::Rig::ParserNext

Inherits:
Object
  • Object
show all
Includes:
Syntax
Defined in:
lib/tzispa/rig/parsernext.rb

Constant Summary collapse

EMPTY_STRING =
''

Constants included from Syntax

Syntax::RIG_EMPTY, Syntax::RIG_EXPRESSIONS, Syntax::RIG_STATEMENTS, Syntax::RIG_TEMPLATES, Syntax::RIG_URL_BUILDER

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, text = nil) ⇒ ParserNext

Returns a new instance of ParserNext.



346
347
348
349
350
# File 'lib/tzispa/rig/parsernext.rb', line 346

def initialize(template, text=nil)
  @template = template
  @inner_text = text ? text : template.content
  @the_parsed = Array.new
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



344
345
346
# File 'lib/tzispa/rig/parsernext.rb', line 344

def flags
  @flags
end

#templateObject (readonly)

Returns the value of attribute template.



344
345
346
# File 'lib/tzispa/rig/parsernext.rb', line 344

def template
  @template
end

#the_parsedObject (readonly)

Returns the value of attribute the_parsed.



344
345
346
# File 'lib/tzispa/rig/parsernext.rb', line 344

def the_parsed
  @the_parsed
end

Instance Method Details

#attribute_tagsObject



376
377
378
379
380
381
382
# File 'lib/tzispa/rig/parsernext.rb', line 376

def attribute_tags
  @attribute_tags ||= @the_parsed.map { |p|
     p.id.to_sym if p.respond_to? :id
   }.concat(@the_parsed.map{ |p|
      p.attribute_tags if p.type==:ife
  }).compact.flatten.uniq.freeze
end

#empty?Boolean

Returns:

  • (Boolean)


352
353
354
# File 'lib/tzispa/rig/parsernext.rb', line 352

def empty?
  @the_parsed.empty?
end

#loop_parser(id) ⇒ Object



384
385
386
387
388
# File 'lib/tzispa/rig/parsernext.rb', line 384

def loop_parser(id)
  @the_parsed.select{ |p| p.type==:loop && p.id==id}.concat(
    @the_parsed.select{ |p| p.type==:ife }.map { |p| p.loop_parser(id) }.flatten.compact
  )
end

#parse!Object



356
357
358
359
360
361
362
363
364
365
366
# File 'lib/tzispa/rig/parsernext.rb', line 356

def parse!
  @tags = nil
  parse_flags
  if @template.bindable?
    parse_statements
    parse_expressions
  end
  parse_url_builder
  parse_templates
  self
end

#render(binder, context = nil) ⇒ Object



368
369
370
371
372
373
374
# File 'lib/tzispa/rig/parsernext.rb', line 368

def render(binder, context=nil)
  @inner_text.dup.tap { |text|
    @the_parsed.each { |value|
      text.gsub! value.anchor, value.render(binder)
    }
  }.freeze
end