Skip to content

Commit

Permalink
feat: misc + refactoring
Browse files Browse the repository at this point in the history
- refactor loading, variable processing etc into reusable loader library
- remove "data.json" loading (use json references to import data from main stamp.yaml)
- update README.md
- support autotune
  • Loading branch information
joostfaassen committed Nov 24, 2019
1 parent befad45 commit 6c9bfa8
Show file tree
Hide file tree
Showing 17 changed files with 782 additions and 413 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
.idea/
example/output/
vendor/
examples/*.md
examples/*/*.md
autotune.json
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ Stamp generate files by applying data to templates.

When you run `stamp generate`, Stamp will look for it's configuration in a file called `stamp.yaml` in the current directory. You can also pass a specify config file using `-c`.

Additionally, stamp loads data from a file called `data.json`, or you can specify one using `-j`.

For example `stamp.yaml` and `data.json` files, please check the `example/` directory.

Stamp will then loop through the `templates` defined in the config file, and use the template files defined by the `src` key, and generate the file defined by the `dest` key.

By specifying an `items` key, one template may be applied multiple times, resulting in multiple output files.
Expand All @@ -39,7 +35,7 @@ variables:
title: Hello world
license: mit

files:
templates:
- src: stamp/README.md.twig
dest: README.md
variables:
Expand All @@ -62,19 +58,15 @@ Stamp supports multiple template languages/engines, which will be used based on
* `.hbs`, `.handlebars`: Use the [Handlebars](https://handlebarsjs.com/) template language (powered by [LightnCandy](https://github.com/zordius/lightncandy))
* `.mustache`: Use the [Mustache](https://mustache.github.io/) template language (powered by [LightnCandy](https://github.com/zordius/lightncandy))

## Functions

In `stamp.yaml`, you define `src`/`dest` filenames and `items` variables.
These keys all support "expressions" in which you could optionally use a set of functions to apply to variables.
## Variables and functions

* `strtolower`: lowercase the variable
* `dict`: Convert a key/value dictionary into an array of `item.key` and `item.value` items.
Stamp is using the [LinkORB Loader](https://github.com/linkorb/loader) library for loading the stamp.yaml file.

More functions can easily be registered in the constructor of `src/Generator.php`.
It therefor supports all features related to variables, includes and functions that the loader does.

## Development / debugging:

The `examples/` directory contains an example configuration (`stamp.yaml`), data file (`data.json`) and template files.
The `examples/` directory contains an example configuration (`stamp.yaml`) and template files.

## License

Expand Down
8 changes: 7 additions & 1 deletion bin/stamp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<?php

use Symfony\Component\Console\Application;
use AutoTune\Tuner;

$loader = __DIR__ . '/../vendor/autoload.php';

Expand All @@ -17,7 +18,12 @@ if (!file_exists($loader)) {
);
}

require $loader;
$l = require $loader;

if (class_exists(Tuner::class)) {
Tuner::init($l);
}


$application = new Application('Stamp', '1.0.0');
$application->setCatchExceptions(true);
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
}
],
"require": {
"linkorb/loader": "^1.0",
"symfony/console": "^3.0|^4.0",
"symfony/dotenv": "^3.0|^4.0",
"symfony/expression-language": "^4.2",
Expand All @@ -26,7 +27,11 @@
},
"license": "MIT",
"require-dev": {
"linkorb/autotune": "^1.2",
"phpunit/phpunit": "^7"
},
"config": {
"sort-packages": true
},
"bin": ["bin/stamp"]
}
Loading

0 comments on commit 6c9bfa8

Please sign in to comment.