PHPackages                             braincrafted/static-site-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. braincrafted/static-site-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

braincrafted/static-site-bundle
===============================

CocurBuildBundle

447[1 issues](https://github.com/braincrafted/static-site-bundle/issues)PHP

Since Jan 7Pushed 12y ago3 watchersCompare

[ Source](https://github.com/braincrafted/static-site-bundle)[ Packagist](https://packagist.org/packages/braincrafted/static-site-bundle)[ RSS](/packages/braincrafted-static-site-bundle/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

CocurBuildBundle
================

[](#cocurbuildbundle)

Static site generator bundle for Symfony2. *Early development release.*

[![Build Status](https://camo.githubusercontent.com/cc3b6af8c83cd2772a8c45b6e5833eee63880ee7517879f92ee92711c51750da/68747470733a2f2f7472617669732d63692e6f72672f636f6375722f6275696c642d62756e646c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/cocur/build-bundle)

Table of Contents
-----------------

[](#table-of-contents)

1. [Motivation](#motivation)
2. [Installation](#installation)
3. [Configuration](#configuration)
    1. [Generators](#generators)
        1. [File Generator](#file-generator)
        2. [Directory Generator](#directory-generator)
        3. [JSON Generator](#json-generator)
        4. [CSV Generator](#csv-generator)
        5. [YAML Generator](#yaml-generator)
        6. [Front-matter Generator](#front-matter-generator)
4. [Usage](#usage)
5. [Author](#author)
6. [License](#license)

Motivation
----------

[](#motivation)

The documentation for [BraincraftedBootstrapBundle](https://github.com/braincrafted/bootstrap-bundle) is a Symfony2 project, because it is used to test and demonstrate the bundles features. I no longer wanted to maintain (and pay for) another Symfony2 project on my server and instead move it to Github Pages. CocurBuildBundle creates static HTML pages from Symfony2 controllers.

Installation
------------

[](#installation)

You can install CocurBuildBundle using [Composer](http://getcomposer.org). Add to your `composer.json`:

```
{
    "require": {
        "cocur/build-bundle": "dev-master"
    }
}
```

You also have to add the bundle to your `AppKernel.php`:

```
// app/AppKernel.php

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Cocur\Bundle\BuildBundle\CocurBuildBundle(),
        );

        // ...

        return $bundles;
    }

    // ...
}
```

Configuration
-------------

[](#configuration)

- `enable_assetic`: When this option is `true` the `assetic:dump` command is executed when building the site. If the option is not defined it will be activated if `AsseticBundle` is installed.
- `build_directory`: The directory where the built site is saved.
- `base_url`: The base URL of the static site. Useful when the HTML is not saved in the root directory. Most commands have an option to override this on an individual basis.
- `index_name`: If a route doesn't contain a filename this value is appended to the route. The default value is `index.html`.

The default configuration looks like this:

```
# app/config/config.yml
cocur_build:
    build_directory: "%kernel.root_dir%/../build/site"
    base_url: ''
    index_name: index.html
    generators: ~
```

### Generators

[](#generators)

If an action requires parameters you can use generators to load the parameters from various sources. The bundle comes with four default generators:

- **File generator**: Every line in a file is a parameter; can only be used with actions that require a single parameter
- **Directory generator**: The name of every file or directory in a given directory is a parameter; can only be used with actions that require a single parameter
- **JSON generator**: A file that contains an array of objects; each object represents the parameters for an action; can be used with actions that require multiple parameters
- **CSV generator**: A file where each row contains the parameters of an action; must contain a header row that includes the parameter names; can be used for actions that require multiple parameters

Generators can be configured in your apps `config.yml` on a per-route basis.

#### File Generator

[](#file-generator)

Parameters are generated from a file.

**Required options:**

- `filename`
- `parameter`

In the following example we have a route `acme_demo_page` with the path `/p/{page}` and we want to generate the `page`parameter from a file called `data.txt`.

```
# app/config/config.yml

cocur_build:
    generators:
        page:
            route: acme_demo_page
            generator: cocur_build.file_generator
            options:
                filename: "%kernel.root_dir%/../data.txt"
                parameter: page
```

We require now the `data.txt` file that contains one parameter per line.

```
products
about
contact

```

CocurBuildBundle will render the following pages:

- `/p/products`
- `/p/about`
- `/p/contact`

#### Directory Generator

[](#directory-generator)

Parameters are generated from the names of files in a directory.

**Required options:**

- `directory_name`
- `parameter`

In this example we have a route `acme_demo_article` with the path `/article/{slug}` and we want to render the page for every file in a directory.

```
# app/config/config.yml

cocur_build:
    generators:
        article:
            route: acme_demo_article
            generator: cocur_build.directory_generator
            options:
                directory_name: "%kernel.root_dir%/../articles"
                parameter: slug
```

The directory `articles/` contains the following files:

```
articles/
    ⊢ 2013-12-03-bootstrap-bundle-2-0.md
    ⊢ 2013-12-04-cocur-bundle-0-1.md

```

CocurBuildBundle will render the following pages:

- `article/2013-12-03-bootstrap-bundle-2-0`
- `article/2013-12-04-cocur-bundle-0-1`

#### JSON Generator

[](#json-generator)

Parameters are generated from a JSON file.

**Required options:**

- `filename`

**Optional options:**

- `parameters`: Only use these parameters to generate pages

Let's consider a route `acme_demo_categorypage` with the path `/page/{category}/{page}`. We require two parameters `category` and `page` that we want to generate from a JSON file called `data.json`.

```
# app/config/config.yml

cocur_build:
    generators:
        categorypage:
            route: acme_demo_categorypage
            generator: cocur_build.json_generator
            options:
                filename: "%kernel.root_dir%/../data.json"
```

The JSON file `data.json` has to contain an array where each element is an object with a `category` and a `page`property:

```
[
    { "category": "foo", "page": "bar" },
    { "category": "foo", "page": "baz" }
]
```

CocurBuildBundle will render the following pages:

- `/pages/foo/bar`
- `/pages/foo/baz`

#### CSV Generator

[](#csv-generator)

Parameters are generated from a CSV file.

**Required options:**

- `filename`

**Optional options:**

- `delimiter` (default value is `,`)
- `enclosure` (default value is `"`)
- `escape` (default value is `\`)
- `parameters`: Only use these parameters to generate pages

Now we want to render the route `acme_demo_person` with the pattern `/person/{name}/{age}/{city}` using a CSV file `persons.csv`.

```
# app/config/config.yml

cocur_build:
    generators:
        person:
            route: acme_demo_person
            generator: cocur_build.csv_generator
            options:
                filename: "%kernel.root_dir%/../persons.csv"
```

The CSV file has to contain three columns and a header row containing `name`, `age` and `city`.

```
"name", "age", "city"
"Florian", "27", "Vienna"
"Daniela", "22", "Vienna"
```

CocurBuildBundle will render the following pages:

- `/person/Florian/27/Vienna`
- `/person/Daniela/22/Vienna`

#### YAML Generator

[](#yaml-generator)

Parameters are generated from a YAML file.

**Required options:**

- `filename`

**Optional options:**

- `parameters`: Only use these parameters to generate pages

If we want to render the route `acme_demo_person` with the pattern `/person/{name}/{age}/{city}` we can also use a YAML file `persons.yaml`.

```
# app/config/config.yml

cocur_build:
    generators:
        person:
            route: acme_demo_person
            generator: cocur_build.yaml_generator
            options:
                filename: "%kernel.root_dir%/../persons.yml"
```

The YAML file `persons.yml` has to contain a list element for every person with a named property for every parameter.

```
-
    name: Florian
    age: 27
    city: Vienna
-
    name: Daniela
    age: 22
    city: Vienna
```

CocurBuildBundle will render the following pages:

- `/person/Florian/27/Vienna`
- `/person/Daniela/22/Vienna`

#### Front-matter Generator

[](#front-matter-generator)

Parameters are generated from the front-matter of files in a directory.

**Required options:**

- `directory_name`

**Optional options:**

- `parameters`: Only use these parameters to generate pages

In this example we have a route `acme_demo_article` with the path `/article/{category}/{slug}` and we want to render the page for every file in a directory.

```
# app/config/config.yml

cocur_build:
    generators:
        article:
            route: acme_demo_article
            generator: cocur_build.front_matter_generator
            options:
                directory_name: "%kernel.root_dir%/../articles"
```

For example, the file `articles/2013-12-03-bootstrap-bundle-2-0.md` could look like:

```
---
category: dev
slug: bootstrap-bundle-2-0
---
This is the rest of the file. Just some text.
```

CocurBuildBundle will render the following page:

- `article/dev/bootstrap-bundle-2-0`

Usage
-----

[](#usage)

The build command is the main command offered by CocurBuildBundle. It renders all pages and dumps the assets into the build directory.

```
$ php app/console cocur:build
```

The HTML code will be saved in the directory configured with `cocur_build.build_directory`.

***Note:** CocurBuildBundle can handle actions with parameters if a generator is configured for these routes.*

When you use the build command, CocurBuildBundle uses the Symfony2 kernel to simulate a request to a page. The kernel is booted in the environment the command is invoked. If you want to build the pages for production, you need to build them in the `prod` environment.

```
$ php app/console cocur:build -e prod
```

If `cocur:build` is called in the prod environment the cache is cleared before the rendering.

You can remove all files from the build directory by using the `clean` command

```
$ php app/console cocur:clean
```

Author
------

[](#author)

- [Florian Eckerstorfer](http://florian.ec) ([Twitter](http://twitter.com/Florian_), [App.net](http://app.net/florian))

License
-------

[](#license)

This bundle is licensed under the [MIT license](http://opensource.org/licenses/MIT). For more information see the LICENSE file.

[![Bitdeli Badge](https://camo.githubusercontent.com/6846629a86362a265aab8507f7d7a14b74de48dc68c7cc17d1e887698d32f2ab/68747470733a2f2f64327765637a68766c38323376302e636c6f756466726f6e742e6e65742f636f6375722f6275696c642d62756e646c652f7472656e642e706e67)](https://bitdeli.com/free "Bitdeli Badge")

###  Health Score

21

—

LowBetter than 17% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a80f9fc61cd3a7d7779e8f120b458ca4d18fdd885d719bb77d3379b96bf714d9?d=identicon)[florianeckerstorfer](/maintainers/florianeckerstorfer)

---

Top Contributors

[![bitdeli-chef](https://avatars.githubusercontent.com/u/3092978?v=4)](https://github.com/bitdeli-chef "bitdeli-chef (1 commits)")

### Embed Badge

![Health badge](/badges/braincrafted-static-site-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/braincrafted-static-site-bundle/health.svg)](https://phpackages.com/packages/braincrafted-static-site-bundle)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
