public function testFormattingVariables() { $styleGuide = new StyleGuide(); $foo = $styleGuide->formatVariable('foo'); $this->assertSame('foo', $foo, 'formatVariable does not return what you pass in'); $styleGuide = new StyleGuide(); $foobar = $styleGuide->formatVariable('bar', 'foo{0}'); $this->assertSame('foobar', $foobar, 'formatVariable does not merge fields in correctly'); $styleGuide = new StyleGuide(); $foobarbaz = $styleGuide->formatVariable(array('foo', 'bar', 'baz'), '{0} {1} {2}'); $this->assertSame('foo bar baz', $foobarbaz, 'formatVariable does not merge fields in correctly'); $mockConfig = array('foo' => 'bar'); $styleGuide = new StyleGuide($mockConfig); $configFoo = $styleGuide->formatConfigVariable('foo', '{0}'); $this->assertSame('bar', $configFoo, 'formatConfigVariable does not merge config variables correctly'); $mockConfig = array('foo' => 'bar'); $styleGuide = new StyleGuide($mockConfig); $configBaz = $styleGuide->formatConfigVariable('baz', 'no baz here --> {0}'); $this->assertSame('no baz here --> ', $configBaz, 'formatConfigVariable does not default invalid config variable keys to an empty string'); $mockConfig = array('foo' => array('bar', 'baz')); $styleGuide = new StyleGuide($mockConfig); $configBarBaz = $styleGuide->formatConfigVariable('foo', '{0}'); $this->assertSame('bar' . PHP_EOL . 'baz', $configBarBaz, 'formatConfigVariable does not default invalid config variable keys to an empty string'); }
<?php //CUSTOM PROJECT ROOT PER INSTALL $PROJECT_ROOT = realpath('..'); require_once $PROJECT_ROOT . '/vendor/autoload.php'; use Mindgruve\StyleGuide; //GET CONFIG $config = parse_ini_file($PROJECT_ROOT . '/config/mgStyleGuide.ini'); //RESOLVE RELATIVE MARKUP PATH if (array_key_exists('markupPath', $config)) { if (strpos($config['markupPath'], '/') !== 0) { $config['markupPath'] = realpath($PROJECT_ROOT . '/' . $config['markupPath']); } } //SHOW SOURCE CODE COLLAPSING BLOCK $showSource = !!@$_GET['dev'] || !!@$_GET['source']; $styleGuide = new StyleGuide($config); $template = array_key_exists('template', $_GET) ? $_GET['template'] : ''; if ($styleGuide->templateExists($template . '.html')) { echo $styleGuide->render('base', array('static_html' => $template . '.html')); } elseif ($styleGuide->templateExists($template . '.html.twig')) { echo $styleGuide->render('base', array('static_html' => $template . '.html.twig')); } else { echo $styleGuide->render('index', array('showSource' => $showSource, 'useMinified' => true)); }