Skip to content

Commit

Permalink
Conform to new rules
Browse files Browse the repository at this point in the history
  • Loading branch information
QWp6t authored and retlehs committed Mar 11, 2016
1 parent 2d02544 commit 6a4d3bd
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 288 deletions.
4 changes: 2 additions & 2 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* themes/sage/index.php also contains some self-correcting code, just in case the template option gets reset
*/
add_filter('template', function ($template) {
return dirname($template);
return dirname($template);
});
add_action('after_switch_theme', function () {
update_option('template', get_option('template') . '/templates');
update_option('template', get_option('template') . '/templates');
});

/**
Expand Down
13 changes: 8 additions & 5 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
<ruleset name="Roots">
<description>Roots Coding Standards</description>

<!-- Use PSR-2 as a base -->
<rule ref="PSR2"/>
<!-- Scan these files -->
<file>functions.php</file>
<file>src</file>

<!-- Show colors in console -->
<arg value="-colors"/>

<!-- Show sniff codes in all reports -->
<arg value="s"/>

<!-- Scan these files -->
<file>functions.php</file>
<file>src</file>
<!-- Use PSR-2 as a base -->
<rule ref="PSR2">
<!-- Allow braces on same line for procedural functions -->
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine"/>
</rule>
</ruleset>
6 changes: 3 additions & 3 deletions src/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* Theme customizer
*/
add_action('customize_register', function (\WP_Customize_Manager $wp_customize) {
// Add postMessage support
$wp_customize->get_setting('blogname')->transport = 'postMessage';
// Add postMessage support
$wp_customize->get_setting('blogname')->transport = 'postMessage';
});

/**
* Customizer JS
*/
add_action('customize_preview_init', function () {
wp_enqueue_script('sage/customizer.js', asset_path('scripts/customizer.js'), ['customize-preview'], null, true);
wp_enqueue_script('sage/customizer.js', asset_path('scripts/customizer.js'), ['customize-preview'], null, true);
});
40 changes: 20 additions & 20 deletions src/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,45 @@
*/
add_filter('sage/display_sidebar', function ($display) {
// The sidebar will NOT be displayed if ANY of the following return true
return $display ? !in_array(true, [
is_404(),
is_front_page(),
is_page_template('template-custom.php'),
]) : $display;
return $display ? !in_array(true, [
is_404(),
is_front_page(),
is_page_template('template-custom.php'),
]) : $display;
});

/**
* Add <body> classes
*/
add_filter('body_class', function (array $classes) {
// Add page slug if it doesn't exist
if (is_single() || is_page() && !is_front_page()) {
if (!in_array(basename(get_permalink()), $classes)) {
$classes[] = basename(get_permalink());
// Add page slug if it doesn't exist
if (is_single() || is_page() && !is_front_page()) {
if (!in_array(basename(get_permalink()), $classes)) {
$classes[] = basename(get_permalink());
}
}
}

// Add class if sidebar is active
if (display_sidebar()) {
$classes[] = 'sidebar-primary';
}
// Add class if sidebar is active
if (display_sidebar()) {
$classes[] = 'sidebar-primary';
}

return $classes;
return $classes;
});

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

/**
* Use theme wrapper
*/
add_filter('template_include', function ($main) {
if (!is_string($main) || !(string) $main) {
return $main;
}
return template_wrap(new Wrapper(basename($main)));
if (!is_string($main) || !(string) $main) {
return $main;
}
return template_wrap(new Wrapper(basename($main)));
}, 109);
48 changes: 24 additions & 24 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,53 @@
use Roots\Sage\Template\WrapperInterface;

function template_wrap(WrapperInterface $wrapper, $slug = 'base') {
WrapperCollection::add($wrapper, $slug);
return $wrapper->getWrapper();
WrapperCollection::add($wrapper, $slug);
return $wrapper->getWrapper();
}

function template_unwrap($slug = 'base') {
return WrapperCollection::get($slug)->getTemplate();
return WrapperCollection::get($slug)->getTemplate();
}

/**
* @param $filename
* @return string
*/
function asset_path($filename) {
static $manifest;
isset($manifest) || $manifest = new JsonManifest(get_template_directory() . '/' . Asset::$dist . '/assets.json');
return (string) new Asset($filename, $manifest);
static $manifest;
isset($manifest) || $manifest = new JsonManifest(get_template_directory() . '/' . Asset::$dist . '/assets.json');
return (string) new Asset($filename, $manifest);
}

/**
* Determine whether to show the sidebar
* @return bool
*/
function display_sidebar() {
static $display;
isset($display) || $display = apply_filters('sage/display_sidebar', true);
return $display;
static $display;
isset($display) || $display = apply_filters('sage/display_sidebar', true);
return $display;
}

/**
* Page titles
* @return string
*/
function title() {
if (is_home()) {
if ($home = get_option('page_for_posts', true)) {
return get_the_title($home);
if (is_home()) {
if ($home = get_option('page_for_posts', true)) {
return get_the_title($home);
}
return __('Latest Posts', 'sage');
}
return __('Latest Posts', 'sage');
}
if (is_archive()) {
return get_the_archive_title();
}
if (is_search()) {
return sprintf(__('Search Results for %s', 'sage'), get_search_query());
}
if (is_404()) {
return __('Not Found', 'sage');
}
return get_the_title();
if (is_archive()) {
return get_the_archive_title();
}
if (is_search()) {
return sprintf(__('Search Results for %s', 'sage'), get_search_query());
}
if (is_404()) {
return __('Not Found', 'sage');
}
return get_the_title();
}
37 changes: 19 additions & 18 deletions src/lib/Sage/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
* @package Roots\Sage
* @author QWp6t
*/
class Asset {
public static $dist = '/dist';
class Asset
{
public static $dist = '/dist';

/** @var ManifestInterface Currently used manifest */
protected $manifest;
/** @var ManifestInterface Currently used manifest */
protected $manifest;

protected $asset;
protected $asset;

protected $dir;
protected $dir;

public function __construct($file, ManifestInterface $manifest = null) {
$this->manifest = $manifest;
$this->asset = basename($file);
$this->dir = dirname($file) != '.' ? dirname($file) : '';
}
public function __construct($file, ManifestInterface $manifest = null) {
$this->manifest = $manifest;
$this->asset = basename($file);
$this->dir = dirname($file) != '.' ? dirname($file) : '';
}

public function __toString() {
return $this->getUri();
}
public function __toString() {
return $this->getUri();
}

public function getUri() {
$file = self::$dist . '/' . $this->dir . '/' . ($this->manifest ? $this->manifest->get($this->asset) : $this->asset);
return get_template_directory_uri() . $file;
}
public function getUri() {
$file = ($this->manifest ? $this->manifest->get($this->asset) : $this->asset);
return get_template_directory_uri() . self::$dist . '/' . $this->dir . '/' . $file;
}
}
40 changes: 22 additions & 18 deletions src/lib/Sage/Assets/JsonManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,29 @@
* @package Roots\Sage
* @author QWp6t
*/
class JsonManifest implements ManifestInterface {
/** @var array */
protected $manifest = [];
class JsonManifest implements ManifestInterface
{
/** @var array */
protected $manifest = [];

/**
* JsonManifest constructor
* @param string $manifestPath Local filesystem path to JSON-encoded manifest
*/
public function __construct($manifestPath) {
$this->manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : [];
}
/**
* JsonManifest constructor
* @param string $manifestPath Local filesystem path to JSON-encoded manifest
*/
public function __construct($manifestPath)
{
$this->manifest = file_exists($manifestPath) ? json_decode(file_get_contents($manifestPath), true) : [];
}

/** @inheritdoc */
public function get($file) {
return isset($this->manifest[$file]) ? $this->manifest[$file] : $file;
}
/** @inheritdoc */
public function get($file)
{
return isset($this->manifest[$file]) ? $this->manifest[$file] : $file;
}

/** @inheritdoc */
public function getAll() {
return $this->manifest;
}
/** @inheritdoc */
public function getAll()
{
return $this->manifest;
}
}
33 changes: 17 additions & 16 deletions src/lib/Sage/Assets/ManifestInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
* @package Roots\Sage
* @author QWp6t
*/
interface ManifestInterface {
/**
* Get the cache-busted filename
*
* If the manifest does not have an entry for $file, then return $file
*
* @param string $file The original name of the file before cache-busting
* @return string
*/
public function get($file);
interface ManifestInterface
{
/**
* Get the cache-busted filename
*
* If the manifest does not have an entry for $file, then return $file
*
* @param string $file The original name of the file before cache-busting
* @return string
*/
public function get($file);

/**
* Get the asset manifest
*
* @return array
*/
public function getAll();
/**
* Get the asset manifest
*
* @return array
*/
public function getAll();
}
Loading

0 comments on commit 6a4d3bd

Please sign in to comment.