Class: Bookfile::PageCtx

Inherits:
Object
  • Object
show all
Includes:
HybookHelper
Defined in:
lib/bookfile/book/book.rb

Overview

page context for evaluate

Instance Method Summary collapse

Methods included from HybookHelper

#columns_begin, #columns_end, #link_to, #number_with_delimiter

Constructor Details

#initialize(config) ⇒ PageCtx

BookConfig



19
20
21
22
23
24
25
# File 'lib/bookfile/book/book.rb', line 19

def initialize( config )   ## BookConfig
  ## pass in templates_dir here
  ##   ## TEMPLATES_DIR = ??  -- passed in as config
  ##  or pass in class to help find templates???
  ##  TemplateMan( ??? )
  @config = config
end

Instance Method Details

#_locals_code(locals) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bookfile/book/book.rb', line 50

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 = {}) ⇒ Object

possible? - make opts required ??



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/bookfile/book/book.rb', line 32

def render( name, opts={}, locals={} )  ## possible? - make opts required ??
  puts "*** render #{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 )

  puts "  #{text}"
  text
end

#write(text) ⇒ Object



27
28
29
30
# File 'lib/bookfile/book/book.rb', line 27

def write( text )
  puts "*** write:"
  puts "  #{text}"
end