class Bookfile::PageCtx
Attributes
content[R]
Public Class Methods
new( config )
click to toggle source
# File lib/bookfile/book/book.rb, line 21 def initialize( config ) ## BookConfig @config = config @content = '' ## rename to body,text,buf,out - why, why not??? ## track rendering (stack) level - only output if in top-level (1) ## -- check/todo - is there a better way??? ## use a (separate) partial method or keep using on render method etc. ??? ## any other ways?? @level = 0 end
Public Instance Methods
_locals_code( locals )
click to toggle source
# File lib/bookfile/book/book.rb, line 67 def _locals_code( locals ) ## convert locals hash to erb snippet with shortcuts ## e.g. country = locals[:country] ## and so on buf = "<%\n" locals.each do |k,v| puts " add local '#{k}' #{k.class.name} - #{v.class.name}" buf << "#{k} = locals[:#{k}];\n" end buf << "%>\n" buf end
render( name, opts={}, locals={} )
click to toggle source
# File lib/bookfile/book/book.rb, line 40 def render( name, opts={}, locals={} ) ## possible? - make opts required ?? @level +=1 puts "*** render(#{@level}) #{name}:" tmpl = File.read_utf8( "#{@config.templates_dir}/#{name}.md" ) ## name e.g. includes/_city ### if any locals defined; add "header/preamble w/ shortcuts" to template # e.g. country = locals[:country] etc. unless locals.empty? tmpl = _locals_code( locals ) + tmpl end text = TextUtils::PageTemplate.new( tmpl ).render( binding ) ## note: only add text to content if top-level render call ## (do NOT add for partials/includes/etc.) if @level == 1 @content << text end @level -=1 ## puts " #{text}" text end
write( text )
click to toggle source
# File lib/bookfile/book/book.rb, line 33 def write( text ) puts "*** write:" ## puts " #{text}" @content << text end