Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
retlehs committed Mar 11, 2016
1 parent fa0e51f commit 67c190f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/admin.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php namespace App;

/**
* Add postMessage support
* Theme customizer
*/
add_action('customize_register', function (\WP_Customize_Manager $wp_customize) {
// Add postMessage support
$wp_customize->get_setting('blogname')->transport = 'postMessage';
});

/**
* Customizer JS
*/
add_action('customize_preview_init', function () {
wp_enqueue_script('sage/customizer', asset_path('scripts/customizer.js'), ['customize-preview'], null, true);
wp_enqueue_script('sage/customizer.js', asset_path('scripts/customizer.js'), ['customize-preview'], null, true);
});
7 changes: 3 additions & 4 deletions src/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @link https://codex.wordpress.org/Conditional_Tags
*/
add_filter('sage/display_sidebar', function ($display) {
/** The sidebar will NOT be displayed if ANY of the following return true. */
// The sidebar will NOT be displayed if ANY of the following return true
return $display ? !in_array(true, [
is_404(),
is_front_page(),
Expand Down Expand Up @@ -36,15 +36,14 @@
});

/**
* Clean up the_excerpt()
* Add "… Continued" to the excerpt
*/
add_filter('excerpt_more', function () {
return ' &hellip; <a href="' . get_permalink() . '">' . __('Continued', 'sage') . '</a>';
});


/**
* Use Wrapper by default
* Use theme wrapper
*/
add_filter('template_include', function ($main) {
if (!is_string($main) || !(string) $main) {
Expand Down
1 change: 0 additions & 1 deletion src/lib/Sage/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* @author QWp6t
*/
class Asset {

public static $dist = '/dist';

/** @var ManifestInterface Currently used manifest */
Expand Down
1 change: 0 additions & 1 deletion src/lib/Sage/Assets/ManifestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author QWp6t
*/
interface ManifestInterface {

/**
* Get the cache-busted filename
*
Expand Down
9 changes: 9 additions & 0 deletions src/lib/Sage/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function unwrap($slug = '', $context = []) {
end(self::$wrappers);
$slug = key(self::$wrappers);
}

$template = new static(self::$wrappers[$slug]->getTemplate(), $context);
unset(self::$wrappers[$slug]);
return $template;
Expand All @@ -61,9 +62,11 @@ public static function unwrap($slug = '', $context = []) {
public static function convertParts($template, $delimeter = '-') {
$templateParts = explode($delimeter, str_replace('.php', '', (string) $template));
$templates[] = array_shift($templateParts);

foreach ($templateParts as $i => $templatePart) {
$templates[] = $templates[$i] . $delimeter . $templatePart;
}

return array_reverse($templates);
}

Expand Down Expand Up @@ -102,10 +105,12 @@ public function get() {
$context = $this->context;
extract($this->context);
ob_start();

if ($template = $this->locate()) {
/** @noinspection PhpIncludeInspection */
include $template;
}

$this->html = ob_get_clean() ?: '';
return $this->html;
}
Expand All @@ -118,9 +123,11 @@ public function set($template) {
$this->templates = self::format($template);
return;
}

if (!is_string($template) || !(string) $template) {
return;
}

// At this point, we assume it's something like `content-single.php` or `content-single-audio.php`
$this->templates = self::format(self::convertParts($template));
}
Expand All @@ -135,6 +142,7 @@ protected static function format($templates) {
if (substr($template, -4, 4) === '.php') {
return $template;
}

return $template . '.php';
}, $templates);
}
Expand All @@ -147,6 +155,7 @@ public function locate($templateDir = '') {
$templates = array_map(function ($template) use ($templateDir) {
return ($templateDir ?: self::$root) . $template;
}, $this->templates);

$template = locate_template($templates);
return apply_filters('sage/locate_template', $template, $templates) ?: $template;
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/Sage/Template/Wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public function getSlug() {
}

/** {@inheritdoc} */
public function getTemplate()
{
public function getTemplate() {
return $this->template;
}
}
1 change: 0 additions & 1 deletion src/lib/Sage/Template/WrapperInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @author QWp6t
*/
interface WrapperInterface {

/**
* Get a list of potential wrappers
* Useful for passing to WordPress's locate_template()
Expand Down
19 changes: 10 additions & 9 deletions src/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

use Roots\Sage\Template;

/**
* Theme assets
*/
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true);
}, 100);

/**
* Theme setup
*/
Expand Down Expand Up @@ -29,7 +37,7 @@
add_theme_support('title-tag');

/**
* Register wp_nav_menu() menus
* Register navigation menus
* @link http://codex.wordpress.org/Function_Reference/register_nav_menus
*/
register_nav_menus([
Expand Down Expand Up @@ -58,7 +66,7 @@

/**
* Use main stylesheet for visual editor
* @see /assets/styles/layouts/_tinymce.scss
* @see assets/styles/layouts/_tinymce.scss
*/
add_editor_style(asset_path('styles/main.css'));
});
Expand All @@ -82,10 +90,3 @@
register_sidebar($config('Footer'));
});

/**
* Theme assets
*/
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('sage/main.css', asset_path('styles/main.css'), false, null);
wp_enqueue_script('sage/main.js', asset_path('scripts/main.js'), ['jquery'], null, true);
}, 100);

0 comments on commit 67c190f

Please sign in to comment.