├── .gitignore ├── LICENSE.md ├── README.md ├── base16-build-all.sh ├── base16-builder.php ├── composer.json └── composer.lock /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | schemes 3 | templates 4 | output 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Base16 Builder PHP is released under the MIT License: 2 | 3 | Copyright (C) [Chris Kempson](https://github.com/chriskempson) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Base16 Builder PHP 2 | A PHP implementation of a _Base16 Builder_ that follows the guidelines at [Base16](https://github.com/chriskempson/base16). 3 | 4 | ## Installation 5 | 6 | git clone https://github.com/chriskempson/base16-builder-php 7 | cd base16-builder-php 8 | composer install 9 | 10 | You'll need to obtain some [scheme files](https://github.com/chriskempson/base16-schemes) and [template files](https://github.com/chriskempson/base16-templates) before you can run the Builder. For example: 11 | 12 | git clone https://github.com/chriskempson/base16-tomorrow-scheme schemes 13 | git clone https://github.com/chriskempson/base16-vim-template schemes 14 | ## Usage 15 | cat scheme.yaml | php base16-builder.php --template template.mustache > theme.file 16 | Updates all scheme and template repositories as defined in `schemes.yaml` and `templates.yaml`. 17 | 18 | ./build-all.sh 19 | Build everything using all schemes in `./schemes/` and all templates in `/.templates/`. -------------------------------------------------------------------------------- /base16-build-all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Base16 Build All 3 | # Chris Kempson (https://github.com/chriskempson) 4 | 5 | schemes_path="schemes" 6 | templates_path="templates" 7 | output_path="output" 8 | 9 | # Loop over template files 10 | find "$templates_path" -name "*.mustache" | sort | while read template_file; do 11 | [ -f "$template_file" ] || continue 12 | 13 | # Resolve filenames and directories 14 | template=$(echo $(basename ${template_file}) | sed "s/.mustache//") 15 | ouput_dirs=$(echo $(dirname ${template_file}) | sed "s/"$templates_path"\///") 16 | 17 | # Remove any old files 18 | rm -f "$output_path/$ouput_dirs/"*."$template" 19 | 20 | # Loop over scheme files 21 | find "$schemes_path" -name "*.yaml" | sort | while read scheme_file; do 22 | [ -f "$scheme_file" ] || continue 23 | 24 | # Resolve filenames and directories 25 | scheme=$(echo $(basename ${scheme_file}) | sed "s/.yaml//") 26 | output_file=$output_path/$ouput_dirs/$scheme.$template 27 | 28 | # Ensure directories exists or create them 29 | mkdir -p "$output_path/$ouput_dirs" 30 | 31 | # Parse scheme and template file and write theme 32 | cat "$scheme_file" | php base16-builder.php --template "$template_file" > "$output_file" 33 | echo "Built $output_file" 34 | done 35 | 36 | done -------------------------------------------------------------------------------- /base16-builder.php: -------------------------------------------------------------------------------- 1 | theme.file 7 | 8 | require __DIR__ . '/vendor/autoload.php'; 9 | use Symfony\Component\Yaml\Yaml; 10 | use Mexitek\PHPColors\Color; 11 | 12 | // Read standard input 13 | $scheme_file = ''; 14 | while (FALSE !== ($line = fgets(STDIN))) { $scheme_file .= $line; } 15 | fclose(STDIN); 16 | 17 | // Handle command line arguments 18 | $options = getopt('t:', ['template:']); 19 | $template_file = $options['t'] ?? $options['template'] ?? null; 20 | if (empty($template_file)) { fwrite(STDERR, 'Specify template with -t or --template='); exit; } 21 | 22 | // Parse Scheme YAML 23 | $scheme_data = Yaml::parse($scheme_file); 24 | 25 | // Create scheme and template data 26 | $template_data = buildTagsForTemplate($scheme_data); 27 | 28 | // Render parsed template 29 | fwrite(STDOUT, renderTemplate($template_file, $template_data)); 30 | 31 | /* 32 | * Create variable tags to be used in mustache templates 33 | */ 34 | function buildTagsForTemplate($scheme_data) 35 | { 36 | $tags['scheme-name'] = $scheme_data['scheme']; 37 | $tags['scheme-slug'] = str_replace(' ', '-', strtolower($tags['scheme-name'])); 38 | $tags['scheme-author'] = $scheme_data['author']; 39 | 40 | $bases = array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', 41 | '0A', '0B', '0C', '0D', '0E', '0F'); 42 | 43 | foreach ($bases as $base) { 44 | $base_key = 'base' . $base; 45 | $color = new Color(str_replace('#', '', $scheme_data[$base_key])); 46 | 47 | $tags[$base_key . '-hex'] = $color->getHex(); 48 | $tags[$base_key . '-hex-bgr'] = substr($color->getHex(), 4, 2) . 49 | substr($color->getHex(), 2, 2) . substr($color->getHex(), 0, 2); 50 | $tags[$base_key . '-hex-r'] = substr($color->getHex(), 0, 2); 51 | $tags[$base_key . '-hex-g'] = substr($color->getHex(), 2, 2); 52 | $tags[$base_key . '-hex-b'] = substr($color->getHex(), 4, 2); 53 | $tags[$base_key . '-rgb-r'] = $color->getRgb()['R']; 54 | $tags[$base_key . '-rgb-g'] = $color->getRgb()['G']; 55 | $tags[$base_key . '-rgb-b'] = $color->getRgb()['B']; 56 | $tags[$base_key . '-dec-r'] = $color->getRgb()['R'] / 255; 57 | $tags[$base_key . '-dec-g'] = $color->getRgb()['G'] / 255; 58 | $tags[$base_key . '-dec-b'] = $color->getRgb()['B'] / 255; 59 | $tags[$base_key . '-hsl-h'] = $color->getHsl()['H']; 60 | $tags[$base_key . '-hsl-s'] = $color->getHsl()['S']; 61 | $tags[$base_key . '-hsl-l'] = $color->getHsl()['L']; 62 | } 63 | 64 | return $tags; 65 | } 66 | 67 | /* 68 | * Renders a template using Mustache 69 | */ 70 | function renderTemplate($path, $template_tags) 71 | { 72 | $mustache = new \Mustache_Engine(); 73 | $mustache = $mustache->loadTemplate(file_get_contents($path)); 74 | 75 | return $mustache->render($template_tags); 76 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "symfony/yaml": "^6.1", 4 | "mustache/mustache": "^2.9", 5 | "mexitek/phpcolors": "dev-master" 6 | }, 7 | "autoload": { 8 | "psr-4": {"Base16\\": "src/"} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "ea7b4443735eb7530f8a8f2283d2a0b6", 8 | "packages": [ 9 | { 10 | "name": "mexitek/phpcolors", 11 | "version": "dev-master", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/mexitek/phpColors.git", 15 | "reference": "346837f2838ef584d5515cb72e7d8af56109893d" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/mexitek/phpColors/zipball/346837f2838ef584d5515cb72e7d8af56109893d", 20 | "reference": "346837f2838ef584d5515cb72e7d8af56109893d", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": "^7.2|^8.0" 25 | }, 26 | "require-dev": { 27 | "nette/tester": "^2.3", 28 | "squizlabs/php_codesniffer": "^3.5" 29 | }, 30 | "default-branch": true, 31 | "type": "library", 32 | "autoload": { 33 | "classmap": [ 34 | "src" 35 | ] 36 | }, 37 | "notification-url": "https://packagist.org/downloads/", 38 | "license": [ 39 | "MIT" 40 | ], 41 | "authors": [ 42 | { 43 | "name": "Arlo Carreon", 44 | "homepage": "http://arlocarreon.com", 45 | "role": "creator" 46 | } 47 | ], 48 | "description": "A series of methods that let you manipulate colors. Just incase you ever need different shades of one color on the fly.", 49 | "homepage": "https://github.com/mexitek/phpColors", 50 | "keywords": [ 51 | "color", 52 | "css", 53 | "design", 54 | "frontend", 55 | "ui" 56 | ], 57 | "support": { 58 | "issues": "https://github.com/mexitek/phpColors/issues", 59 | "source": "https://github.com/mexitek/phpColors" 60 | }, 61 | "time": "2022-05-26T01:34:53+00:00" 62 | }, 63 | { 64 | "name": "mustache/mustache", 65 | "version": "v2.14.1", 66 | "source": { 67 | "type": "git", 68 | "url": "https://github.com/bobthecow/mustache.php.git", 69 | "reference": "579ffa5c96e1d292c060b3dd62811ff01ad8c24e" 70 | }, 71 | "dist": { 72 | "type": "zip", 73 | "url": "https://api.github.com/repos/bobthecow/mustache.php/zipball/579ffa5c96e1d292c060b3dd62811ff01ad8c24e", 74 | "reference": "579ffa5c96e1d292c060b3dd62811ff01ad8c24e", 75 | "shasum": "" 76 | }, 77 | "require": { 78 | "php": ">=5.2.4" 79 | }, 80 | "require-dev": { 81 | "friendsofphp/php-cs-fixer": "~1.11", 82 | "phpunit/phpunit": "~3.7|~4.0|~5.0" 83 | }, 84 | "type": "library", 85 | "autoload": { 86 | "psr-0": { 87 | "Mustache": "src/" 88 | } 89 | }, 90 | "notification-url": "https://packagist.org/downloads/", 91 | "license": [ 92 | "MIT" 93 | ], 94 | "authors": [ 95 | { 96 | "name": "Justin Hileman", 97 | "email": "justin@justinhileman.info", 98 | "homepage": "http://justinhileman.com" 99 | } 100 | ], 101 | "description": "A Mustache implementation in PHP.", 102 | "homepage": "https://github.com/bobthecow/mustache.php", 103 | "keywords": [ 104 | "mustache", 105 | "templating" 106 | ], 107 | "support": { 108 | "issues": "https://github.com/bobthecow/mustache.php/issues", 109 | "source": "https://github.com/bobthecow/mustache.php/tree/v2.14.1" 110 | }, 111 | "time": "2022-01-21T06:08:36+00:00" 112 | }, 113 | { 114 | "name": "symfony/polyfill-ctype", 115 | "version": "v1.26.0", 116 | "source": { 117 | "type": "git", 118 | "url": "https://github.com/symfony/polyfill-ctype.git", 119 | "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4" 120 | }, 121 | "dist": { 122 | "type": "zip", 123 | "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", 124 | "reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4", 125 | "shasum": "" 126 | }, 127 | "require": { 128 | "php": ">=7.1" 129 | }, 130 | "provide": { 131 | "ext-ctype": "*" 132 | }, 133 | "suggest": { 134 | "ext-ctype": "For best performance" 135 | }, 136 | "type": "library", 137 | "extra": { 138 | "branch-alias": { 139 | "dev-main": "1.26-dev" 140 | }, 141 | "thanks": { 142 | "name": "symfony/polyfill", 143 | "url": "https://github.com/symfony/polyfill" 144 | } 145 | }, 146 | "autoload": { 147 | "files": [ 148 | "bootstrap.php" 149 | ], 150 | "psr-4": { 151 | "Symfony\\Polyfill\\Ctype\\": "" 152 | } 153 | }, 154 | "notification-url": "https://packagist.org/downloads/", 155 | "license": [ 156 | "MIT" 157 | ], 158 | "authors": [ 159 | { 160 | "name": "Gert de Pagter", 161 | "email": "BackEndTea@gmail.com" 162 | }, 163 | { 164 | "name": "Symfony Community", 165 | "homepage": "https://symfony.com/contributors" 166 | } 167 | ], 168 | "description": "Symfony polyfill for ctype functions", 169 | "homepage": "https://symfony.com", 170 | "keywords": [ 171 | "compatibility", 172 | "ctype", 173 | "polyfill", 174 | "portable" 175 | ], 176 | "support": { 177 | "source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0" 178 | }, 179 | "funding": [ 180 | { 181 | "url": "https://symfony.com/sponsor", 182 | "type": "custom" 183 | }, 184 | { 185 | "url": "https://github.com/fabpot", 186 | "type": "github" 187 | }, 188 | { 189 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", 190 | "type": "tidelift" 191 | } 192 | ], 193 | "time": "2022-05-24T11:49:31+00:00" 194 | }, 195 | { 196 | "name": "symfony/yaml", 197 | "version": "v6.1.2", 198 | "source": { 199 | "type": "git", 200 | "url": "https://github.com/symfony/yaml.git", 201 | "reference": "b01c4e7dc6a51cbf114567af04a19789fd1011fe" 202 | }, 203 | "dist": { 204 | "type": "zip", 205 | "url": "https://api.github.com/repos/symfony/yaml/zipball/b01c4e7dc6a51cbf114567af04a19789fd1011fe", 206 | "reference": "b01c4e7dc6a51cbf114567af04a19789fd1011fe", 207 | "shasum": "" 208 | }, 209 | "require": { 210 | "php": ">=8.1", 211 | "symfony/polyfill-ctype": "^1.8" 212 | }, 213 | "conflict": { 214 | "symfony/console": "<5.4" 215 | }, 216 | "require-dev": { 217 | "symfony/console": "^5.4|^6.0" 218 | }, 219 | "suggest": { 220 | "symfony/console": "For validating YAML files using the lint command" 221 | }, 222 | "bin": [ 223 | "Resources/bin/yaml-lint" 224 | ], 225 | "type": "library", 226 | "autoload": { 227 | "psr-4": { 228 | "Symfony\\Component\\Yaml\\": "" 229 | }, 230 | "exclude-from-classmap": [ 231 | "/Tests/" 232 | ] 233 | }, 234 | "notification-url": "https://packagist.org/downloads/", 235 | "license": [ 236 | "MIT" 237 | ], 238 | "authors": [ 239 | { 240 | "name": "Fabien Potencier", 241 | "email": "fabien@symfony.com" 242 | }, 243 | { 244 | "name": "Symfony Community", 245 | "homepage": "https://symfony.com/contributors" 246 | } 247 | ], 248 | "description": "Loads and dumps YAML files", 249 | "homepage": "https://symfony.com", 250 | "support": { 251 | "source": "https://github.com/symfony/yaml/tree/v6.1.2" 252 | }, 253 | "funding": [ 254 | { 255 | "url": "https://symfony.com/sponsor", 256 | "type": "custom" 257 | }, 258 | { 259 | "url": "https://github.com/fabpot", 260 | "type": "github" 261 | }, 262 | { 263 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", 264 | "type": "tidelift" 265 | } 266 | ], 267 | "time": "2022-06-20T12:01:07+00:00" 268 | } 269 | ], 270 | "packages-dev": [], 271 | "aliases": [], 272 | "minimum-stability": "stable", 273 | "stability-flags": { 274 | "mexitek/phpcolors": 20 275 | }, 276 | "prefer-stable": false, 277 | "prefer-lowest": false, 278 | "platform": [], 279 | "platform-dev": [], 280 | "plugin-api-version": "2.3.0" 281 | } 282 | --------------------------------------------------------------------------------