Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
Merge branch 'feature/flatten-config-array' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hassankhan committed Feb 17, 2014
2 parents 06b28fe + a0f9699 commit a86b255
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 181 deletions.
38 changes: 16 additions & 22 deletions config.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
<?php

$config = array(
'zepto' => array(
'environment' => 'dev',
'content_dir' => 'content',
'plugins_dir' => 'plugins',
'templates_dir' => 'templates',
'default_template' => 'base.twig',
'content_ext' => array('.md', '.markdown'),
'plugins_enabled' => true
),
'site' => array(
'site_root' => 'Site root URL goes here',
'site_title' => 'Zepto',
'date_format' => 'jS M Y',
'excerpt_length' => '50',
'nav' => array(
'class' => 'nav',
'dropdown_li_class' => 'dropdown',
'dropdown_ul_class' => 'dropdown-menu',
'dropdown_li_markup' => '<li class="%s"><a href="%s" class="dropdown-toggle" data-toggle="dropdown"> %s <b class="caret"></b></a><ul class="%s">'
)
),
'twig' => array(
'zepto.environment' => 'dev',
'zepto.content_dir' => 'content',
'zepto.plugins_dir' => 'plugins',
'zepto.templates_dir' => 'templates',
'zepto.default_template' => 'base.twig',
'zepto.content_ext' => array('.md', '.markdown'),
'zepto.plugins_enabled' => true,
'site.site_root' => 'http://localhost:8888/zepto/',
'site.site_title' => 'Zepto',
'site.date_format' => 'jS M Y',
'site.excerpt_length' => '50',
'site.nav.class' => 'nav',
'site.nav.dropdown_li_class' => 'dropdown',
'site.nav.dropdown_ul_class' => 'dropdown-menu',
'site.nav.dropdown_li_markup' => '<li class="%s"><a href="%s" class="dropdown-toggle" data-toggle="dropdown"> %s <b class="caret"></b></a><ul class="%s">',
'twig' => array(
'charset' => 'utf-8',
'cache' => 'cache',
'strict_variables' => false,
Expand Down
54 changes: 22 additions & 32 deletions library/Zepto/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Zepto;

/**
* Helper class to hold all helper-related functions
* Helper class to hold all helper-y functions
*
*
* @package Zepto
* @subpackage Helper
* @author Hassan Khan <contact@hassankhan.me>
* @link http://https://github.com/hassankhan/Zepto
* @link https://github.com/hassankhan/Zepto
* @license MIT
* @since 0.6
*/
Expand Down Expand Up @@ -44,27 +44,18 @@ public function __construct(\Pimple $app)
public static function default_config()
{
return array(
'zepto' => array(
'environment' => 'dev',
'content_dir' => 'content',
'plugins_dir' => 'plugins',
'templates_dir' => 'templates',
'default_template' => 'base.twig',
'content_ext' => array('.md', '.markdown'),
'plugins_enabled' => true
),
'site' => array(
'site_root' => 'http://localhost:8888/zepto/',
'site_title' => 'Zepto',
'date_format' => 'jS M Y',
'excerpt_length' => '50',
'nav' => array(
'class' => 'nav',
'dropdown_li_class' => 'dropdown',
'dropdown_ul_class' => 'dropdown-menu'
)
),
'twig' => array(
'zepto.environment' => 'dev',
'zepto.content_dir' => 'content',
'zepto.plugins_dir' => 'plugins',
'zepto.templates_dir' => 'templates',
'zepto.default_template' => 'base.twig',
'zepto.content_ext' => array('.md', '.markdown'),
'zepto.plugins_enabled' => false,
'site.site_root' => 'http://localhost:8888/zepto/',
'site.site_title' => 'Zepto',
'site.date_format' => 'jS M Y',
'site.excerpt_length' => '50',
'twig' => array(
'charset' => 'utf-8',
'cache' => 'cache',
'strict_variables' => false,
Expand All @@ -86,30 +77,30 @@ public static function validate_config($config)
$message = '';

while ($message === '') {
if (!is_dir($config['zepto']['content_dir'])) {
if (!is_dir($config['zepto.content_dir'])) {
$message = 'Content directory does not exist';
break;
}

if (!is_dir($config['zepto']['plugins_dir'])) {
if (!is_dir($config['zepto.plugins_dir'])) {
$message = 'Plugins directory does not exist';
break;
}

if (!is_dir($config['zepto']['templates_dir'])) {
if (!is_dir($config['zepto.templates_dir'])) {
$message = 'Templates directory does not exist';
break;
}

if (
!is_file("{$config['zepto']['templates_dir']}/{$config['zepto']['default_template']}")
!is_file("{$config['zepto.templates_dir']}/{$config['zepto.default_template']}")
) {
$message = 'No default template exists';
break;
}

if ($config['zepto']['environment'] !== 'dev') {
preg_match('#^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/+$#', $config['site']['site_root']) === 0
if ($config['zepto.environment'] !== 'dev') {
preg_match('#^(https?://)?([\da-z\.-]+)\.([a-z\.]{2,6})([/\w \.-]*)*/+$#', $config['site.site_root']) === 0
? $message = 'Site root is invalid. Should be like http://www.example.com/'
: $message = '';
}
Expand Down Expand Up @@ -139,17 +130,16 @@ public function url_for($file_name)

// Create URL and return
$clean_file_name = str_replace(
array_merge(array('index'), $this->app['settings']['zepto']['content_ext']),
array_merge(array('index'), $this->app['settings']['zepto.content_ext']),
'',
$file_name
);
return trim($this->app['settings']['site']['site_root'] . $clean_file_name, '/') . '/';
return trim($this->app['settings']['site.site_root'] . $clean_file_name, '/') . '/';
}
catch (\Exception $e) {
$this->app['router']->error($e);
}
return null;

}

/**
Expand Down
47 changes: 9 additions & 38 deletions library/Zepto/Zepto.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,6 @@ class Zepto {
/**
* Zepto constructor
*
* <code>
* $config = array(
* 'zepto' => array(
* 'environment' => 'dev',
* 'content_dir' => 'content',
* 'plugins_dir' => 'plugins',
* 'templates_dir' => 'templates',
* 'default_template' => 'base.twig',
* 'content_ext' => array('.md', '.markdown'),
* 'plugins_enabled' => true
* ),
* 'site' => array(
* 'site_root' => 'Site root URL goes here',
* 'site_title' => 'Zepto',
* 'date_format' => 'jS M Y',
* 'excerpt_length' => '50',
* 'nav' => array(
* 'class' => 'nav',
* 'dropdown_li_class' => 'dropdown',
* 'dropdown_ul_class' => 'dropdown-menu'
* )
* ),
* 'twig' => array(
* 'charset' => 'utf-8',
* 'cache' => 'cache',
* 'strict_variables' => false,
* 'autoescape' => false,
* 'auto_reload' => true
* )
* );
* </code>
* @param array $settings
*/
public function __construct(array $settings = array())
Expand Down Expand Up @@ -111,7 +80,7 @@ function ($app) {
$app['content_loader'] = $app->share(
function ($app) {
return new FileLoader\MarkdownLoader(
$app['ROOT_DIR'] . $app['settings']['zepto']['content_dir'],
$app['ROOT_DIR'] . $app['settings']['zepto.content_dir'],
new \Michelf\MarkdownExtra
);
}
Expand All @@ -126,7 +95,9 @@ function ($app) {
$app['twig'] = $app->share(
function($app) {
$twig = new \Twig_Environment(
new \Twig_Loader_Filesystem($app['ROOT_DIR'] . 'templates')
new \Twig_Loader_Filesystem($app['ROOT_DIR'] . 'templates',
$app['settings']['twig']
)
);
$twig->addExtension(new Extension\Twig);
return $twig;
Expand All @@ -143,15 +114,15 @@ function($app) {
}

// Set this particular setting now
$app['plugins_enabled'] = $settings['zepto']['plugins_enabled'];
$app['plugins_enabled'] = $settings['zepto.plugins_enabled'];

// So if plugins ARE indeed enabled, initialise the plugin loader
// and load the fuckers
if ($app['plugins_enabled'] === true) {
$app['plugin_loader'] = $app->share(
function($c) use ($settings) {
return new FileLoader\PluginLoader(
$c['ROOT_DIR'] . $settings['zepto']['plugins_dir']
$c['ROOT_DIR'] . $settings['zepto.plugins_dir']
);
}
);
Expand Down Expand Up @@ -267,8 +238,8 @@ protected function setup_router()
// Set Twig options
$twig_vars = array(
'config' => $app['settings'],
'base_url' => $app['settings']['site']['site_root'],
'site_title' => $app['settings']['site']['site_title']
'base_url' => $app['settings']['site.site_root'],
'site_title' => $app['settings']['site.site_title']
);

$app['nav'] = isset($app['nav']) === TRUE ? $app['nav'] : array();
Expand All @@ -280,7 +251,7 @@ protected function setup_router()
// Get template name from file, if not set, then use default
$template_name = array_key_exists('template', $content['meta']) === true
? $content['meta']['template']
: $app['settings']['zepto']['default_template'];
: $app['settings']['zepto.default_template'];

// Render template with Twig
return $app['twig']->render($template_name, $options);
Expand Down
11 changes: 10 additions & 1 deletion plugins/NavGenPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public function after_plugins_load(\Pimple $app)

public function before_config_load(\Pimple $app, &$settings)
{
$nav_settings = array(
'site.nav.class' => 'nav',
'site.nav.dropdown_li_class' => 'dropdown',
'site.nav.dropdown_ul_class' => 'dropdown-menu',
'site.nav.dropdown_li_markup' => '<li class="%s"><a href="%s" class="dropdown-toggle" data-toggle="dropdown"> %s <b class="caret"></b></a><ul class="%s">'
);
$old_settings = $settings;
$settings = array_merge($nav_settings, $old_settings);

}

public function before_router_setup(\Pimple $app)
Expand Down Expand Up @@ -46,7 +55,7 @@ public function generate_html($app)
$content_loader = $app['content_loader'];

// Opening ``<ul>`` tag and adding class name
$nav_html = sprintf('<ul class="%s">' . PHP_EOL, $settings['site']['nav']['class']);
$nav_html = sprintf('<ul class="%s">' . PHP_EOL, $settings['site.nav.class']);
$files = $content_loader->get_folder_contents();

foreach ($files as $file) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/WhoopsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function($app) {
public function before_config_load(\Pimple $app, &$settings)
{
// If we're not on dev, then don't load up
if ($settings['zepto']['environment'] !== 'dev') {
if ($settings['zepto.environment'] !== 'dev') {
return;
}

Expand Down
Loading

0 comments on commit a86b255

Please sign in to comment.