Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit 7c7a551

Browse files
committed
Merge pull request #31 from synapticism/develop
Develop
2 parents 81c5c36 + 2a1cea8 commit 7c7a551

File tree

12 files changed

+56
-58
lines changed

12 files changed

+56
-58
lines changed

gulpconfig.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ module.exports = {
5353
, chunks: { // Chunks are arrays of paths or globs matching a set of source files; this way you can organize a bunch of scripts that go together into pieces that can then be bundled (above)
5454
// The core chunk is loaded no matter what; put essential scripts that you want loaded by your theme in here
5555
core: [
56-
modules+'timeago/jquery.timeago.js'
56+
modules+'timeago/jquery.timeago.js' // The modules directory contains packages downloaded via npm
5757
, src+'js/responsive-menu.js'
5858
, src+'js/core.js'
5959
]
6060
// The pageloader chunk provides an example of how you would add a user-configurable feature to your theme; you can delete this if you wish
6161
// Have a look at the `src/inc/assets.php` to see how script bundles could be conditionally loaded by a theme
6262
, pageloader: [
63-
modules+'html5-history-api/history.js' // The modules directory contains packages downloaded via npm
63+
modules+'html5-history-api/history.js'
6464
, modules+'spin.js/spin.js'
6565
, modules+'spin.js/jquery.spin.js'
6666
, modules+'wp-ajax-page-loader/wp-ajax-page-loader.js'
@@ -72,8 +72,7 @@ module.exports = {
7272
src: [src+'js/**/*.js'] // Linting checks the quality of the code; we only lint custom scripts, not those under the various modules, so we're relying on the original authors to ship quality code
7373
}
7474
, minify: {
75-
src: [build+'js/**/*.js', '!'+build+'js/**/*.min.js'] // Avoid recursive min.min.min.js
76-
, rename: { suffix: '.min' }
75+
src: build+'js/**/*.js'
7776
, uglify: {} // Default options
7877
, dest: build+'js/'
7978
}

gulpfile.js/tasks/images.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ gulp.task('images', function() {
1313
});
1414

1515
// Optimize images in the `dist` folder (slow)
16-
gulp.task('images-dist', ['utils-dist'], function() {
16+
gulp.task('images-optimize', ['utils-dist'], function() {
1717
return gulp.src(config.dist.src)
1818
.pipe(plugins.imagemin(config.dist.imagemin))
1919
.pipe(gulp.dest(config.dist.dest));

gulpfile.js/tasks/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ gulp.task('build', ['images', 'scripts', 'styles', 'theme']);
1313

1414
// Dist task chain: wipe -> build -> clean -> copy -> compress images
1515
// NOTE: this is a resource-intensive task!
16-
gulp.task('dist', ['images-dist']);
16+
gulp.task('dist', ['images-optimize']);

gulpfile.js/tasks/scripts.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var gulp = require('gulp')
99
// Check core scripts for errors
1010
gulp.task('scripts-lint', function() {
1111
return gulp.src(config.lint.src)
12-
.pipe(plugins.jshint('.jshintrc'))
12+
.pipe(plugins.jshint())
1313
.pipe(plugins.jshint.reporter('default')); // No need to pipe this anywhere
1414
});
1515

@@ -47,8 +47,9 @@ gulp.task('scripts-bundle', ['scripts-lint'], function(){
4747
// Minify scripts in place
4848
gulp.task('scripts-minify', ['scripts-bundle'], function(){
4949
return gulp.src(config.minify.src)
50-
.pipe(plugins.rename(config.minify.rename))
50+
.pipe(plugins.sourcemaps.init())
5151
.pipe(plugins.uglify(config.minify.uglify))
52+
.pipe(plugins.sourcemaps.write('./'))
5253
.pipe(gulp.dest(config.minify.dest));
5354
});
5455

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wordpress-gulp-starter-kit",
3-
"version": "0.2.1",
3+
"version": "0.2.2",
44
"description": "A starter kit for developing WordPress themes with Gulp",
55
"homepage": "https://github.com/synapticism/wordpress-gulp-starter-kit",
66
"repository": {
@@ -50,7 +50,7 @@
5050
"scut": "^1.4.0",
5151
"spin.js": "^2.3.2",
5252
"timeago": "^1.5.2",
53-
"wp-ajax-page-loader": "^0.2.0"
53+
"wp-ajax-page-loader": "^0.2.1"
5454
},
5555
"scripts": {
5656
"postinstall": "gulp setup"

readme.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ If you're already up and running with most of the usual Node ecosystem tools thi
3838
* Install all dependencies by running `npm install`. This will fetch all dependencies listed in `package.json` (which includes front-end JavaScript packages and back-end tools like Gulp plugins and [BrowserSync](http://www.browsersync.io/)).
3939
* [BrowserSync](http://www.browsersync.io/) setup: assuming you have a local development environment setup all you should need to do is enter the URL into the `proxy` setting in `gulpconfig.js`. Why use BrowserSync? It's fast, awesome, and allows for simultaneous responsive development across multiple devices.
4040
* [LiveReload](http://livereload.com/) setup: install a browser extension for [Chrome](https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei) or Firefox. Why use LiveReload? It does the job without complications or additional setup after the extension is installed.
41+
* This build process assumes you're up and running with [source maps for both JavaScript and Sass](http://blog.teamtreehouse.com/introduction-source-maps). You may need to configure your browser or debugging environment to make sense of the minified files generated by Gulp!
4142
* Run `gulp` and start hacking!
4243

4344

@@ -53,7 +54,7 @@ There are two components worth a closer look:
5354
* The script variable and enqueuing functions in `src/inc/assets.php`; these are tightly coupled with the output of the build process.
5455
* The theme configuration pattern described in `functions.php` and `functions-config-defaults.php`.
5556

56-
Whether you use anything from this built-in theme is entirely up to you. If you prefer to start working with your own theme just drop it in. You may need to go into `gulpconfig.js` and modify paths and glob matching patterns but this is designed to be fairly easy and straight-forward with lots of comments to point you in the right direction.
57+
Whether you use anything from this built-in theme is entirely up to you. If you prefer to start working with your own theme just drop it in. You will probably need to modify paths and glob matching patterns in `gulpconfig.js` but it is designed to be fairly easy and straight-forward with lots of comments to point you in the right direction.
5758

5859

5960

@@ -82,7 +83,7 @@ Configuration is handled by a single file: `gulpconfig.js`. If you leave the dir
8283
* [BrowserSync](http://www.browsersync.io/) settings: if you are developing on a local web server you will want to enter the URL into `browsersync.proxy` and then change `watch.watcher` to `browsersync` to take it for a test drive. You'll know it's working when you run `gulp` and a new browser opens with a live copy of your web site. Make changes to any of the Sass files and they should be shown on the page almost immediately. Of course, BrowserSync really shines when you connect a mobile device to your development server, but for that you're on your own ;)
8384
* Script settings: draw your attention to `scripts.bundles` and `scripts.chunks`. This feature is essentially a poor man's [Browserify](http://browserify.org/) or [Webpack](https://webpack.github.io/). By defining different "chunks" (script files that combine to provide a particular feature) and "bundles" (chunks that combine to provide feature sets) you can generate an assortment of files that can be efficiently and intelligently loaded through your WordPress theme. This approach has its limitations, of course, particularly when dependencies are shared between scripts, but it should be of use to many WordPress theme developers.
8485

85-
Interested in adding new Gulp plugins to your build system? A full tutorial is out of scope for this project but it really shouldn't be all that hard to figure out. In brief, install a plugin with `npm install [package] --save-dev`, require it in a suitable task file, add something to the configuration file if needed, and drop it into the pipeline somewhere. Some types of plugin are particularly easy to add, for instance anything listed on the [postcss.parts](http://postcss.parts/) web site (install, require, and add to the `processor` variable in `./gulpfile.js/tasks/styles.js`).
86+
Interested in adding new Gulp plugins to your build system? A full tutorial is out of scope for this project but it really shouldn't be all that hard to figure out. In brief, install a plugin with `npm install [package] --save-dev`, require it in a suitable task file, add something to the configuration file if needed, and drop it into the pipeline somewhere. Some types of plugin are particularly easy to add, for instance anything listed on the [postcss.parts](http://postcss.parts/) web site (install, require, and add to the `processor` variable in `/gulpfile.js/tasks/styles.js`).
8687

8788

8889

@@ -131,7 +132,9 @@ Like images, PHP (and language) files can go anywhere under `src` and will be co
131132

132133

133134

134-
## EXAMPLE INTEGRATION
135+
## EXAMPLE INTEGRATIONS
136+
137+
The bare bones theme included in this starter kit integrates two external JavaScript projects: [timeago](http://timeago.yarp.com/) (which facilitates human-readable timestamps) and [WP AJAX Page Loader](https://github.com/synapticism/wp-ajax-page-loader) (a lightweight and intelligent infinite scroll script). Have a look at the `/src/inc/assets.php` file and `gulpconfig.js` to see how this was accomplished. Timeago required only `npm install -d timeago`, an extra line in `gulpconfig.js`, and initialization in `/src/js/core.js`. Integrating the other script was much more involved; you'll have to browse the source and see for yourself.
135138

136139
Let's say you run across a cool project like [Headroom.js](http://wicky.nillia.ms/headroom.js/) and decide you'd like to try it out. Here's how you would do that with the tools and workflow outlined in this repo:
137140

src/header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
1818
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
1919
</div>
20+
<button id="responsive-menu-toggle"><?php _e( 'Menu', 'voidx' ); ?></button>
2021
<nav id="site-navigation" class="site-navigation">
21-
<button id="responsive-menu-toggle"><?php _e( 'Menu', 'voidx' ); ?></button>
2222
<div id="responsive-menu"><?php wp_nav_menu( array( 'theme_location' => 'header', 'menu_id' => 'menu-header', 'menu_class' => 'menu-inline' ) ); ?></div>
2323
</nav>
2424
</header>

src/inc/assets.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,64 @@
11
<?php // ==== ASSETS ==== //
22

33
// Now that you have efficiently generated scripts and stylesheets for your theme, how should they be integrated?
4-
// This file walks you through the approach I use but you are free to approach this any way you like
4+
// This file walks you through the approach I use but you are free to do this any way you like
55

66
// Enqueue front-end scripts and styles
77
function voidx_enqueue_scripts() {
88

9-
$script_name = ''; // Empty by default, may be populated by conditionals below
9+
$script_name = ''; // Empty by default, may be populated by conditionals below; this is used to generate the script filename
1010
$script_vars = array(); // An empty array that can be filled with variables to send to front-end scripts
11-
$script_handle = 'voidx'; // A generic script handle
12-
$suffix = '.min'; // The suffix for minified scripts
13-
$ns = 'wp'; // Namespace for scripts
14-
15-
// Load original scripts when debug mode is on; this allows for easier local development
16-
if ( WP_DEBUG === true )
17-
$suffix = '';
11+
$script_handle = 'voidx'; // A generic script handle used internally by WordPress
12+
$ns = 'wp'; // Namespace for scripts; this should match what is specified in your `gulpconfig.js` (and it's safe to leave alone)
1813

1914
// Figure out which script bundle to load based on various options set in `src/functions-config-defaults.php`
20-
// Note: bundles require less HTTP requests at the expense of addition caching hits when different scripts are requested
21-
// You could also load one main bundle on every page with supplementary scripts as needed (e.g. for commenting or a contact page)
15+
// Note: bundles require fewer HTTP requests at the expense of addition caching hits when different scripts are requested on different pages of your site
16+
// You could also load one main bundle on every page with supplementary scripts as needed (e.g. for commenting or a contact page); it's up to you!
17+
18+
19+
20+
// == EXAMPLE INTEGRATION == //
2221

2322
// An example integration using WP AJAX Page Loader; this script requires a bit more setup as outlined in the documentation: https://github.com/synapticism/wp-ajax-page-loader
2423
$script_vars_page_loader = '';
2524

2625
// This conditional establishes whether the page loader bundle is loaded or not; you can turn this off completely from the theme configuration file if you wish (or just remove the code)
2726
if ( VOIDX_SCRIPTS_PAGELOAD && ( is_archive() || is_home() || is_search() ) ) {
28-
$script_name .= '-pageloader'; // This is used to generate the filename that the theme will serve to the user; it is additive to allow for multiple features that can be toggled in the theme configuration
2927

30-
global $wp_query;
28+
// The script name is used to specify the file that the theme will serve to users
29+
// Script names are designed to be additive (meaning you can append more script names to the end in other conditional blocks using `.= '-anotherscript'` etc.) to allow for multiple feature toggles in the theme configuration
30+
$script_name .= '-pageloader';
3131

32-
// This chunk of code provisions the script with some important information it needs: What page are we on? And what is the page limit?
32+
// This chunk of code provisions the WP AJAX Page Loader script with some important information it needs: What page are we on? And what is the page limit?
33+
global $wp_query;
3334
$max = $wp_query->max_num_pages;
3435
$paged = ( get_query_var( 'paged' ) > 1 ) ? get_query_var( 'paged' ) : 1;
3536

36-
// Prepare script variables; note that these are separate from the rest of the script variables as this script requires everything in an object named `PG8Data`
37+
// Prepare script variables; note that these are separate from the rest of the script variables as the WP AJAX Page Loader script requires everything in a specific object named `PG8Data`
3738
$script_vars_page_loader = array(
3839
'startPage' => $paged,
3940
'maxPages' => $max,
4041
'nextLink' => next_posts( $max, false )
4142
);
4243
} // WP AJAX Page Loader configuration ends
4344

44-
// Default script name
45+
46+
47+
// Default script name; used when conditional blocks (above) aren't triggered
4548
if ( empty( $script_name ) )
4649
$script_name = '-core';
4750

4851
// Load theme-specific JavaScript bundles with versioning based on last modified time; http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/
4952
// The handle is the same for each bundle since we're only loading one script; if you load others be sure to provide a new handle
50-
wp_enqueue_script( $script_handle, get_stylesheet_directory_uri() . '/js/' . $ns . $script_name . $suffix . '.js', array( 'jquery' ), filemtime( get_template_directory() . '/js/' . $ns . $script_name . $suffix . '.js' ), true );
53+
wp_enqueue_script( $script_handle, get_stylesheet_directory_uri() . '/js/' . $ns . $script_name . '.js', array( 'jquery' ), filemtime( get_template_directory() . '/js/' . $ns . $script_name . '.js' ), true );
5154

5255
// Pass variables to JavaScript at runtime; see: http://codex.wordpress.org/Function_Reference/wp_localize_script
5356
$script_vars = apply_filters( 'voidx_script_vars', $script_vars );
5457
if ( !empty( $script_vars ) )
5558
wp_localize_script( $script_handle, 'voidxVars', $script_vars );
5659

57-
// Script variables for WP AJAX Page Loader (these are separate from the main theme script variables due to the naming requirement; the object must be `PG8Data`)
60+
// Script variables specific to WP AJAX Page Loader (these are separate from the main theme script variables due to the naming requirement; the object must be `PG8Data`)
61+
// This appears and NOT in the conditional block (above) because these variables will be attached to the main script handle (which may be modified after the page loader block)
5862
if ( !empty( $script_vars_page_loader ) )
5963
wp_localize_script( $script_handle, 'PG8Data', $script_vars_page_loader );
6064

@@ -70,7 +74,7 @@ function voidx_enqueue_scripts() {
7074
// Provision the front-end with the appropriate script variables
7175
function voidx_update_script_vars( $script_vars = array() ) {
7276

73-
// Non-destructively merge script variables if a particular condition is met (e.g. `is_archive()` or whatever)
77+
// Non-destructively merge script variables if a particular condition is met (e.g. `is_archive()` or whatever); useful for managing many different kinds of script variables
7478
if ( 1 == 1 ) {
7579
$script_vars = array_merge( $script_vars, array(
7680
'ajaxUrl' => admin_url( 'admin-ajax.php' ),

src/js/responsive-menu.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ==== RESPONSIVE NAVIGATION MENU ==== //
1+
// ==== RESPONSIVE MENU ==== //
22

33
// Menu toggle script adapted from _s: https://github.com/Automattic/_s
44
;(function() {
@@ -19,16 +19,12 @@
1919

2020
// Toggle navigation; add or remove a class to both the button and the nav element itself
2121
button.onclick = function() {
22-
if (button.className.indexOf( 'toggled' ) !== -1) {
23-
button.className = button.className.replace(' toggled', '');
22+
if (button.className.indexOf( 'active' ) !== -1) {
23+
nav.style.display = 'none';
24+
button.className = button.className.replace(' active', '');
2425
} else {
25-
button.className += ' toggled';
26-
}
27-
28-
if (menu.className.indexOf( 'toggled' ) !== -1) {
29-
menu.className = menu.className.replace(' toggled', '');
30-
} else {
31-
menu.className += ' toggled';
26+
nav.style.display = 'block';
27+
button.className += ' active';
3228
}
3329
};
3430
} )();

src/scss/_config.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $_metadata: (
3030
, theme-author: "Alexander Synaptic"
3131
, theme-author-uri: "http://synapticism.com"
3232
, theme-description: "A minimally viable theme made with the WordPress/Gulp starter kit"
33-
, theme-version: "0.2.1"
33+
, theme-version: "0.2.2"
3434
, theme-license: "GPLv3"
3535
, theme-license-uri: "http://www.gnu.org/licenses/gpl.txt"
3636
, theme-tags: (light, responsive-layout, right-sidebar, starter-theme, two-columns, translation-ready, white)

0 commit comments

Comments
 (0)