public function getNormalizedPath() { if (!isset($this->normalizedPath)) { $this->normalizedPath = PatternLab::normalizePath($this->getPath()); } return $this->normalizedPath; }
public function jsonSerialize() { $type = PatternLab::stripDigits($this->name); $items = array_values($this->patterns); if (!empty($this->subtypes)) { $items[] = ["patternPath" => "{$this->name}/index.html", "patternName" => "View All", "patternType" => $this->name, "patternSubtype" => "all", "patternPartial" => "viewall-{$type}-all"]; } return ['patternTypeLC' => $this->getLowercaseName(), 'patternTypeUC' => $this->getUppercaseName(), 'patternType' => $this->getName(), 'patternTypeDash' => $this->getNameWithDashes(), 'patternTypeItems' => array_values($this->subtypes), 'patternItems' => $items]; }
protected function makeIndex(PatternLabInterface $patternlab) { $this->index = []; foreach ($patternlab->getPatterns() as $pattern) { $file = $pattern->getFile(); $partial = $pattern->getPartial(); $path = PatternLab::normalizePath($pattern->getPath()); $this->index[$partial] = $file; $this->index[$path] = $file; } }
public function initRuntime(Twig_Environment $environment) { parent::initRuntime($environment); $config = (object) Config::get('patternlab'); $loader = $environment->getLoader(); if (!$loader instanceof Twig_Loader_Chain) { $origLoader = $loader; $loader = new Twig_Loader_Chain([$loader]); $loader->addLoader($origLoader); } $loader->addLoader(new Twig_Loader_Filesystem(base_path() . '/' . $config->twig_ext_path)); $loader->addLoader(new Twig_Loader_Filesystem(base_path() . '/' . $config->layout_path)); $loader->addLoader(new Twig_Loader_Filesystem(base_path() . '/' . $config->views_path)); $labcoatConfig = Styleguide::getConfig(); $patternlab = new LabcoatPatternlab($labcoatConfig); $labcoatLoader = new LabcoatLoader($patternlab); $loader->addLoader($labcoatLoader); $environment->setLoader($loader); $globalData = $patternlab->getGlobalData(); foreach ($globalData as $key => $value) { $environment->addGlobal($key, $value); } }
/** * Get the full path to a style guide template * * @param string $template The relative path of the template * @return string The full template path */ protected function getStyleguideTemplatePath($template) { return PatternLab::makePath([$this->patternlab->getStyleguideTemplatesDirectory(), $template]); }
protected function makePath($path) { $path = (array) $path; array_unshift($path, $this->root); return PatternLab::makePath($path); }
public function __construct($dir) { $configPath = PatternLab::makePath([$dir, 'config', 'config.yml']); if (is_file($configPath)) { $seConfig = Yaml::parse(file_get_contents($configPath)); if (!empty($seConfig['sourceDir'])) { $sourceDir = PatternLab::makePath([$dir, $seConfig['sourceDir']]); if (is_dir($sourceDir)) { $this->addAssetDirectory($sourceDir); $patternsDir = PatternLab::makePath([$sourceDir, '_patterns']); if (is_dir($patternsDir)) { $this->setPatternsDirectory($patternsDir); } $dataDir = PatternLab::makePath([$sourceDir, '_data']); if (is_dir($dataDir)) { foreach (glob(PatternLab::makePath([$dataDir, '*.json'])) as $path) { if (basename($path) == 'listitems.json') { $this->addListItems($path); } else { $this->addGlobalData($path); } } } $annotationsPath = PatternLab::makePath([$sourceDir, '_annotations', 'annotations.js']); if (is_file($annotationsPath)) { $this->setAnnotationsFile($annotationsPath); } $headerPath = PatternLab::makePath([$sourceDir, '_meta', '_00-head.twig']); if (is_file($headerPath)) { $this->setStyleguideHeader($headerPath); } $footerPath = PatternLab::makePath([$sourceDir, '_meta', '_01-foot.twig']); if (is_file($footerPath)) { $this->setStyleguideFooter($footerPath); } } } if (!empty($seConfig['packagesDir'])) { $packagesDir = PatternLab::makePath([$dir, $seConfig['packagesDir']]); if (is_dir($packagesDir)) { $assetsDir = PatternLab::makePath([$packagesDir, 'pattern-lab', 'styleguidekit-assets-default', 'dist']); if (is_dir($assetsDir)) { $this->addStyleguideAssetDirectory($assetsDir); } if (!empty($seConfig['styleguideKit'])) { $templatesDir = PatternLab::makePath([$packagesDir, $seConfig['styleguideKit'], 'views']); if (is_dir($templatesDir)) { $this->setStyleguideTemplatesDirectory($templatesDir); } } } } if (!empty($seConfig['id'])) { $this->setIgnoredDirectories($seConfig['id']); } if (!empty($seConfig['ie'])) { $this->setIgnoredExtensions($seConfig['ie']); } if (!empty($seConfig['ishControlsHide'])) { $this->setHiddenControls($seConfig['ishControlsHide']); } if (!empty($seConfig['patternExtension'])) { $this->setPatternExtension($seConfig['patternExtension']); } } }
/** * @param $path * @return SubtypeInterface */ protected function getOrCreateSubtype($path) { list(, $key) = explode('/', PatternLab::normalizePath($path)); if (!isset($this->items[$key])) { $this->items[$key] = new Subtype($path); } return $this->items[$key]; }
public function getNameWithDashes() { return PatternLab::stripDigits($this->getName()); }
public function makePath(SourcePattern $pattern) { $path = Navigation::escapePath($pattern->getPath()); return PatternLab::makePath([$path, "{$path}.html"]); }
protected function makePaths(SourcePatternInterface $pattern) { $path = preg_replace('|[\\\\/~]|', '-', $pattern->getPath()); $this->escapedSourcePath = PatternLab::makePath(['patterns', $path, "{$path}.escaped.html"]); $this->path = PatternLab::makePath([$path, "{$path}.html"]); $this->pagePath = PatternLab::makePath(['patterns', $this->path]); $this->sourcePath = PatternLab::makePath(['patterns', $path, "{$path}.pattern.html"]); $this->templatePath = PatternLab::makePath(['patterns', $path, "{$path}.twig"]); $this->lineagePath = PatternLab::makePath(['..', '..', $this->pagePath]); }
protected function makePath($path) { return PatternLab::makePath([$this->path, $path]); }