public function register(Application $app)
 {
     $app['publisher'] = $app->share(function ($app) {
         $outputFormat = $app->edition('format');
         switch (strtolower($outputFormat)) {
             case 'pdf':
                 $publisher = new PdfPublisher($app);
                 break;
             case 'html':
                 $publisher = new HtmlPublisher($app);
                 break;
             case 'html_chunked':
                 $publisher = new HtmlChunkedPublisher($app);
                 break;
             case 'epub':
                 $publisher = new Epub2Publisher($app);
                 break;
             case 'mobi':
                 $publisher = new MobiPublisher($app);
                 break;
             default:
                 throw new \RuntimeException(sprintf('Unknown "%s" format for "%s" edition (allowed: "pdf", "html", "html_chunked", "epub", "mobi")', $outputFormat, $app['publishing.edition']));
         }
         if (true != $publisher->checkIfThisPublisherIsSupported()) {
             throw new \RuntimeException(sprintf("Your system doesn't support publishing books with the '%s' format\n" . "Check the easybook documentation to know the dependencies required by this format.", $outputFormat));
         }
         return $publisher;
     });
 }
 public function register(Application $app)
 {
     $app['twig.options'] = array('autoescape' => false, 'charset' => $app['app.charset'], 'debug' => $app['app.debug'], 'strict_variables' => $app['app.debug']);
     $app['twig.loader'] = $app->share(function () use($app) {
         $theme = ucfirst($app->edition('theme'));
         $format = Toolkit::camelize($app->edition('format'), true);
         $loader = new \Twig_Loader_Filesystem($app['app.dir.themes']);
         // Base theme (common styles per edition type)
         // <easybook>/app/Resources/Themes/Base/<edition-type>/Templates/<template-name>.twig
         $baseThemeDir = sprintf('%s/Base/%s/Templates', $app['app.dir.themes'], $format);
         $loader->addPath($baseThemeDir);
         $loader->addPath($baseThemeDir, 'theme');
         $loader->addPath($baseThemeDir, 'theme_base');
         // Book theme (configured per edition in 'config.yml')
         // <easybook>/app/Resources/Themes/<theme>/<edition-type>/Templates/<template-name>.twig
         $bookThemeDir = sprintf('%s/%s/%s/Templates', $app['app.dir.themes'], $theme, $format);
         $loader->prependPath($bookThemeDir);
         $loader->prependPath($bookThemeDir, 'theme');
         $userTemplatePaths = array($app['publishing.dir.templates'], sprintf('%s/%s', $app['publishing.dir.templates'], strtolower($format)), sprintf('%s/%s', $app['publishing.dir.templates'], $app['publishing.edition']));
         foreach ($userTemplatePaths as $path) {
             if (file_exists($path)) {
                 $loader->prependPath($path);
             }
         }
         $defaultContentPaths = array(sprintf('%s/Base/%s/Contents', $app['app.dir.themes'], $format), sprintf('%s/%s/%s/Contents', $app['app.dir.themes'], $theme, $format));
         foreach ($defaultContentPaths as $path) {
             if (file_exists($path)) {
                 $loader->prependPath($path, 'content');
             }
         }
         return $loader;
     });
     $app['twig'] = $app->share(function () use($app) {
         $twig = new \Twig_Environment($app['twig.loader'], $app['twig.options']);
         $twig->addExtension(new TwigCssExtension());
         $twig->addGlobal('app', $app);
         if (null != ($bookConfig = $app['publishing.book.config'])) {
             $twig->addGlobal('book', $bookConfig['book']);
             $publishingEdition = $app['publishing.edition'];
             $editions = $app->book('editions');
             $twig->addGlobal('edition', $editions[$publishingEdition]);
         }
         return $twig;
     });
 }
 public function register(Application $app)
 {
     $app['slugger.options'] = array('separator' => '-', 'prefix' => '');
     // stores all the generated slugs to ensure slug uniqueness
     $app['slugger.generated_slugs'] = array();
     $app['slugger'] = $app->share(function () use($app) {
         return new Slugger($app['slugger.options']);
     });
 }
 public function register(Application $app)
 {
     $app['parser.options'] = array('markdown_syntax' => 'easybook', 'code_block_type' => 'markdown');
     $app['parser'] = $app->share(function ($app) {
         $format = strtolower($app['publishing.active_item']['config']['format']);
         if (in_array($format, array('md', 'mdown', 'markdown'))) {
             return new MarkdownParser($app);
         }
         throw new \RuntimeException(sprintf('Unknown "%s" format for "%s" content (easybook only supports Markdown)', $format, $app['publishing.active_item']['config']['content']));
     });
 }
 public function register(Application $app)
 {
     $app['prince.path'] = null;
     // the common installation dirs for PrinceXML in several OS
     $app['prince.default_paths'] = array('/usr/local/bin/prince', '/usr/bin/prince', 'C:\\Program Files\\Prince\\engine\\bin\\prince.exe');
     $app['prince'] = $app->share(function () use($app) {
         $princePath = $app['prince.path'] ?: $app->findPrinceXmlExecutable();
         // ask the user about the location of the executable
         if (null == $princePath) {
             $princePath = $app->askForPrinceXMLExecutablePath();
             if (!file_exists($princePath)) {
                 throw new \RuntimeException(sprintf("We couldn't find the PrinceXML executable in the given directory (%s)", $princePath));
             }
         }
         $prince = new Prince($princePath);
         $prince->setHtml(true);
         return $prince;
     });
 }