public function handle() { $name = $this->ask('Directory name'); $displayName = $this->ask('Display name'); $name = Str::slugify($name); $destPath = Path::join(config('codex.root_dir'), $name); $fs = $this->getLaravel()->make('fs'); if ($fs->exists($destPath)) { return $this->error("Could not create {$name}. Already exists"); } $this->getLaravel()->make(ProjectGenerator::class)->setDestPath($destPath)->generateProject($name, $displayName); $this->comment('All done sire!'); }
/** * Joins a split file system path. * * @param array|string $path * @return string */ public static function join() { $arguments = func_get_args(); if (func_get_args() === 1 and is_array($arguments[0])) { $arguments = $arguments[0]; } foreach ($arguments as $key => $argument) { $arguments[$key] = Str::removeRight($arguments[$key], '/'); if ($key > 0) { $arguments[$key] = Str::removeLeft($arguments[$key], '/'); } } return implode(DIRECTORY_SEPARATOR, $arguments); }
/** * Removes indentation * * @param string $text The markdown text * @return mixed */ protected function transform($text) { $firstLine = explode("\n", $text, 1); $firstLine = Str::toSpaces($firstLine[0], 4); preg_match('/([\\s]*).*/', $firstLine, $firstLineSpacesMatches); if (isset($firstLineSpacesMatches[1])) { $spaceMatcher = ""; for ($i = 0; $i < strlen($firstLineSpacesMatches[1]); $i++) { $spaceMatcher .= "\\s"; } $spaceMatcher = '/^' . $spaceMatcher . '(.*)/m'; $newText = preg_replace($spaceMatcher, '$1', $text); return $newText; } return $text; }
/** * generate * * @param string $stubDir * @param string $destDir * @param array $files * @param array $vars * @return $this * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException */ public function generate($stubDir, $destDir, array $files = [], array $vars = []) { foreach ($files as $stubFile => $destFile) { foreach (array_dot($vars) as $key => $val) { $destFile = Str::replace($destFile, '{{' . $key . '}}', $val); } $stubPath = Path::join($stubDir, $stubFile); $destPath = Path::join($destDir, $destFile); $destDirPath = Path::getDirectory($destPath); if (!$this->files->exists($destDirPath)) { $this->files->makeDirectory($destDirPath, 0755, true); } $rendered = $this->render($this->files->get($stubPath), $vars); $this->files->put($destPath, $rendered); } return $this; }
protected function write($content, $name = null) { $tmpDir = storage_path('blade-extensions'); if (!$this->files->exists($tmpDir)) { $this->files->makeDirectory($tmpDir); } if (is_null($name)) { $name = Str::slugify($this->viewPath) . '__' . uniqid(time(), true); } $path = Path::join($tmpDir, $name); $this->files->put($path, $content); return [$name, $path]; }
/** * Resolves and creates the documents menu from the parsed menu.yml * * @param array $items The array converted from yaml * @param string $parentId * @return \Codex\Codex\Menus\Menu */ protected function resolveDocumentsMenu($items, $parentId = 'root') { /** * @var Menus\Menu $menu */ $menu = $this->factory->getMenus()->add('project_sidebar_menu'); foreach ($items as $item) { $link = '#'; if (array_key_exists('document', $item)) { // remove .md extension if present $path = Str::endsWith($item['document'], '.md', false) ? Str::remove($item['document'], '.md') : $item['document']; $link = $this->factory->url($this, $this->ref, $path); } elseif (array_key_exists('href', $item)) { $link = $item['href']; } $id = md5($item['name'] . $link); $node = $menu->add($id, $item['name'], $parentId); $node->setAttribute('href', $link); $node->setAttribute('id', $id); if (isset($item['icon'])) { $node->setMeta('icon', $item['icon']); } if (isset($item['children'])) { $this->resolveDocumentsMenu($item['children'], $id); } } return $menu; }
/** * Resolve the given link. * * @param string $link * @return string */ protected function resolveLink($link) { if (Str::startsWith('http', $link, false)) { return $link; } else { $path = Str::endsWith($link, '.md', false) ? Str::remove($link, '.md') : $link; return $this->project->getFactory()->url($this->project, $this->project->getRef(), $path); } }
/** * Transforms a package name (eg: codex-project/github-filesystem) into a namespace (eg: CodexProject\GithubFilesystem) * * @param $packageName * @return string */ protected function getPackageNamespace($packageName) { return Str::namespacedStudly($packageName); }
public function testCanGetBaseClass() { $this->assertEquals('Baz', Str::baseClass('Foo\\Bar\\Baz')); }
/** * getViewsPath * * @param null $path * @return string */ public function getViewsPath($dirName) { return realpath(Str::replace($this->viewsPath, '{dirName}', $dirName)); }