Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
add summaryOnly option
Browse files Browse the repository at this point in the history
ref: #25
  • Loading branch information
hariadi committed Apr 1, 2014
1 parent 7ee8ec8 commit dea05f9
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 7 deletions.
25 changes: 25 additions & 0 deletions Gruntfile.js
Expand Up @@ -21,6 +21,31 @@ module.exports = function(grunt) {
'test/fixtures/script2.php': ['test/fixtures/assets/css/main.min.css', 'test/fixtures/assets/js/scripts.min.js']
}
},
roots: {
options: {
summaryOnly: true,
length: 8,
manifest: 'test/fixtures/assets/assets-manifest.json',
},
files: {
'test/fixtures/script3.php': ['test/fixtures/assets/css/main.min.css', 'test/fixtures/assets/js/scripts.min.js']
}
},
rootsQuerystring: {
options: {
summaryOnly: true,
format: true,
length: 32,
manifest: 'test/fixtures/assets/assets-manifest-querystring.json',
querystring: {
style: 'roots_css',
script: 'roots_js'
}
},
files: {
'test/fixtures/script3.php': ['test/fixtures/assets/css/main.min.css', 'test/fixtures/assets/js/scripts.min.js']
}
},
withConfig: {
options: {
format: true,
Expand Down
8 changes: 5 additions & 3 deletions tasks/version.js
Expand Up @@ -25,7 +25,8 @@ module.exports = function(grunt) {
length: 8,
rename: false,
querystring: {},
manifest: false
manifest: false,
summaryOnly: false
});
var manifest = grunt.manifest || {}, summary = {};

Expand Down Expand Up @@ -117,8 +118,9 @@ module.exports = function(grunt) {
if(typeof summary !== 'undefined'){
manifest[file] = summary;
}
grunt.file.write(files.dest, wpcontent);

if (!options.summaryOnly) {
grunt.file.write(files.dest, wpcontent);
}
});
next();
}, this.async());
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/assets/assets-manifest-querystring.json
@@ -0,0 +1,14 @@
{
"dest": "test/fixtures/assets/assets-manifest-querystring.json",
"test/fixtures/assets/css/main.min.css": {
"path": "test/fixtures/assets/css/main.min.css",
"hash": "51ea71910a6813fdd9ad5aeb250b2857",
"handle": "roots_css"
},
"test/fixtures/assets/js/scripts.min.js": {
"path": "test/fixtures/assets/js/scripts.min.js",
"hash": "71a67acb0cf0c504f45412f383d5a231",
"handle": "roots_js"
},
"querystring": true
}
11 changes: 11 additions & 0 deletions test/fixtures/assets/assets-manifest.json
@@ -0,0 +1,11 @@
{
"dest": "test/fixtures/assets/assets-manifest.json",
"test/fixtures/assets/css/main.min.css": {
"path": "test/fixtures/assets/css/main.min.css",
"hash": "51ea7191"
},
"test/fixtures/assets/js/scripts.min.js": {
"path": "test/fixtures/assets/js/scripts.min.js",
"hash": "71a67acb"
}
}
8 changes: 4 additions & 4 deletions test/fixtures/assets/manifest.json
Expand Up @@ -3,16 +3,16 @@
"test/fixtures/assets/css/main.min.css": {
"path": "test/fixtures/assets/css/main.min.css",
"hash": "51ea71910a6813fdd9ad5aeb250b2857",
"handle": "roots_main"
"handle": "roots_css"
},
"test/fixtures/assets/js/scripts.min.js": {
"path": "test/fixtures/assets/js/scripts.min.js",
"hash": "71a67acb0cf0c504f45412f383d5a231",
"handle": "roots_scripts"
"handle": "roots_js"
},
"querystring": true,
"test/fixtures/assets/css/custom.min.css": {
"path": "test/fixtures/assets/css/custom.min.css",
"hash": "45f8aa1a"
},
"querystring": true
}
}
1 change: 1 addition & 0 deletions test/fixtures/assets/manifest_withConfig.json
Expand Up @@ -8,6 +8,7 @@
"path": "test/fixtures/assets/js/scripts.min.js",
"hash": "bbe2121b"
},
"querystring": true,
"test/fixtures/assets/css/custom.min.css": {
"path": "test/fixtures/assets/css/custom.min.css",
"hash": "45f8aa1a"
Expand Down
96 changes: 96 additions & 0 deletions test/fixtures/script3.php
@@ -0,0 +1,96 @@
<?php
/**
* Scripts and stylesheets
*
* Enqueue stylesheets in the following order:
* 1. /theme/assets/css/main.css
*
* Enqueue scripts in the following order:
* 1. jquery-1.11.0.min.js via Google CDN
* 2. /theme/assets/js/vendor/modernizr.min.js
* 3. /theme/assets/js/scripts.js (in footer)
*
* Google Analytics is loaded after enqueued scripts if:
* - An ID has been defined in config.php
* - You're not logged in as an administrator
*/
function roots_scripts() {
/**
* The build task in Grunt renames production assets with a hash
* Read the asset names from assets-manifest.json
*/
if (!(WP_ENV === 'development')) {
$get_assets = file_get_contents(get_template_directory_uri() . '/assets/manifest.json');
$assets = json_decode($get_assets, true);
$assets = array(
'css' => '/assets/css/main.min.css' . '?' . $assets['assets/css/main.min.css']['hash'],
'js' => '/assets/js/scripts.min.js' . '?' . $assets['assets/js/scripts.min.js']['hash'],
'modernizr' => '/assets/js/vendor/modernizr.min.js',
'jquery' => '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js'
);
} else {
$assets = array(
'css' => '/assets/css/main.css',
'js' => '/assets/js/scripts.js',
'modernizr' => '/assets/js/vendor/modernizr.min.js',
'jquery' => '//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js'
);
}

wp_enqueue_style('roots_css', get_template_directory_uri() . $assets['css'], false, null);

/**
* jQuery is loaded using the same method from HTML5 Boilerplate:
* Grab Google CDN's latest jQuery with a protocol relative URL; fallback to local if offline
* It's kept in the header instead of footer to avoid conflicts with plugins.
*/
if (!is_admin() && current_theme_supports('jquery-cdn')) {
wp_deregister_script('jquery');
wp_register_script('jquery', $assets['jquery'], array(), null, false);
add_filter('script_loader_src', 'roots_jquery_local_fallback', 10, 2);
}

if (is_single() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}

wp_enqueue_script('modernizr', get_template_directory_uri() . $assets['modernizr'], array(), null, false);
wp_enqueue_script('jquery');
wp_enqueue_script('roots_js', get_template_directory_uri() . $assets['js'], array(), null, true);
}
add_action('wp_enqueue_scripts', 'roots_scripts', 100);

// http://wordpress.stackexchange.com/a/12450
function roots_jquery_local_fallback($src, $handle = null) {
static $add_jquery_fallback = false;

if ($add_jquery_fallback) {
echo '<script>window.jQuery || document.write(\'<script src="' . get_template_directory_uri() . '/assets/vendor/jquery/jquery.min.js"><\/script>\')</script>' . "\n";
$add_jquery_fallback = false;
}

if ($handle === 'jquery') {
$add_jquery_fallback = true;
}

return $src;
}
add_action('wp_head', 'roots_jquery_local_fallback');

/**
* Google Analytics snippet from HTML5 Boilerplate
*/
function roots_google_analytics() { ?>
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','<?php echo GOOGLE_ANALYTICS_ID; ?>');ga('send','pageview');
</script>

<?php }
if (GOOGLE_ANALYTICS_ID && !current_user_can('manage_options')) {
add_action('wp_footer', 'roots_google_analytics', 20);
}

0 comments on commit dea05f9

Please sign in to comment.