-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRye.php
169 lines (149 loc) · 4.16 KB
/
Rye.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
namespace Rye;
use Rye\Grain;
/**
* There generally isn't a reason to touch this class unless you want to.
**/
class Rye
{
// Enviornment constants for convenience.
const PRODUCTION = 10;
const STAGING = 20;
const TESTING = 30;
const DEVELOPMENT = 40;
/**
* @var object Reference to Grain instance.
*/
public static $grain;
/**
* @var int Current enviornment variable.
*/
public static $enviornment = Rye::DEVELOPMENT;
/**
* @var array Internal configuration hash array.
*/
private static $_config = array();
/**
* JSON decode the package.json file.
* @return {object}
*/
public static function package()
{
return json_decode(file_get_contents(get_template_directory()."/package.json"));
}
/**
* Create a safe name to use for such things as compiled asset filenames.
* @return {string}
*/
public static function projectName()
{
$package = self::package();
return sanitize_title($package->name);
}
/**
* Output the stylesheet html.
* @return {string}
*/
public static function stylesheet()
{
if (Rye::$enviornment > Rye::PRODUCTION) {
$path = get_bloginfo('template_directory').'/assets/dist/'.Rye::projectName().'.css';
} else {
$path = get_bloginfo('template_directory').'/assets/dist/'.Rye::projectName().'.min.css';
}
return '<link rel="stylesheet" type="text/css" media="all" href="'.$path.'" />';
}
/**
* Register JavaScripts.
* @return {void}
*/
private static function register_scripts()
{
if (!is_admin()) {
foreach (self::$_config['javascripts'] as $name => $path) {
wp_deregister_script($name);
wp_register_script($name, $path, array(), false, false);
wp_enqueue_script($name, $path, array(), false, false);
}
}
}
/**
* Register sidebar regions.
* @return {void}
*/
private static function register_regions()
{
foreach (self::$_config['widgetized_regions'] as $region) {
register_sidebar($region);
}
}
/**
* Register taxonomies.
* @return {void}
*/
private static function register_taxonomies()
{
foreach (self::$_config['taxonomies'] as $taxonomy) {
register_taxonomy($taxonomy[0], $taxonomy[1], $taxonomy[2]);
}
}
/**
* Register post types.
* @return {void}
*/
private static function register_post_types()
{
foreach (self::$_config['post_types'] as $name => $type) {
register_post_type($name, $type);
}
}
/**
* Register image sizes.
* @return {void}
*/
private static function register_image_sizes()
{
foreach (self::$_config['image_sizes'] as $name => $args) {
add_image_size($name, $args[0], $args[1], $args[2]);
}
}
/**
* Add various types of theme support.
* @return {void}
*/
private static function add_theme_support()
{
foreach (self::$_config['theme_support'] as $name => $args) {
add_theme_support($name, $args);
}
}
/**
* Initialize the site the way WP likes it. This will be called on
* the init hook.
* @return {void}
*/
public static function _init()
{
register_nav_menus(self::$_config['menus']);
self::register_scripts();
self::register_regions();
self::register_taxonomies();
self::register_post_types();
self::register_image_sizes();
self::add_theme_support();
}
/**
* Set the hook for initiating WP.
* @return {void}
*/
public static function init(array $rye_config)
{
// Set internal config property.
self::$_config = $rye_config;
// Init Grain.
self::$grain = new Grain();
// Hook the Rye initialization method with WordPress init.
// http://codex.wordpress.org/Function_Reference/add_action
add_action('init', array('Rye\Rye', '_init'));
}
}