Skip to content

Commit 65a4019

Browse files
committed
initial commit
0 parents  commit 65a4019

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Dave Olsen, http://dmolsen.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
![license](https://img.shields.io/github/license/pattern-lab/plugin-php-data-inheritance.svg?maxAge=2592000)
2+
[![Packagist](https://img.shields.io/packagist/v/pattern-lab/plugin-data-inheritance.svg?maxAge=2592000)](https://packagist.org/packages/pattern-lab/plugin-data-inheritance) [![Gitter](https://img.shields.io/gitter/room/pattern-lab/php.svg?maxAge=2592000)](https://gitter.im/pattern-lab/php)
3+
4+
# Data Inheritance Plugin for Pattern Lab
5+
6+
The Data Inheritance Plugin forces patterns to inherit data from their lineage. This allows data in included patterns to bubble
7+
to the top of the pattern stack. With this plugin pseudo-patterns become first-class citizens.
8+
9+
This is a crap intro. Rewrite it.
10+
11+
## Installation
12+
13+
To add the Data Inheritance Plugin to your project using [Composer](https://getcomposer.org/) type:
14+
15+
composer require pattern-lab/plugin-data-inheritance
16+
17+
See Packagist for [information on the latest release](https://packagist.org/packages/pattern-lab/plugin-data-inheritance).
18+
19+
## Usage
20+
21+
After install make sure to generate your site again with:
22+
23+
php core/console --generate
24+
25+
26+
## Disabling the Plugin
27+
28+
To disable the Faker plugin you can either directly edit `./config/config.yml` or use the command line option:
29+
30+
php core/console --config --set plugins.dataInheritance.enabled=false

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "pattern-lab/plugin-data-inheritance",
3+
"description": "Data inheritance based on pattern lineage for Pattern Lab.",
4+
"keywords": ["data", "inheritance", "lineage", "pattern lab"],
5+
"homepage": "http://patternlab.io",
6+
"license": "MIT",
7+
"type": "patternlab-plugin",
8+
"authors": [
9+
{
10+
"name": "Dave Olsen",
11+
"email": "[email protected]",
12+
"homepage": "http://dmolsen.com",
13+
"role": "Lead Developer"
14+
}
15+
],
16+
"support": {
17+
"issues": "https://github.com/pattern-lab/plugin-php-data-inheritance/issues",
18+
"wiki": "http://patternlab.io/docs/",
19+
"source": "https://github.com/pattern-lab/plugin-php-data-inheritance/releases"
20+
},
21+
"autoload": {
22+
"psr-0": {
23+
"PatternLab\\DataInheritance": "src/"
24+
}
25+
},
26+
"require": {
27+
"php": ">=5.4",
28+
"pattern-lab/core": "^2.4.0"
29+
},
30+
"extra": {
31+
"patternlab": {
32+
"config": {
33+
"plugins": {
34+
"dataInheritance": {
35+
"enabled": true
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*!
4+
* Faker Listener Class
5+
*
6+
* Copyright (c) 2016 Dave Olsen, http://dmolsen.com
7+
* Licensed under the MIT license
8+
*
9+
* Adds Faker support to Pattern Lab
10+
*
11+
*/
12+
13+
namespace PatternLab\DataInheritance;
14+
15+
use \PatternLab\Config;
16+
use \PatternLab\PatternData;
17+
18+
class PatternLabListener extends \PatternLab\Listener {
19+
20+
/**
21+
* Add the listeners for this plug-in
22+
*/
23+
public function __construct() {
24+
25+
// add listener
26+
$this->addListener("patternData.lineageHelperEnd","inherit");
27+
28+
}
29+
30+
/**
31+
* Fake some content. Replace the entire store.
32+
*/
33+
public function inherit() {
34+
35+
if ((bool)Config::getOption("plugins.dataInheritance.enabled")) {
36+
37+
$store = PatternData::get();
38+
39+
foreach ($store as $patternStoreKey => $patternData) {
40+
41+
if (count($patternData["lineages"]) > 0) {
42+
43+
$data = PatternData::getPatternOption($patternStoreKey, "data");
44+
45+
foreach($patternData["lineages"] as $lineage) {
46+
47+
$lineageData = PatternData::getPatternOption($lineage["lineagePattern"], "data");
48+
$data = array_replace_recursive($data, $lineageData);
49+
50+
}
51+
52+
PatternData::setPatternOption($patternStoreKey, "data", $data);
53+
54+
}
55+
56+
}
57+
58+
}
59+
60+
}
61+
62+
}

0 commit comments

Comments
 (0)