Class: DockDriver::Template

Inherits:
OpenStruct
  • Object
show all
Includes:
DatesAndTimes, Dzen2, Environment, FreeBSD, Linux, Network
Defined in:
lib/dock_driver/template.rb

Overview

This class provides a binding/namespace for ERB templating.

Defined Under Namespace

Modules: DatesAndTimes, Dzen2, Environment, FreeBSD, Linux, Network

Constant Summary

Constants included from FreeBSD

FreeBSD::LOADAVG_KEYS

Constants included from Linux

Linux::LOADAVG_KEYS, Linux::LOADAVG_PATH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dzen2

#button, #color_deg_c, #color_deg_f, #color_load, #colorize, #i3_button, #icon, included

Methods included from Network

#first_ipv4, #first_ipv6, #fqdn, #hostname, #ip_addrs

Methods included from Environment

#env, #username

Methods included from DatesAndTimes

#beats, #centibeats, #date, #gmdate

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Handle missing methods gracefully, by returning a red ! instead.



27
28
29
# File 'lib/dock_driver/template.rb', line 27

def method_missing( sym, *args, &block )
	return '^fg(red)!^fg()'
end

Class Method Details

.render(tmpl, items) ⇒ Object

A factory method to render the template, given a string, and a list of objects that respond to :to_s.

Returns the result of the template.

Example:

my_tmpl = "<%= date %>"
DockDriver::Template.render( my_tmpl, [] ) => '2012-10-05 11:30:22'


20
21
22
23
24
# File 'lib/dock_driver/template.rb', line 20

def self::render( tmpl, items )
	tmpl = ERB.new( tmpl )
	result = tmpl.result( self.new( items ).instance_eval { binding } )
	return result.gsub( /\s+/, ' ' )
end

Instance Method Details

#pagerObject

Get the workspace pager as a string. See WorkspacePager. Example:

<%= pager %>


40
41
42
# File 'lib/dock_driver/template.rb', line 40

def pager
	return DockDriver::pager.to_s
end