Documentation ¶
Overview ¶
Package gen is the modern day static site generator that focus on practical usage , performance , maintainability, and ability to extend.
Features ¶
* Fast it has been designed for speed in mind. The implementation is well banchmarked.
* Robust plugin system. This allows you to write plugins in vanilla javascript. It avoids the pitfall of all Golang based static site generators by allowing uses to tap into the build process via javascript.
* Unparalled templating engine. Benefit with the power of go templates with the flexibility of writing template functions in javascript.
Index ¶
- func AddRequire(ctx *Context) error
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func Configure(ctx *Context) error
- func EvaluateFile(fs afero.Fs, vm *otto.Otto, path string) error
- func ExecPlan(ctx *Context, fl FileList, s *Plan) error
- func Execute(ctx *Context) error
- func Initilize(ctx *Context) error
- func MustAsset(name string) []byte
- func PlanExecution(ctx *Context) error
- func RegisterBuiltins(ctx *Context, r *Require) error
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func ToValue(o interface{}) otto.Value
- type Author
- type Boot
- type Config
- type Context
- type Export
- type File
- type FileList
- type Plan
- type Require
- type Stage
- type Strategy
- type System
- type Template
- type Theme
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddRequire ¶
AddRequire adds require function to the ctx VM. It also loads the modules that are shipped with the package( a.k.a builtin modules).
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func Configure ¶
Configure configures the ctx with default values. This make sure the ctx is in good shape to be passed around to any other stages.
It is safe to pass an eunintialized *Context, when you want to expect default behaviour.
passing unitialized *Context will make the current working directory as the context WOrkDir. This can have unintended effect so be warned and just make sure the context passed has WorkDir set if you inted to do something otherwise.
func EvaluateFile ¶
EvaluateFile opens the file in the specified path and evaluates it withing the context of the javascript runtine.
The evaluated javascript code can mutate the global state. Use execFile to execute the javascript without mutating the state of the generato'r javascript runtime.
func Execute ¶
Execute executes the plans that are outilend by the plans found in ctx.
Execution is done in two phases. First the files are evaluated using the matching plans. Plans are per file. Secondly the rendering of the site is done.
Evaluation of files is done concurrently, then the results are aggregated back together.
Rendering is done synchronously. As there is a lot of cross refences and stuffs to be considered, the rendering function is provided by the plan.
func Initilize ¶
Initilize initializes the build process. Any stages after this will have the generator already bootstraped.
It is possible to bootstrap the generator from the project( User's side) by providing an entry javascript file in the default path of scripts/init/index.js which will be executed and you can overide the default entry script which is evaluated internally
Initialzation is offloaded to the javascript runtine of the generator..Any error returned is a build error.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func PlanExecution ¶
PlanExecution is the planning phase of the generator. First a project specific plan file is evaluated, the file is loacetd in /scripts_dir/plan_fir/index.js for example /scripts/plan/index.js. Second the existing system plan is merged with default plan.
TODO: Use user defined plan only when it is set, and use default plan only when there is no user defined plan.
This is executed to prepare the Plan object, which is the blueprint on how the whole execution is going to take place.
func RegisterBuiltins ¶
RegisterBuiltins adds important modules like underscore and fs. This relies on the assumption that the reuire function that is vailable in the ctx.VM instance is the one passed as r.
It caches the pre evaluated values for the modules to the reauire object.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type Author ¶
type Author struct { Name string `json:"name"` Github string `json:"github"` Twitter string `json:"twitter"` Linkedin string `json:"linkedin"` Email string `json:"email"` Website string `json:"website"` }
Author description of the author of the project being built.
type Boot ¶
type Boot struct { ConfigiFile string `json:"config_file"` PlanFile string `json:"plan_file"` ENV map[string]string `json:"env"` }
Boot necessary info to bootstrap the Generator.
type Config ¶
type Config struct { Name string `json:"name" yaml:"name"` Source string `json:"source" yaml:"source"` Destination string `json:"destination" yaml:"destination"` StaticDir string `json:"statc_dir" yaml:"statc_dir"` TemplatesDir string `json:"templates_dir" yaml:"templates_dir"` ThemeDir string `json:"theme_dir" yaml:"theme_dir"` DefaultTheme string `json:"default_theme" yaml:"default_theme"` PluginDir string `json:"plugin_dir" yaml:"plugin_dir"` Safe bool `json:"safe" yaml:"safe"` Excluede []string `json:"exclude" yaml:"exclude"` Include []string `json:"include" yaml:"include"` }
Config is the settings needed by the static generatot. It is inspired by the jekyll configuration options.
The format can either be json, yaml or toml TODO: add yaml and toml support.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig retruns *Config with default settings
type Context ¶
type Context struct { FS afero.Fs VM *otto.Otto Sys *System WorkDir string Verbose bool Job *health.Job Out io.Writer }
Context is the context of a static website project.
type Export ¶
type Export map[string]interface{}
Export helper for building javascript objects from Go objects.
func Markdown ¶
func Markdown() Export
Markdown module for the otto runtime. This exposes one method exec, which accepts a File object as an argument. It renders the Contents of the file to markdown.
A HTML method is provided just in case you want to render a piece of text as markdown.
type File ¶
type File struct { Name string `json:"name"` Meta map[string]interface{} `json:"meta"` Contents string `json:"contents"` }
File is a representation of a file unit as it is passed arouund for processing. File content is passed as a string so as to allow easy trasition between Go and javascript boundary.
type FileList ¶
type FileList []*File
FileList is a list of files, which can be ordered based on various criterias
type Plan ¶
type Plan struct { Title string `json:"title"` // Modules that are supposed to be loaded before the execution starts. The // execution process wont start if one of the dependencies is missing. Dependency []string `json:"dependencies"` TemplateEngine string `json:"template_engine"` Strategies []*Strategy `json:"strategies"` After []string `json:"after"` }
Plan is the execution planner object. It states the steps and stages on which the execution process should take.
type Require ¶
type Require struct { Cache *cache2go.CacheTable Paths []string Fs afero.Fs }
Require implements a simple node.js like require mechanism. It loads jsavascript files from the source and exposes them as modules in the runtime.
This follows node.js convention by using the exports object to attach the functions or objects exposed by the module.
NOTE: cyclic dependencies are not taken care yet, so this will break in case of cyclic dependency.
func NewRequire ¶
NewRequire returns an initialized Require object
type Stage ¶
Stage is an interface representing a generation step
type Strategy ¶
type Strategy struct { Title string `json:"title"` Patterns []string `json:"patterns"` FullMatch bool `json:"fullMatch"` Before []string `json:"before"` Exec []string `json:"exec"` After []string `json:"after"` }
Strategy defines what should be done when a file matches a certain pattern. the pattern is glob like and matches only on the filenames
The FullMatch field specifies the pattern to be matchig the full file path. if set to false is means the pattern only matches the base of the file path( ignoring the directories).
type System ¶
type System struct { Boot *Boot `json:"boot"` Config *Config `json:"config"` Plan *Plan `json:"plan"` }
System configuration for the whole static generator system. The information consost of things necessary to bootup, configure and plan the execution of the static project..