ginpar package

Submodules

ginpar.build module

Build command for Ginpar projects.

This module implements the building command for the ginpar static content generator.

build will read the configuration file in search for build_path and source_path. If not defined, build will use "public" and "sketches", respectively.

Examples

To build your project according to your specifications in config.yaml:

ginpar build

To build targeting a custom path _site/:

ginpar build --path="_site"

Notes

You cannot specify the content path. It is either config.content_path or "sketches".

ginpar.build.build(path)

Main function of the module. This is what ginpar build calls.

Parameters:
build_path : str

Path of the build.

ginpar.build.convert_information(sketch)

Convert the [“data”] field of a sketch into a Python dictionary.

Parameters:
sketch : dict

It contains the sketch information. Must contain [“data”], and [“data”] must be a YAML-valid string.

Returns:
dictionary

sketch but with the updated [“data”] field.

ginpar.build.copy_theme(build_path, theme)

Copy the theme static content into the build static directory.

Parameters:
build_path : str

Path of the build.

theme : str

Name of the theme to install.

ginpar.build.create_publishing_directory(build_path)

Remove existing directories with the same name, and create again.

Parameters:
build_path : str

Path of the build.

ginpar.build.dict_to_attrs(d)

Filter to convert a python dictionary into a HTML attributes.

For each (key, value) pair inside the dict, a key=value string will be created.

Parameters:
d : dict

Dictionary containing the key value attributes.

Returns:
str

String containing all the attributes of the dictionary separated with spaces.

ginpar.build.get_sketches(content_path)

Obtain the list of valid sketches inside path.

Valid sketches are directories containing at least two files: sketch.js and data.yaml.

This function will create a list of sketch objects containing name, script, and data.

Parameters:
content_path : str

The path containing the sketches to fetch.

Returns:
list

Individual elements contain {“name”, “script”, “data”}.

ginpar.build.param_to_dict(param)

Receive a parameter entry and convert it into a Python dictionary

A parameter entry looks like [{ VAR : CONTENTS_OF_VAR }]. This function turns that entry into a dictionary with keys {var, id, name, attrs}.

The attrs key must exist inside COTENTS_OF_VAR.

Parameters:
param : dict

A parameter as specified inside the data.yaml file of the sketch.

Returns:
dict

A properly formatted dictionary to use inside Ginpar with keys {var, id, attrs, name}.

ginpar.build.read_config(path)

Create a dictionary out of the YAML file received

Parameters:
path : str

Path of the YAML file.

ginpar.build.render_index(build_path, sketches, site, page_template)

Render the index using the list of sketches and site configuration

The index is rendered using a Jinja2 template inside the theme templates/ directory.

The index template must receive sketches, containing a list of the sketches names; and site, containing the site configuration from config.yaml.

Parameters:
build_path : str

Path of the build.

sketches : list

Contains all the sketches in the project. Must contain at leas [“name”].

site : dict

Contains the site information, such as sitename and author.

page_template : Jinja2.Template

Jinja2 template to render the sketch.

ginpar.build.render_sketch_page(build_path, sketch, site, page_template, input_templates)

Render a sketch page

This generates the page for a single sketch. This will convert the sketch[“data”] into a form that will control the variables of the script.

When sketch[“data”] doesn’t define fields that may be used at the moment of the form generation, Ginpar will instead look up for those fields in site[“sketch_defaults”].

When both sketch[“data”] and site[“sketch_defaults”] don’t define those fields, Ginpar will use the default values.

Ginpar default values for sketch data

Parameters:
build_path : str

Path of the build.

sketch : dict

Sketch information. Must contain [“data”] and [“name”]

site : dict

Site configuration.

page_template : Jinja2.Template

Jinja2 template to render the sketch.

ginpar.cli module

Definition of the CLI commands for Ginpar.

This module defines the different commands available for the ginpar static content generator.

Examples

To get the list of available commands and options run:

ginpar

ginpar.generators module

ginpar.generators.dict_to_attrs(d)

Filter to convert a python dictionary into a HTML attributes.

For each (key, value) pair inside the dict, a key=value string will be created.

Parameters:
d : dict

Dictionary containing the key value attributes.

Returns:
str

String containing all the attributes of the dictionary separated with spaces.

ginpar.generators.makeValueGetter(global_seed, attrs)

ginpar.init module

Init command for Ginpar projects.

This module implements the initialization command for the ginpar static content generator.

init will prompt for a series of values to write the site configuration file.

Examples

To initialize a project in a standard way to specify the configuration values:

ginpar init

To skip the prompts and initialize the project with the default values:

ginpar init --quick
ginpar init --q

To force the initialization in case there is a directory with the same name of the project to initialize:

ginpar init --force
ginpar init -f
ginpar.init.init(force, quick)

Main function of the module. This is what ginpar init calls.

Parameters:
force : bool

Remove conflicting files when true.

quick : bool

Skip prompts when true.

ginpar.init.prompt_site_config(quick)

Echo the prompts and create the configuration dict.

Echo the instructions and configuration fields, store each input, and create a dictionary containing those values.

Parameters:
quick : bool

Returns the default values immediatle if True.

Returns:
dict

Used to generate the site configuration file.

ginpar.new module

New sketch creation command for Ginpar projects.

This module implements the sketch creation command for the ginpar static content generator.

new will read the configuration file in search for source_path and create a new directory in there with the specified name, which by default is new-sketch-{n}.

This directory will contain the two required files with a boilerplate code.

Examples

To create a new sketch rectangle:

ginpar new rectangle

To start a new sketch with the default name new-sketch-{n}:

ginpar new
ginpar.new.new(sketch)

Main function of the module. This is what ginpar new calls.

Parameters:
sketch : str

Name of the sketch to create

ginpar.new.read_config(path)

Create a dictionary out of the YAML file received

Parameters:
path : str

Path of the YAML file.

ginpar.quickstart module

Quickstart command for Ginpar projects.

This module implements the quickstart command for the ginpar static content generator.

quickstart will download the contents of the sample repository hosted at davidomarf/ginpar-quickstart into ./quickstart.

This is aimed to provide an easier and faster way to start working in a Ginpar project for people who isn’t familiar with static content generators.

Example

To create ./quickstart and copy the contents of the sample repository:

ginpar quickstart

If there’s another directory named quickstart, you can force this command, removing the existing directory:

ginpar quickstart --force
ginpar quickstart -f
ginpar.quickstart.quickstart(force)

Main function of the module. This is what ginpar quickstart calls.

Parameters:
force : bool

Remove conflicting files when true.

ginpar.serve module

Serve command for Ginpar projects.

This module implements the server starting command for the ginpar static content generator.

serve will start a live-reloading server in a specified port.

Examples

To start a new server in the default port 8080:

ginpar serve

To start a new server in a custom port:

ginpar serve --port=3000
ginpar serve -p=3000
ginpar.serve.read_config(path)

Create a dictionary out of the YAML file received

Parameters:
path : str

Path of the YAML file.

ginpar.serve.serve(port, watch)

Main function of the module. This is what ginpar serve calls.

Parameters:
port : int

The port of the server

Module contents

ginpar.main()