Permalink
Browse files

Merge branch 'develop'

Brings in ZF2 console tooling
  • Loading branch information...
2 parents d9c09dd + ac3c297 commit a906cc14beeafb4a0dd45cd3bddb905e01a1c6d8 @weierophinney weierophinney committed Sep 26, 2012
Showing with 406 additions and 217 deletions.
  1. +1 −0 .gitignore
  2. +83 −5 Module.php
  3. +41 −44 README.md
  4. +1 −0 autoload_classmap.php
  5. +0 −168 bin/compile.php
  6. +15 −0 config/module.config.php
  7. +265 −0 src/PhlyBlog/CompileController.php
View
@@ -1 +1,2 @@
.vimproject
+.*.swp
View
@@ -3,9 +3,15 @@
namespace PhlyBlog;
use Traversable;
+use Zend\Console\Adapter\AdapterInterface as Console;
+use Zend\Http\PhpEnvironment\Request;
+use Zend\Http\PhpEnvironment\Response;
+use Zend\ModuleManager\Feature\ConsoleUsageProviderInterface;
use Zend\Stdlib\ArrayUtils;
+use Zend\View\Renderer\PhpRenderer;
+use Zend\View\View;
-class Module
+class Module implements ConsoleUsageProviderInterface
{
public static $config;
@@ -23,19 +29,91 @@ public function getConfig()
return include __DIR__ . '/config/module.config.php';
}
+ public function getServiceConfig()
+ {
+ return array('factories' => array(
+ 'blogrequest' => function ($services) {
+ return new Request();
+ },
+ 'blogresponse' => function ($services) {
+ return new Response();
+ },
+ 'blogrenderer' => function ($services) {
+ $helpers = $services->get('ViewHelperManager');
+ $resolver = $services->get('ViewResolver');
+
+ $renderer = new PhpRenderer();
+ $renderer->setHelperPluginManager($helpers);
+ $renderer->setResolver($resolver);
+
+ $config = $services->get('Config');
+ if ($services->has('MvcEvent')) {
+ $event = $services->get('MvcEvent');
+ $model = $event->getViewModel();
+ } else {
+ $model = new Model\ViewModel();
+ }
+ $layout = 'layout/layout';
+ if (isset($config['view_manager']['layout'])) {
+ $layout = $config['view_manager']['layout'];
+ }
+ $model->setTemplate($layout);
+ $helpers->get('view_model')->setRoot($model);
+
+ return $renderer;
+ },
+ ));
+ }
+
+ public function getControllerConfig()
+ {
+ return array('factories' => array(
+ 'PhlyBlog\CompileController' => function ($controllers) {
+ $services = $controllers->getServiceLocator();
+ $config = $services->get('Config');
+ $config = isset($config['blog']) ? $config['blog'] : array();
+
+ $request = $services->get('BlogRequest');
+ $response = $services->get('BlogResponse');
+ $view = new View();
+ $view->setRequest($request);
+ $view->setResponse($response);
+
+ $controller = new CompileController();
+ $controller->setConfig($config);
+ $controller->setConsole($services->get('Console'));
+ $controller->setView($view);
+ return $controller;
+ },
+ ));
+ }
+
+ public function getConsoleUsage(Console $console)
+ {
+ return array(
+ 'blog compile [--all|-a] [--entries|-e] [--archive|-c] [--year|-y] [--month|-m] [--day|-d] [--tag|-t] [--author|-r]' => 'Compile blog:
+ --all|-a: Execute all actions (default)
+ --entries|-e: Compile entries
+ --archive|-c: Compile paginated archive (and feed)
+ --year|-y: Compile paginated entries by year
+ --month|-m: Compile paginated entries by month
+ --day|-d: Compile paginated entries by day
+ --tag|-t: Compile paginated entries by tag (and feeds)
+ --author|-r: Compile paginated entries by author (and feeds)
+',
+ );
+ }
+
public function onBootstrap($e)
{
$app = $e->getApplication();
$services = $app->getServiceManager();
self::$config = $services->get('config');
- if (self::$config instanceof Traversable) {
- self::$config = ArrayUtils::iteratorToArray(self::$config);
- }
}
public static function prepareCompilerView($view, $config, $services)
{
- $renderer = $services->get('ViewRenderer');
+ $renderer = $services->get('BlogRenderer');
$view->addRenderingStrategy(function($e) use ($renderer) {
return $renderer;
}, 100);
View
@@ -1,5 +1,5 @@
-Static Blog
-===========
+PhlyBlog: Static Blog Generator
+===============================
This module is a tool for generating a static blog.
@@ -10,41 +10,42 @@ application, or they can be plain old HTML markup files that you serve
directly.
Requirements
-----
+------------
-* PHP >= 5.3.3
-* Zend Framework 2 >= 2.0.0beta4, specifically:
- * Zend\View\View, used to render and write generated files
- * Zend\Mvc and Zend\ModuleManager, as this implements a module, and the
+- PHP >= 5.3.3
+- Zend Framework 2 >= 2.0.0beta4, specifically:
+ - Zend\View\View, used to render and write generated files
+ - Zend\Mvc and Zend\ModuleManager, as this implements a module, and the
compiler script depends on it and an Application instance. As such, it also
has a dependency on Zend\Loader, Zend\ServiceManager, and Zend\EventManager.
- * Zend\Feed\Writer
- * Zend\Tag\Cloud
-* PhlyCommon (for Entity and Filter interfaces)
+ - Zend\Feed\Writer
+ - Zend\Tag\Cloud
+- PhlyCommon (for Entity and Filter interfaces)
Installation
-----
+------------
You can add this module as a git submodule to your repository. Alternately, use
composer. To do so, add the following `composer.json` configuration in your
project:
-{{{
+```js
{
+ "minimum-stability": "dev",
"require": {
"phly/phly-blog": "dev-master"
}
}
-}}}
+```
and then execute:
-{{{
+```bash
php composer.phar install
-}}}
+```
Writing Entries
-====
+---------------
Find a location in your repository for entries, preferably outside your document
root; I recommend either `data/blog/` or `posts/`.
@@ -55,42 +56,37 @@ template.
Important things to note:
-* Set the created and/or updated timestamps. Alternately, use `DateTime` or
+- Set the created and/or updated timestamps. Alternately, use `DateTime` or
`date()` to generate a timestamp based on a date/time string.
-* Entries marked as "drafts" (i.e., `setDraft(true)`) will not be published.
-* Entries marked as private (i.e., `setPublic(false)`) will be published, but
+- Entries marked as "drafts" (i.e., `setDraft(true)`) will not be published.
+- Entries marked as private (i.e., `setPublic(false)`) will be published, but
will not be aggregated in paginated views or feeds. As such, you need to hand
the URL to somebody in order for them to see it.
-* You can set an array of tags. Tags can have whitespace, which will be
+- You can set an array of tags. Tags can have whitespace, which will be
translated to "+" characters.
Usage
=====
-A script, `bin/compile.php`, is shipped for your convenience, and it will
-generate the following artifacts:
+This module is ZF2 Console-aware. Once installed and active in your
+application, you should be able to run:
-* A file per entry
-* Paginated entry files
-* Paginated entry files by year
-* Paginated entry files by month
-* Paginated entry files by day
-* Paginated entry files by tag
-* Atom and/or RSS feeds for recent entries
-* Atom and/or RSS feeds for recent entries by tag
-* Optionally, a tag cloud
+```bash
+% php public/index.php
+```
-The script, makes the following assumptions:
+and see usage for the module. Currently, it defines a "blog compile" action
+that can generate the following artifacts:
-* They are being called by another script that:
- * sets up one or more autoloaders, including functionality to autoload the
- code in this library
- * compiles and merges all application configuration
- * bootstraps the application
- * retains the Application instance in the current scope
-
-Basically, a script that does normal bootstrapping, but without calling `run()`
-or `send()` on the Application instance.
+- A file per entry
+- Paginated entry files
+- Paginated entry files by year
+- Paginated entry files by month
+- Paginated entry files by day
+- Paginated entry files by tag
+- Atom and/or RSS feeds for recent entries
+- Atom and/or RSS feeds for recent entries by tag
+- Optionally, a tag cloud
You will want to setup local configuration; I recommend putting it in
`config/autoload/module.blog.config.global.php`. As a sample:
@@ -202,12 +198,13 @@ You will want to setup local configuration; I recommend putting it in
),
)),
));
+ ```
-When you run the script, it will generate files in the locations you specify in
-your configuration.
+When you run the command line tool, it will generate files in the locations you
+specify in your configuration.
License
-----
+-------
Copyright (c) 2012, Matthew Weier O'Phinney
All rights reserved.
View
@@ -7,6 +7,7 @@
'PhlyBlog\Filter\Url' => __DIR__ . '/src/PhlyBlog/Filter/Url.php',
'PhlyBlog\Filter\Tags' => __DIR__ . '/src/PhlyBlog/Filter/Tags.php',
'PhlyBlog\Filter\Permalink' => __DIR__ . '/src/PhlyBlog/Filter/Permalink.php',
+ 'PhlyBlog\CompileController' => __DIR__ . '/src/PhlyBlog/CompileController.php',
'PhlyBlog\Compiler\ResponseFile' => __DIR__ . '/src/PhlyBlog/Compiler/ResponseFile.php',
'PhlyBlog\Compiler\FileWriter' => __DIR__ . '/src/PhlyBlog/Compiler/FileWriter.php',
'PhlyBlog\Compiler\Event' => __DIR__ . '/src/PhlyBlog/Compiler/Event.php',
Oops, something went wrong.

0 comments on commit a906cc1

Please sign in to comment.