X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDevelop%2FGenerateDocCheatsheetCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDevelop%2FGenerateDocCheatsheetCommand.php;h=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=474ab6e0ca878b5311aa9becdcbd0c5fd2dcb8b9;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Develop/GenerateDocCheatsheetCommand.php b/vendor/drupal/console/src/Command/Develop/GenerateDocCheatsheetCommand.php deleted file mode 100644 index 474ab6e0c..000000000 --- a/vendor/drupal/console/src/Command/Develop/GenerateDocCheatsheetCommand.php +++ /dev/null @@ -1,266 +0,0 @@ -setName('generate:doc:cheatsheet') - ->setDescription($this->trans('commands.generate.doc.cheatsheet.description')) - ->addOption( - 'path', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.doc.cheatsheet.options.path') - ) - ->addOption( - 'wkhtmltopdf', - null, - InputOption::VALUE_OPTIONAL, - $this->trans('commands.generate.doc.cheatsheet.options.wkhtmltopdf') - ); - ; - } - - /** - * {@inheritdoc} - */ - protected function execute(InputInterface $input, OutputInterface $output) - { - $io = new DrupalStyle($input, $output); - - $path = null; - - if ($input->hasOption('path')) { - $path = $input->getOption('path'); - } - - if (!$path) { - $io->error( - $this->trans('commands.generate.doc.gitbook.messages.missing_path') - ); - - return 1; - } - - // $wkhtmltopdfPath is overwritable by command option - - if ($input->getOption('wkhtmltopdf')) { - $this->wkhtmltopdfPath = $input->getOption('wkhtmltopdf'); - } - - $application = $this->getApplication(); - $command_list = []; - - foreach ($this->singleCommands as $single_command) { - $command = $application->find($single_command); - $command_list['none'][] = [ - 'name' => $command->getName(), - 'description' => $command->getDescription(), - ]; - } - - $namespaces = $application->getNamespaces(); - sort($namespaces); - - $namespaces = array_filter( - $namespaces, function ($item) { - return (strpos($item, ':')<=0); - } - ); - - foreach ($namespaces as $namespace) { - $commands = $application->all($namespace); - - usort( - $commands, function ($cmd1, $cmd2) { - return strcmp($cmd1->getName(), $cmd2->getName()); - } - ); - - foreach ($commands as $command) { - if ($command->getModule()=='Console') { - $command_list[$namespace][] = [ - 'name' => $command->getName(), - 'description' => $command->getDescription(), - ]; - } - } - } - - if (!empty($command_list)) { - $this->prepareHtml($command_list, $path, $io); - } - } - - - /** - * Generates (programatically, not with twig) the HTML to convert to PDF - * - * @param array $array_content - * @param string $path - */ - protected function prepareHtml($array_content, $path, $io) - { - $str = ''; - $str .= "
Drupal Console cheatsheet
"; - - // 1st page - foreach ($this->orderCommands as $command) { - $str .= $this->doTable($command, $array_content[$command]); - } - - // 2nd page - $str .= "

"; - - $str .= "

DrupalConsole Cheatsheet



"; - - $str .= $this->doTable("generate", $array_content["generate"]); - $str .= $this->doTable("miscelaneous", $array_content["none"]); - - $this->doPdf($str, $path, $io); - } - - - /** - * Generates the pdf with Snappy - * - * @param string $content - * @param string $path - * - * @return string - */ - protected function doPdf($content, $path, $io) - { - $snappy = new Pdf(); - //@TODO: catch exception if binary path doesn't exist! - $snappy->setBinary($this->wkhtmltopdfPath); - $snappy->setOption('orientation', "Landscape"); - $snappy->generateFromHtml($content, "/" .$path . 'dc-cheatsheet.pdf'); - $io->success("cheatsheet generated at /" .$path ."/dc-cheatsheet.pdf"); - - // command execution ends here - } - - /** - * Encloses text in tags - * - * @param string $str - * - * @return string - */ - public function td($str, $mode = null) - { - if ("header" == $mode) { - return "" . strtoupper($str) . ""; - } else { - if ("body" == $mode) { - return "". $str. ""; - } else { - return "" . $str . ""; - } - } - } - - /** - * Encloses text in tags - * - * @param string $str - * @param array $element - * - * @return string - */ - public function tr($str) - { - return "" . $str . ""; - } - - /** - * Encloses text in tag - * - * @param string $key_element - header - * @param array $element - command, description - * - * @return string - */ - public function doTable($key_element, $element) - { - $str = "
"; - $str .= $this->td($key_element, "header"); - - foreach ($element as $section) { - $str .= $this->tr($this->td($section["name"], "body") . $this->td($section["description"], "body")); - } - - return $str . "
\n\r"; - } -}