pup-tent.js

Summary
pup-tent.js
Functions
AbstractFSSynchronous cross-platform filesystem abstraction for a few common operations.
environmentReturn a string representation og the current running environment.
exists_pWhether or not a path exists.
file_pReturns whether or not a path is a file.
read_fileRead a file, returning it as a string.
list_directoryReturn a list of the files in a directory (names relative to the directory) as strings.
require(‘pup-tent’)Creates an instance of the Pup Tent femto-framework.
use_cache_pBy default, Pup Tent uses a cache of files read from the filesystem during the initial scan.
getGet a file from the cache by key; null otherwise.
cached_listReturns a list of the cached files.
applyRun a template with the given arguments.
set_commonAdd variables and libraries to special variables for all calls to render.
renderRender with special variables.

Functions

AbstractFS

function AbstractFS()

Synchronous cross-platform filesystem abstraction for a few common operations.  Not meant to a be full-blown fix for these issues (http://www.gigamonkeys.com/book/files-and-file-io.html#filenames).

Currently supports Node.js and RingoJS.  Will hopefully be unnecessary when CommonJS and everybody get it together: http://wiki.commonjs.org/wiki/Filesystem

Parameters

n/a

Returns

An instance of the AbstractFS abstraction.

environment

anchor.environment = function()

Return a string representation og the current running environment.

Parameters

n/a

Returns

string

exists_p

anchor.exists_p = function(path)

Whether or not a path exists.

Parameters

paththe desired path as a string

Returns

boolean

file_p

anchor.file_p = function(path)

Returns whether or not a path is a file.

Parameters

paththe desired path as a string

Returns

boolean

read_file

anchor.read_file = function(path)

Read a file, returning it as a string.

Parameters

paththe desired path as a string

Returns

string or null

list_directory

anchor.list_directory = function(path)

Return a list of the files in a directory (names relative to the directory) as strings.

Parameters

paththe desired path as a string

Returns

list of strings

require(‘pup-tent’)

Creates an instance of the Pup Tent femto-framework.

Parameters

search_path_listlist of directories to search for static files (e.g.  [‘static’, ‘js’, ‘css’, ‘templates’])
filename_list[optional] list of static files (e.g.  [‘Login.js’, ‘login_content.tmpl’])

Returns

An instance of the Pup Tent femto-framework.

use_cache_p

use_cache_p: function(yes_no)

By default, Pup Tent uses a cache of files read from the filesystem during the initial scan.  However, to enable rapid development of browser JS and sites, this can be turned off, with files being re-read off the filesystem.

Note that new or deleted files would still require a restart.

Parameters

yes_no[optional] change the state of cache use (default: true)

Returns

boolean

get

get: function(key)

Get a file from the cache by key; null otherwise.

Parameters

tmpl_namethe (string) name of the template to run
thing[optional] argument hash

Returns

string or null

cached_list

cached_list: function()

Returns a list of the cached files.

Parameters

n/a

Returns

list of strings

apply

apply: function(tmpl_name,
tmpl_args)

Run a template with the given arguments.

Parameters

tmpl_namethe (string) name of the template to run
thing[optional] argument hash

Returns

string

Also see

render

set_common

set_common: function(stack_name,
thing)

Add variables and libraries to special variables for all calls to render.

Available stacks are

  • css_libs: will map to pup_tent_css_libraries
  • js_vars: will map to pup_tent_js_variables
  • js_libs: will map to pup_tent_js_libraries

Parameters

stack_namethe name of the stact to add to (list above)
thingvariable structure; either a string for *_libs or {‘name’: name, ‘value’: value} for js_vars

Returns

return thing or null

Also see

render

render

render: function(tmpl_name,
tmpl_args,
frame_tmpl_name)

Render with special variables.  Also wrapper for the usual inner/outer pattern.

Special template/variable names in/for base

  • pup_tent_css_libraries: list of CSS files to use
  • pup_tent_js_libraries: list of JS files to use
  • pup_tent_js_variables: list of name/value objects to convert to vaiables
  • pup_tent_content: meant for use in [base_tmpl_name] to embed one template in another

Parameters

tmpl_namecontent template name (in path)
tmpl_argsvariable arguments
frame_tmpl_name[optional] using variable [pup_tent_content] embed content_tmpl_name

Returns

string

function AbstractFS()
Synchronous cross-platform filesystem abstraction for a few common operations.
anchor.environment = function()
Return a string representation og the current running environment.
anchor.exists_p = function(path)
Whether or not a path exists.
anchor.file_p = function(path)
Returns whether or not a path is a file.
anchor.read_file = function(path)
Read a file, returning it as a string.
anchor.list_directory = function(path)
Return a list of the files in a directory (names relative to the directory) as strings.
use_cache_p: function(yes_no)
By default, Pup Tent uses a cache of files read from the filesystem during the initial scan.
get: function(key)
Get a file from the cache by key; null otherwise.
cached_list: function()
Returns a list of the cached files.
apply: function(tmpl_name,
tmpl_args)
Run a template with the given arguments.
set_common: function(stack_name,
thing)
Add variables and libraries to special variables for all calls to render.
render: function(tmpl_name,
tmpl_args,
frame_tmpl_name)
Render with special variables.
Close