# Class: Tgtemplate::Template

The template class. Used to create an instance of template from an action

# Public Class Methods

### new (filename)

Sets values when calling new method for a template

Show source...

        # File bbs/lib/tgtemplate.rb, line 86
    86:    def initialize(filename)
    87:       @tout = JavaIO::OutputStreamWriter.new(JavaLang::System.out)
    88:       @template = $tcfg.getTemplate(filename)
    89:       @tdata = JavaUtil::HashMap.new
    90:       @tcolors = JavaUtil::HashMap.new
    91:       ANSICOLORS.each do |key, value|
    92:             @tcolors.put(key, value)
    93:       end
    94:    end

### parse_dataset (sqlset)

Parses an array of hashes created by a Sequel Dataset, and constructs a new array of JavaUtil::HashMap(s) with the keys converted from symbols to string.

Show source...

         # File bbs/lib/tgtemplate.rb, line 139
    139:    def Template.parse_dataset(sqlset)
    140:      if sqlset.class == Array
    141:        newarray = []
    142:        sqlset.each do |h|
    143:          if h.class == Hash
    144:            newhash = JavaUtil::HashMap.new
    145:            h.each_pair do |k ,v|
    146:              newhash.put(k.to_s, v)
    147:            end
    148:          end
    149:          newarray.push(newhash)
    150:        end
    151:      end
    152:      return newarray
    153:    end

### parse_hash (sqlset)

Show source...

         # File bbs/lib/tgtemplate.rb, line 155
    155:     def Template.parse_hash(sqlset)
    156:      if sqlset.class == Hash
    157:            newhash = JavaUtil::HashMap.new
    158:            sqlset.each_pair do |k ,v|
    159:              newhash.put(k.to_s, v)
    160:            end
    161:      end
    162:      return newhash
    163:    end

# Public Instance Methods

### render (data={})

Renders the template to stdout

Show source...

         # File bbs/lib/tgtemplate.rb, line 97
     97:    def render(data={})
     98:       if data.class == Hash
     99:          data.each do |key, value|
    100:             @tdata.put(key, value)
    101:          end
    102:          @tdata.put("color", @tcolors)
    103:          if $session
    104:            @tdata.put("session_expires", $session.expires.to_s)
    105:            @tdata.put("session_timeremain", $session.timeremain.to_s)
    106:          end
    107:          @template.process(@tdata, @tout)
    108:          @tout.flush
    109:       else
    110:          puts "Tgtemplate: Parsing error - data not of type Ruby::Hash. Type was (#{data.class})"
    111:       end
    112:    end

### stringify (data={})

Renders the template to a string so it may be paged using the Pager facility

Show source...

         # File bbs/lib/tgtemplate.rb, line 116
    116:    def stringify(data={})
    117:       if data.class == Hash
    118:          data.each do |key, value|
    119:             @tdata.put(key, value)
    120:          end
    121:          @tdata.put("color", @tcolors)
    122:          if $session
    123:            @tdata.put("session_expires", $session.expires.to_s)
    124:            @tdata.put("session_timeremain", $session.timeremain.to_s)
    125:          end
    126:          @sout = JavaIO::StringWriter.new()
    127:
    128:          @template.process(@tdata, @sout)
    129:          return @sout.toString
    130:       else
    131:          puts "Tgtemplate: Parsing error - data not of type Ruby::Hash. Type was (#{data.class})"
    132:       end
    133:    end