예제 #1
0
 /**
  * githubFilesystem
  *
  * @param       $repository
  * @param array $settings
  * @return \Illuminate\Contracts\Filesystem\Filesystem
  */
 public function githubFilesystem($repository, array $settings = [])
 {
     $settings = array_replace_recursive(['driver' => 'github', 'repository' => $repository, 'credentials' => [\Potherca\Flysystem\Github\Settings::AUTHENTICATE_USING_TOKEN, $this->config->get('docit.hooks.github.github_token')], 'branch' => 'master', 'ref' => null], $settings);
     $key = 'filesystems.disks.' . Str::slug($repository);
     $this->config->set($key, $settings);
     return $this->filesystemManager->disk($key);
 }
예제 #2
0
파일: MakeCommand.php 프로젝트: docit/core
 public function handle()
 {
     $name = $this->ask('Directory name');
     $displayName = $this->ask('Display name');
     $name = Str::slugify($name);
     $this->generate($name, ['config.php.stub' => 'config.php', 'index.md.stub' => '{{directory}}/index.md', 'menu.yml.stub' => '{{directory}}/menu.yml'], ['displayName' => $displayName]);
     $this->comment('All done sire!');
 }
예제 #3
0
파일: Path.php 프로젝트: docit/support
 /**
  * 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);
 }
예제 #4
0
 /**
  * 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;
 }
예제 #5
0
 /**
  * getViewsPath
  *
  * @param null $path
  * @return string
  */
 public function getViewsPath($dirName)
 {
     return realpath(Str::replace($this->viewsPath, '{dirName}', $dirName));
 }
예제 #6
0
 public function syncRef($ref, $type)
 {
     $content = new GitSyncContent($this->setting('owner'), $this->setting('repository'), $this->github);
     $hasDocs = $content->exists($this->setting('sync.paths.docs'), $ref);
     if (!$hasDocs) {
         return;
     }
     $destinationDir = Path::join($this->project->getPath(), $ref);
     $menu = $content->show($this->setting('sync.paths.menu'), $ref);
     $menuContent = base64_decode($menu['content']);
     $menuArray = Yaml::parse($menuContent);
     $unfilteredPages = [];
     $this->extractDocumentsFromMenu($menuArray['menu'], $unfilteredPages);
     $filteredPages = [];
     # filter out pages that link to external sites
     foreach ($unfilteredPages as $page) {
         if (Str::startsWith($page, 'http', true) || Str::startsWith($page, '//', true) || Str::startsWith($page, 'git', true)) {
             continue;
         }
         if (!in_array($page, $filteredPages, true)) {
             $filteredPages[] = $page;
         }
     }
     # get all pages their content and save to local
     foreach ($filteredPages as $pagePath) {
         $path = Path::join($this->setting('sync.paths.docs'), $pagePath . '.md');
         # check if page exists on remote
         $exists = $content->exists($path, $ref);
         if (!$exists) {
             continue;
         }
         # the raw github page content response
         $pageRaw = $content->show('/' . $path, $ref);
         # transform remote directory path to local directory path
         $dir = Str::remove($pageRaw['path'], $this->setting('sync.paths.docs'));
         $dir = Str::remove($dir, $pageRaw['name']);
         $dir = Path::canonicalize(Path::join($destinationDir, $dir));
         if (!$this->files->exists($dir)) {
             $this->files->makeDirectory($dir);
         }
         # raw github page to utf8 and save it to local
         $this->files->put(Path::join($dir, $pageRaw['name']), base64_decode($pageRaw['content']));
     }
     # save the menu to local
     $this->files->put(Path::join($destinationDir, 'menu.yml'), $menuContent);
     # if enabled, Get phpdoc structure and save it
     if ($this->setting('phpdoc')) {
         $hasStructure = $content->exists($this->setting('paths.phpdoc'), $ref);
         if ($hasStructure) {
             $structure = $content->show($this->setting('paths.phpdoc'), $ref);
             $structureXml = base64_decode($structure['content']);
             $destination = Path::join($destinationDir, 'structure.xml');
             $destinationDir = Path::getDirectory($destination);
             if (!$this->files->exists($destinationDir)) {
                 $this->files->makeDirectory($destinationDir);
             }
             $this->files->put($destination, $structureXml);
         }
     }
     # set cache sha for branches, not for tags (obviously)
     if ($type === 'branch') {
         $branchData = $this->github->repositories()->branches($this->setting('owner'), $this->setting('repository'), $ref);
         $this->cache->forever(md5($this->project->getName() . $branchData['name']), $branchData['commit']['sha']);
     }
 }
예제 #7
0
파일: Project.php 프로젝트: docit/core
 /**
  * Resolves and creates the documents menu from the parsed menu.yml
  *
  * @param array       $items The array converted from yaml
  * @param string $parentId
  * @return \Docit\Core\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;
 }
예제 #8
0
 /**
  * Transforms a package name (eg: docit-project/github-filesystem) into a namespace (eg: DocitProject\GithubFilesystem)
  *
  * @param $packageName
  * @return string
  */
 protected function getPackageNamespace($packageName)
 {
     return Str::namespacedStudly($packageName);
 }