├── docs ├── bblueprint.md ├── bfile.md ├── bparse.md ├── bread.md ├── cache.md ├── changelog.md ├── compare.md ├── install.md └── options.md ├── kirby-blueprint-reader.php ├── lib ├── api.php ├── cache.php ├── definitions.php ├── language.php ├── method-blueprint.php ├── method-read.php ├── methods.php └── read.php ├── license.md ├── package.json └── readme.md /docs/bblueprint.md: -------------------------------------------------------------------------------- 1 | # b::blueprint() 2 | 3 | Get a blueprint data array by a blueprint name. 4 | 5 | - **$name** (string) 6 | *Path to the blueprint file* 7 | - **$steps** (string)(optional) 8 | *Step the array to get your value.* 9 | - **$options** (array)(optional) 10 | - **$format** (array) 11 | *The format can be filepath or data. Default is data.* 12 | - **$language** (string) 13 | *The language of the fields. If no language is set, it will show all languages.* 14 | - **$definitions** (bool) 15 | *Turn global field definitions off by set it to false. It's set to true by default.* 16 | - **return** (array) 17 | *It will return an array with blueprint data if found, else it will return null.* 18 | 19 | ### Basic examples 20 | 21 | We use the blueprint name to get the blueprint data as array: 22 | 23 | ```php 24 | $data = b::blueprint('project'); 25 | print_r($data); 26 | ``` 27 | 28 | We can also use the step feature as second argument, to get the field title type and print it out. 29 | 30 | ```php 31 | echo b::blueprint('project', 'fields/title/type'); 32 | ``` 33 | 34 | ### Advanced example 35 | 36 | In this case we don't use the steps feature. Instead of having steps as a second argument we can set options as second argument instead. 37 | 38 | ```php 39 | $options = array( 40 | 'language' => 'sv', 41 | 'definitions' => false 42 | ); 43 | 44 | $data = b::blueprint('project', $options); 45 | print_r($data); 46 | ``` 47 | 48 | To also use steps, we set it as the second argument and push the options to the third argument: 49 | 50 | ```php 51 | $options = array( 52 | 'language' => 'sv', 53 | 'definitions' => false 54 | ); 55 | 56 | echo b::blueprint('project', 'fields/title/type', $options); 57 | ``` -------------------------------------------------------------------------------- /docs/bfile.md: -------------------------------------------------------------------------------- 1 | # b::file() 2 | 3 | Get a filepath by a blueprint name. 4 | 5 | - **$name** (string) 6 | *Path to the blueprint file* 7 | - **return** (array) 8 | *It will return a blueprint filepath if found, else it will return null.* 9 | 10 | ### Basic example 11 | 12 | We use the blueprint name to get the blueprint filepath: 13 | 14 | ```php 15 | echo b::file('project'); 16 | ``` -------------------------------------------------------------------------------- /docs/bparse.md: -------------------------------------------------------------------------------- 1 | # b::parse() 2 | 3 | Get a parsed blueprint data array by an own blueprint data array. It will include global field defintions, extends and translations. 4 | 5 | - **$data** (array) 6 | *Path to the blueprint file* 7 | - **$steps** (string)(optional) 8 | *Step the array to get your value.* 9 | - **$options** (array)(optional) 10 | - **$language** (string) 11 | *The language of the fields. If no language is set, it will show all languages.* 12 | - **$definitions** (bool) 13 | *Turn global field definitions off by set it to false. It's set to true by default.* 14 | - **return** (array) 15 | *It will return an array with blueprint data if found, else it will return null.* 16 | 17 | ### Basic examples 18 | 19 | We use an own blueprint data array. Then we run it through the parser to include global field definitions, extends and translations. 20 | 21 | ```php 22 | $data = array( 23 | 'title' => 'My page', 24 | 'fields' => array( 25 | 'title' => array( 26 | 'label' => array( 27 | 'sv' => 'Hej världen!', 28 | 'en' => 'Hello world!', 29 | ), 30 | 'type' => 'title', 31 | ) 32 | ) 33 | ); 34 | 35 | $data = b::parse($data); 36 | print_r($data); 37 | ``` 38 | 39 | We can also use the step feature as second argument, to get the field title type and print it out. 40 | 41 | ```php 42 | echo b::parse('project', 'fields/title/type'); 43 | ``` 44 | 45 | ### Advanced example 46 | 47 | In this case we don't use the steps feature. Instead of having steps as a second argument we can set options as second argument instead. 48 | 49 | ```php 50 | $data = array( 51 | 'title' => 'My page', 52 | 'fields' => array( 53 | 'title' => array( 54 | 'label' => array( 55 | 'sv' => 'Hej världen!', 56 | 'en' => 'Hello world!', 57 | ), 58 | 'type' => 'title', 59 | ) 60 | ) 61 | ); 62 | 63 | $options = array( 64 | 'language' => 'sv', 65 | 'definitions' => false 66 | ); 67 | 68 | $data = b::parse('project', $options); 69 | print_r($data); 70 | ``` 71 | 72 | To also use steps, we set it as the second argument and push the options to the third argument: 73 | 74 | ```php 75 | $data = array( 76 | 'title' => 'My page', 77 | 'fields' => array( 78 | 'title' => array( 79 | 'label' => array( 80 | 'sv' => 'Hej världen!', 81 | 'en' => 'Hello world!', 82 | ), 83 | 'type' => 'title', 84 | ) 85 | ) 86 | ); 87 | 88 | $options = array( 89 | 'language' => 'sv', 90 | 'definitions' => false 91 | ); 92 | 93 | echo b::parse('project', 'fields/title/type', $options); 94 | ``` -------------------------------------------------------------------------------- /docs/bread.md: -------------------------------------------------------------------------------- 1 | # b::read() 2 | 3 | Get a blueprint data array by a blueprint filepath. 4 | 5 | - **$filepath** (string) 6 | *Path to the blueprint file* 7 | - **$steps** (string)(optional) 8 | *Step the array to get your value.* 9 | - **$options** (array)(optional) 10 | - **$cache_key** (string) 11 | *Name of the cache key. If no cache key name is set, it will use the filename.* 12 | - **$language** (string) 13 | *The language of the fields. If no language is set, it will show all languages.* 14 | - **$definitions** (bool) 15 | *Turn global field definitions off by set it to false. It's set to true by default.* 16 | - **return** (array) 17 | *It will return an array with blueprint data if found, else it will return null.* 18 | 19 | ### Basic examples 20 | 21 | We use the filepath to get the blueprint data as array: 22 | 23 | ```php 24 | $data = b::read('C:\xampp\htdocs\kirby\site\blueprints\project.yml'); 25 | print_r($data); 26 | ``` 27 | 28 | We can also use the step feature as second argument, to get the field title type and print it out. 29 | 30 | ```php 31 | echo b::read('C:\xampp\htdocs\kirby\site\blueprints\project.yml', 'fields/title/type'); 32 | ``` 33 | 34 | ### Advanced example 35 | 36 | In this case we don't use the steps feature. Instead of having steps as a second argument we can set options as second argument instead. 37 | 38 | ```php 39 | $options = array( 40 | 'cache_key' => 'my-cache-key', 41 | 'language' => 'sv', 42 | 'definitions' => false 43 | ); 44 | 45 | $data = b::read('C:\xampp\htdocs\kirby\site\blueprints\project.yml', $options); 46 | print_r($data); 47 | ``` 48 | 49 | To also use steps, we set it as the second argument and push the options to the third argument: 50 | 51 | ```php 52 | $options = array( 53 | 'cache_key' => 'my-cache-key', 54 | 'language' => 'sv', 55 | 'definitions' => false 56 | ); 57 | 58 | echo b::read('C:\xampp\htdocs\kirby\site\blueprints\project.yml', 'fields/title/type', $options); 59 | ``` -------------------------------------------------------------------------------- /docs/cache.md: -------------------------------------------------------------------------------- 1 | # Cache 2 | 3 | The blueprint reader has a built in memory cache. You don't need to do anything to set it up. It's always working behind the scenes and does not save any files because it's stored in the memory. 4 | 5 | ## Cached types 6 | 7 | There are three different types of data that will be cached: 8 | 9 | - [x] Blueprint data `blueprint.reader.data` 10 | - [x] Blueprint filepaths `blueprint.reader.files` 11 | - [x] Global field definitions `blueprint.reader.definitions` 12 | 13 | ### Storage 14 | 15 | The cached data is stored in the memory. After your function calls are made you can look at your cache. 16 | 17 | ```php 18 | print_r(kirby()->get('option', 'blueprint.reader.data')); 19 | print_r(kirby()->get('option', 'blueprint.reader.files')); 20 | print_r(kirby()->get('option', 'blueprint.reader.definitions')); 21 | ``` 22 | 23 | ### Blueprint data 24 | 25 | This cache stores the full blueprint arrays, if you have used the `b::blueprint()`. 26 | 27 | ### Blueprint filepaths 28 | 29 | This cache stores the blueprint filepaths, if you have used the `b::read()` method. 30 | 31 | ### Global field definitions 32 | 33 | This cache stores the blueprint global field definitions. All the methods that returns the blueprint data array will parse the global field definitions. -------------------------------------------------------------------------------- /docs/changelog.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | **0.4** 4 | 5 | - Support for translations. 6 | - Support for users blueprints with `users/blueprint`. 7 | - Support for multiple caches separated by return type. 8 | - Support for array step like `fields/title/type`. 9 | - Support for global options. 10 | - Support for `.yaml` and `.php` extensions. 11 | - Changed syntax from `bread::` to `b::`. 12 | - Changed arguments. Steps added and options is now an array. 13 | - Changed `b::file()` to use filename as cache-key instead of path as default. 14 | - Changed the behavior of the `$name` argument, which does no longer fallback to `default.yml`. 15 | - Docs changed. 16 | - Bugfixes and code enhancements. 17 | 18 | **0.3** 19 | 20 | - Fixed major bug with singleton class. 21 | - Fixed major bug with `bread::parse()`. 22 | - Added support for global field definitions in structure fields. 23 | - Added support for global field definitions extends in structure fields. 24 | - Added [compare](compare.md) to Kirby Architect. 25 | 26 | **0.2** 27 | 28 | - Complete rewrite 29 | 30 | **0.1** 31 | 32 | - Initial release -------------------------------------------------------------------------------- /docs/compare.md: -------------------------------------------------------------------------------- 1 | # Kirby Blueprint Reader VS Kirby Architect 2 | 3 | Because [Kirby Architect](https://github.com/AugustMiller/kirby-architect) is the only competitor, I have made a comparation table for both plugins. 4 | 5 | | Feature | Blueprint Reader | Architect 6 | | -------------------------------------------------------- | ---------------- | --------- 7 | | Support for global field definitions | Yes | - 8 | | Support for global field extends | Yes | - 9 | | Support for definitions and extends in structure fields | Yes | - 10 | | Method to get the label | - | Yes 11 | | Method to get an option label | - | Yes 12 | | Method to get options | - | Yes 13 | | Method to generate a menu | - | Yes 14 | | Method to blacklist values | - | Yes 15 | | Method to step in the array | Yes | - 16 | | Method to get the blueprint filepath by template | Yes | - 17 | | Method to get the blueprint data by a filepath | Yes | - 18 | | Method to parse a blueprint array | Yes | - 19 | 20 | ## Summery 21 | 22 | Which one you need depends on your needs. They are very different in what you can do and how things work and how the syntax looks like. 23 | 24 | **[Kirby Blueprint Reader](https://github.com/jenstornell/kirby-blueprint-reader)** 25 | It's probably better for reading and parsing as it supports global field definitions, extends, structure fields and array stepping. 26 | 27 | **[Kirby Architect](https://github.com/AugustMiller/kirby-architect)** 28 | It's probably better for help with generating html as it supports methods for menus, options and labels. -------------------------------------------------------------------------------- /docs/install.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Use one of the alternatives below. 4 | 5 | ## 1. Kirby CLI 6 | 7 | If you are using the [Kirby CLI](https://github.com/getkirby/cli) you can install this plugin by running the following commands in your shell: 8 | 9 | ``` 10 | $ cd path/to/kirby 11 | $ kirby plugin:install jenstornell/kirby-blueprint-reader 12 | ``` 13 | 14 | ## 2. Clone or download 15 | 16 | 1. [Clone](https://github.com/jenstornell/kirby-blueprint-reader.git) or [download](https://github.com/jenstornell/kirby-blueprint-reader/archive/master.zip) this repository. 17 | 2. Unzip the archive if needed and rename the folder to `kirby-blueprint-reader`. 18 | 19 | **Make sure that the plugin folder structure looks like this:** 20 | 21 | ``` 22 | site/plugins/kirby-blueprint-reader/ 23 | ``` 24 | 25 | ## 3. Git Submodule 26 | 27 | If you know your way around Git, you can download this plugin as a submodule: 28 | 29 | ``` 30 | $ cd path/to/kirby 31 | $ git submodule add https://github.com/jenstornell/kirby-blueprint-reader site/plugins/kirby-blueprint-reader 32 | ``` -------------------------------------------------------------------------------- /docs/options.md: -------------------------------------------------------------------------------- 1 | # Options 2 | 3 | ```php 4 | c::set('blueprint.reader.language', null); 5 | c::set('blueprint.reader.definitions', true); 6 | c::set('blueprint.reader.format', 'array'); 7 | ``` 8 | 9 | ### blueprint.reader.language 10 | 11 | Blueprint fallback language if no `language` argument is sent. It defaults to `null` which will show all translated values. 12 | 13 | ### blueprint.reader.definitions 14 | 15 | You can enable or disable global field definitions by sending an argument to the function, or use this option as fallback. It defaults to `true` which means that global fields definitions will be included. 16 | 17 | ### blueprint.reader.format 18 | 19 | The blueprint format that your blueprint will be returned. It can be `array` or `filepath`. -------------------------------------------------------------------------------- /kirby-blueprint-reader.php: -------------------------------------------------------------------------------- 1 | get($options, $steps_options, $steps); 17 | return $data; 18 | } 19 | 20 | public static function read($filepath, $steps_options = array(), $options = array()) { 21 | $Read = new BlueprintReader\MethodRead(); 22 | $steps = array(); 23 | 24 | if(is_string($steps_options)) { 25 | $steps = explode('/', $steps_options); 26 | } else { 27 | $options = $steps_options; 28 | } 29 | 30 | $options['filepath'] = $filepath; 31 | return $Read->get($options, $steps_options, $steps); 32 | } 33 | 34 | public static function file($template, $options = array()) { 35 | $options['format'] = 'filepath'; 36 | return self::blueprint($template, $options); 37 | } 38 | 39 | public static function parse($data, $steps_options = array(), $options = array()) { 40 | $steps = array(); 41 | 42 | if(is_string($steps_options)) { 43 | $steps = explode('/', $steps_options); 44 | } else { 45 | $options = $steps_options; 46 | } 47 | 48 | $options = BlueprintReader\fallbackOptions($options); 49 | $data = BlueprintReader\parse($data, $options); 50 | 51 | if(is_string($steps_options) && $format != 'filepath') { 52 | $data = steps($steps, $data); 53 | } 54 | 55 | return $data; 56 | } 57 | } -------------------------------------------------------------------------------- /lib/cache.php: -------------------------------------------------------------------------------- 1 | kirby = $kirby; 8 | } 9 | 10 | function getOption($option) { 11 | return $this->kirby->get('option', $option); 12 | } 13 | 14 | function get($template, $option) { 15 | $cache = $this->getOption($option); 16 | if(isset($cache[$template])) { 17 | return $cache[$template]; 18 | } 19 | } 20 | 21 | function set($template, $data, $option) { 22 | $cache = $this->getOption($option); 23 | $cache[$template] = $data; 24 | $this->kirby->set('option', $option, $cache); 25 | return $data; 26 | } 27 | } -------------------------------------------------------------------------------- /lib/definitions.php: -------------------------------------------------------------------------------- 1 | kirby = $kirby; 10 | $array = $this->walkField($array); 11 | return $array; 12 | } 13 | 14 | function walkField($array) { 15 | if(array_key_exists('fields', $array)) { 16 | foreach($array['fields'] as $key => $field) { 17 | if(is_string($field)) { 18 | $array['fields'][$key] = $this->setDefinition($field, $key); 19 | } elseif(is_array($field)) { 20 | if(!empty($field['extends'])) { 21 | $array['fields'][$key] = $this->setExtends($field, $key); 22 | } 23 | $array = $this->walkStructure($field, $key, $array); 24 | } 25 | } 26 | } 27 | return $array; 28 | } 29 | 30 | function walkStructure($field, $key, $array) { 31 | if(array_key_exists('fields', $field)) { 32 | foreach($field['fields'] as $key2 => $item) { 33 | if(is_string($item)) { 34 | $array['fields'][$key]['fields'][$key2] = $this->setDefinition($item, $key2); 35 | } elseif(is_array($item)) { 36 | if(!empty($item['extends'])) { 37 | $array['fields'][$key]['fields'][$key2] = $this->setExtends($item, $key2); 38 | } 39 | } 40 | } 41 | } 42 | return $array; 43 | } 44 | 45 | function setExtends($part, $key) { 46 | $buffer = $part; unset($buffer['extends']); 47 | return array_merge($this->cache($part['extends']), $buffer); 48 | } 49 | 50 | function setDefinition($part, $key) { 51 | return $this->cache($part); 52 | } 53 | 54 | function cache($name) { 55 | $Cache = new Cache(); 56 | $cache_key = 'blueprint.reader.definitions'; 57 | 58 | if($Cache->get($name, $cache_key)) { 59 | $data = $Cache->get($name, $cache_key); 60 | 61 | } else { 62 | $data = $this->find($name); 63 | $Cache->set($name, $data, $cache_key); 64 | } 65 | return $data; 66 | } 67 | 68 | function find($field) { 69 | $definition = blueprint('fields/' . $field); 70 | if(isset($definition)) { 71 | return yaml::read($definition); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /lib/language.php: -------------------------------------------------------------------------------- 1 | array = $array; 7 | if(isset($language)) { 8 | global $kirby; 9 | $this->kirby = $kirby; 10 | $this->language = $language; 11 | 12 | $this->walkField(); 13 | } 14 | return $this->array; 15 | } 16 | 17 | function walkField() { 18 | if(is_array($this->array) && array_key_exists('fields', $this->array)) { 19 | foreach($this->array['fields'] as $this->field_key => $field) { 20 | if(is_array($field)) { 21 | $this->depth = 'field'; 22 | $this->setFields(); 23 | $this->walkStructure($field, $this->field_key); 24 | } 25 | } 26 | } 27 | } 28 | 29 | function walkStructure($field) { 30 | if(array_key_exists('fields', $field)) { 31 | if(!empty($field['fields'])) { 32 | foreach($field['fields'] as $this->structure_key => $item) { 33 | if(is_array($item)) { 34 | $this->depth = 'structure'; 35 | $this->setFields(); 36 | } 37 | } 38 | } 39 | } 40 | } 41 | 42 | function setFields() { 43 | foreach(array('label', 'help', 'placeholder') as $key) { 44 | $this->singular($key); 45 | } 46 | $this->headlines(); 47 | $this->options(); 48 | } 49 | 50 | function singular($type) { 51 | $part = $this->getPart(); 52 | 53 | if(isset($part[$type][$this->language])) { 54 | $part[$type] = $part[$type][$this->language]; 55 | } elseif(isset($part[$type]) && is_array($part[$type])) { 56 | $part[$type] = null; 57 | } 58 | 59 | $this->setPart($part); 60 | } 61 | 62 | function getPart() { 63 | $part = $this->array['fields'][$this->field_key]; 64 | if($this->depth == 'structure') { 65 | $part = $part['fields'][$this->structure_key]; 66 | } 67 | return $part; 68 | } 69 | 70 | function setPart($part) { 71 | if($this->depth == 'field') { 72 | $this->array['fields'][$this->field_key] = $part; 73 | } elseif($this->depth == 'structure') { 74 | $this->array['fields'][$this->field_key]['fields'][$this->structure_key] = $part; 75 | } 76 | } 77 | 78 | function options() { 79 | $part = $this->getPart(); 80 | if(isset($part['options']) && is_array($part['options'])) { 81 | if(!empty($part['options'])) { 82 | foreach($part['options'] as $key => $option) { 83 | if(array_key_exists($this->language, $option)) { 84 | $part['options'][$key] = $option[$this->language]; 85 | } else { 86 | $part['options'][$key] = null; 87 | } 88 | } 89 | } 90 | $this->setPart($part); 91 | } 92 | } 93 | 94 | function headlines() { 95 | $part = $this->getPart(); 96 | if(isset($part['type']) && $part['type'] == 'headline') { 97 | if(isset($part['text'][$this->language])) { 98 | $part['text'] = $part['text'][$this->language]; 99 | } elseif(isset($part['text']) && is_array($part['text'])) { 100 | $part['text'] = null; 101 | } 102 | $this->setPart($part); 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /lib/method-blueprint.php: -------------------------------------------------------------------------------- 1 | Cache = new Cache(); 8 | $this->Read = new Read(); 9 | } 10 | function get($options, $steps_options, $steps) { 11 | $options = $this->setArgs($options); 12 | extract($options); 13 | 14 | $cache_key = 'blueprint.reader.' . $format . 's'; 15 | 16 | $cache = $this->Cache->get($template, $cache_key); 17 | 18 | if($cache) { 19 | return $cache; 20 | } else { 21 | $filepath = blueprint($template); 22 | 23 | if($filepath) { 24 | if($format == 'filepath') { 25 | $this->Cache->set($template, $filepath, $cache_key); 26 | return $filepath; 27 | } else { 28 | $options['filepath'] = $filepath; 29 | $data = $this->Read->file($options); 30 | if(is_string($steps_options)) { 31 | $data = steps($steps, $data); 32 | } 33 | $this->Cache->set($template, $data, $cache_key); 34 | return $data; 35 | } 36 | } 37 | } 38 | } 39 | 40 | function setArgs($options) { 41 | extract($options); 42 | $fallbacks = array( 43 | 'template' => $template, 44 | 'format' => fallback($options, 'format', 'data') 45 | ); 46 | return array_merge(fallbackOptions($options), $fallbacks); 47 | } 48 | } -------------------------------------------------------------------------------- /lib/method-read.php: -------------------------------------------------------------------------------- 1 | Cache = new Cache(); 9 | $this->Read = new Read(); 10 | } 11 | function get($options, $steps_options, $steps) { 12 | $options = $this->setArgs($options); 13 | extract($options); 14 | 15 | $cache_key = 'blueprint.reader.data'; 16 | $cache = $this->Cache->get($template, $cache_key); 17 | 18 | if($cache) { 19 | $data = $cache; 20 | } else { 21 | if(f::exists($filepath)) { 22 | $data = $this->Read->file($options); 23 | $this->Cache->set($template, $data, $cache_key); 24 | } 25 | } 26 | if(is_string($steps_options)) { 27 | $data = steps($steps, $data); 28 | } 29 | return $data; 30 | } 31 | 32 | function setArgs($options) { 33 | extract($options); 34 | $fallbacks = array( 35 | 'template' => (isset($cache_key)) ? $cache_key : pathinfo($filepath, PATHINFO_FILENAME), 36 | 'filepath' => $filepath, 37 | ); 38 | return array_merge(fallbackOptions($options), $fallbacks); 39 | } 40 | } -------------------------------------------------------------------------------- /lib/methods.php: -------------------------------------------------------------------------------- 1 | get('blueprint', $name); 16 | $filepath = (is_string($blueprint)) ? $blueprint : null; 17 | return $filepath; 18 | } 19 | 20 | function parse($data, $options) { 21 | $Language = new Language(); 22 | $Definitions = new Definitions(); 23 | 24 | extract($options); 25 | 26 | if($definitions) { 27 | $data = $Definitions->parse($data); 28 | } 29 | $data = $Language->parse($data, $language); 30 | return $data; 31 | } 32 | 33 | function fallbackOptions($options) { 34 | return array( 35 | 'language' => fallback($options, 'language', null), 36 | 'definitions' => fallback($options, 'definitions', true), 37 | ); 38 | } 39 | 40 | function steps($steps, $data) { 41 | foreach($steps as $step) { 42 | if(!isset($data[$step])) { 43 | $data = null; 44 | break; 45 | } 46 | $data = $data[$step]; 47 | } 48 | return $data; 49 | } -------------------------------------------------------------------------------- /lib/read.php: -------------------------------------------------------------------------------- 1 | kirby = $kirby; 9 | $this->Cache = new Cache(); 10 | $this->Language = new Language(); 11 | $this->Definitions = new Definitions(); 12 | } 13 | 14 | function file($options) { 15 | $array = $this->set($options); 16 | return $array; 17 | } 18 | 19 | function set($options) { 20 | $array = yaml::read($options['filepath']); 21 | 22 | $options['language'] = fallback($options, 'language', null); 23 | $options['definitions'] = fallback($options, 'definitions', true); 24 | 25 | $array = parse($array, $options); 26 | 27 | return $array; 28 | } 29 | } -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jens Törnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kirby-blueprint-reader", 3 | "description": "Blueprint Reader for Kirby CMS", 4 | "author": "Jens Törnell ", 5 | "version": "0.4", 6 | "type": "kirby-plugin", 7 | "license": "MIT" 8 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Kirby Blueprint Reader 2 | 3 | A very easy to use blueprint reader for Kirby CMS. 4 | 5 | *Version 0.4* - ***[Changelog](docs/changelog.md)*** 6 | 7 | **Features / Supports** 8 | 9 | - [x] Global field definitions 10 | - [x] Global field extends 11 | - [x] Translated fields 12 | - [x] Structure fields 13 | - [x] Simple array walking 14 | - [x] Caching 15 | 16 | ## Basic examples 17 | 18 | If you have a project blueprint, you can get the title field type by this one-liner: 19 | 20 | ```php 21 | echo b::blueprint('project', 'fields/title/type'); 22 | ``` 23 | 24 | If you want the complete blueprint data array, you can do that like this: 25 | 26 | ```php 27 | $data = b::blueprint('project'); 28 | print_r($data); 29 | ``` 30 | 31 | ## Methods 32 | 33 | These are the methods you can use. Read more about them if you need more advanced configurations. 34 | 35 | - **[b::blueprint](docs/bblueprint.md)($name, $steps, $options = array())** 36 | *Get the blueprint data array by template.* 37 | - **[b::read](docs/bread.md)($filepath, $steps, $options = array())** 38 | *Get the blueprint data array by filepath.* 39 | - **[b::file](docs/bfile.md)($name, $options = array())** 40 | *Get the blueprint filepath by template.* 41 | - **[b::parse](docs/bparse.md)($data, $steps, $options)** 42 | *Get the parsed blueprint data array by blueprint data array.* 43 | 44 | ## Table of contents 45 | 46 | - [Cache](docs/cache.md) 47 | - [Options](docs/options.md) 48 | - [Differences to Kirby Architect](docs/compare.md) 49 | 50 | ## Requirements 51 | 52 | - [**Kirby**](https://getkirby.com/) 2.4.1+ 53 | 54 | ## Disclaimer 55 | 56 | This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/username/kirby-blueprint-reader/issues/new). 57 | 58 | ## License 59 | 60 | [**MIT**](https://opensource.org/licenses/MIT) 61 | 62 | It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech. 63 | 64 | ## Credits 65 | 66 | - [Jens Törnell](https://github.com/jenstornell) 67 | --------------------------------------------------------------------------------