Class: Sbuilder::TemplateResolve

Inherits:
TemplateRoot show all
Extended by:
Forwardable
Includes:
Utils::MyLogger
Defined in:
lib/sbuilder/mustache/template_resolve.rb

Overview

Find names of templates included from mustache extension point template file.

Since:

  • 0.3.1

Constant Summary collapse

PROGNAME =

Since:

  • 0.3.1

nil

Constants included from Utils::MyLogger

Utils::MyLogger::LOGFILE

Instance Attribute Summary

Attributes inherited from TemplateRoot

#reader

Construtor + configure collapse

Public services collapse

Called from 'partial' -method collapse

Collect partials called collapse

Methods included from Utils::MyLogger

#getLogger, #logfile

Methods inherited from TemplateRoot

#is_extension_point, #partial

Constructor Details

#initialize(reader, options = {}) ⇒ TemplateResolve


Since:

  • 0.3.1



21
22
23
24
25
26
27
# File 'lib/sbuilder/mustache/template_resolve.rb', line 21

def initialize(  reader, options={} )
  super( reader, options )
  
  @logger = getLogger( PROGNAME, options )
  @logger.info( "#{__method__} created" )

end

Instance Method Details

#get_partial(name) ⇒ Object

Intercept chain to read template file.

Delegates actual read operation to ‘get_template’ in parent class reader.

Parameters:

  • name (:symbol)

    name of partial template to include

Since:

  • 0.3.1



71
72
73
74
75
76
77
78
79
80
# File 'lib/sbuilder/mustache/template_resolve.rb', line 71

def get_partial( name ) 
  @logger.info( "#{__method__} read partial_file=#{name}:#{name.class}" )

  # this partial called
  partialsAdd( name.to_s )
  
  partial = get_template( name )
  return partial

end

#partialsAdd(name) ⇒ Object

Since:

  • 0.3.1



91
92
93
# File 'lib/sbuilder/mustache/template_resolve.rb', line 91

def partialsAdd( name )
  @partials << name
end

#partialsCalledObject

Since:

  • 0.3.1



95
96
97
# File 'lib/sbuilder/mustache/template_resolve.rb', line 95

def partialsCalled
  @partials
end

#partialsInitObject


Since:

  • 0.3.1



87
88
89
# File 'lib/sbuilder/mustache/template_resolve.rb', line 87

def partialsInit()
  @partials=[]
end

#resolve_partials(extension_point) ⇒ String:Array

Resolve file names used in ‘extesion_point’

Implementation assumes that this method is called only for extension points.

Parameters:

  • extension_point (String)

    template for extension point

Returns:

  • (String:Array)

    array filenames for partials called for the ‘extension_point’

Since:

  • 0.3.1



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sbuilder/mustache/template_resolve.rb', line 42

def resolve_partials( extension_point )
  @logger.info( "#{__method__} extension_point=#{extension_point}" )
  template = get_template( extension_point )
  @logger.debug( "#{__method__} #{extension_point} -> template #{template}" )      

  # data passed to rendering, in this use empty data, because we
  # are interested only in names included templates
  data = {}

  # render collects partials used for 'template'
  partialsInit

  str = render( template, {} )

  return partialsCalled

end