Spirit Core
Summary
A simple, adaptable and powerful static file generator.
Installation
Install the Spirit Core module through npm.
npm install spirit-core
Syntax
var SpiritCore = ;var spirit = rootPath config ;
Paramaters
rootPath
A String
that specifies the root path relative to the node processes current working directory.
config
By default the software will look for configuration file in the SPIRIT_CONFIG
environment variable.
If no environment variable is set, it will use the optional Object
config paramater.
If no config parameter is given, it will then look for a _config.json
file in the root directory.
Otherwise it will use the default configuration settings listed below.
The configuration object will default to these values.
config.src
: "."
The relative source path to load files from. More information at the
Spirit Paths middleware repository.
config.dest
: "dest"
The relative destination path to write files to. More information at the
Spirit Paths middleware repository.
config.ignore
: [ 'node_modules', '.DS_Store', 'npm-debug.log', 'package.json' ]
An Array
of filesPaths relative to the source directory to be ignored. More information
at the Spirit Ignore middleware repository.
config.site
:
{ data: { }, src: '_site.json'}
A Spirit Site Data configuration Object
config.site.data
: { }
An empty site data object. More information at the
Spirit Site Data repository.
config.site.src
: "_site.json"
relative file path to load site data JSON from. More information
at the Spirit Site Data repository.
src: '.' dest: '_dest' ignore: 'node_modules' '.DS_Store' 'npm-debug.log' 'package.json' site: data: src: '_site.json'
Properties
spiritCore.END_EVENT
:
A unique end event string. Emitted when all the middleware has been loaded and the files have been written to the destination folder.
spiritCore.ERROR_EVENT
:
A unique error event string to handle errors. See Spirit Errors middleware for more information.
Methods
spiritCore.use( [ Function] )
:
Takes a middleware Function
to be called. The Function
is called with two arguments.
-
next : A
Function
to be called when your middleware is done executing. ( Will call the following middleware, if one exists ). -
spirit : The SpiritCore
Object
instance.
For more information visit the Spirit Middleware middleware repository.
spiritCore.ignore( [ Array ] )
:
Takes an array of relative string paths to ignore. For more information visit the Spirit Ignore middleware repository.
spiritCore.on( [ String ], [ Function ] )
:
Takes a unique event String
and a Function
to be called every time the String
is emitted .
For more information visit the Spirit Events middleware repository.
spiritCore.off( [ String ], [ Function ] )
:
Takes a unique event String
and optional Function
.
If a function is provided it will remove that from function from the unique event String
subscription.
If no function is provided is will remove all functions fromt the unique event String
subscription.
For more information visit the Spirit Events middleware repository.
spiritCore.emit( [ String] )
:
Takes a unique event String
that will call all functions subscribed to it.
For more information visit the Spirit Events middleware repository.
spiritCore.run( )
:
Will write all files in the current files Object
to the destination directory.
spiritCore.getData( )
:
Will return an spiritData Object
with the following properties on it.
spiritData.paths
: Object
A paths Object
with the following properties. See Spirit Paths
middleware for more information.
spiritData.paths.root
: String
The absolute root path of the directory.
spiritData.paths.src
: String
the absolute source path to be read from.
spiritData.paths.dest
: String
the absolute destination path to write to.
spiritData.config
: Object
The Spirit Core configuration object. See Spirit Config middleware for more information.
spiritData.ignore
: Array
An Array
of relative String
paths to ignore. See Spirit Ignore
middleware for more information.
spiritData.files
: Object
An Object
of relative filepath keys mapping to a file Object
with the following properties. See Spirit Files
middleware for more information.
spiritData.files[ filePath ].buffer
: Buffer Object
The files content buffer Object
.
spiritData.site
: Object
Custom site data object for templates. See Spirit Site Data middleware for more information.
spiritCore.setData( [ Object ] )
:
Replaces the spiritData Object
with the new Object
argument.
Example
Directory structure
> = Directory
- = File
>"example"
>"_src"
-"index.html"
-"main.js"
-"main.css"
-"keys.json"
-"site_data.json"
>"_dest"
var config = src : '_src' dest: '_dest' ignore: "keys.json" site : src : "site_data.json" var SpiritCore = ; var spirit = './example' config ; spirit ; spirit ; { var spiritData = spirit ; console ; console ; console ; }
Output directory structure.
>"example"
>"_src"
-"index.html"
-"main.js"
-"main.css"
-"keys.json"
-"site_data.json"
>"_dest"
-"index.html"
-"main.js"
-"main.css"
Hand made in San Francisco California by Alex Ray .