Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version ID now automatically added to boilerplate

  • Loading branch information...
commit 3d6939011cb6b6e2f6e6e2116facb9fdc93373e9 1 parent 4489b1c
Pete Boere authored May 09, 2012
2  CssCrush.boilerplate
... ...
@@ -1,2 +1,2 @@
1 1
 CSS Crush(ed) on {{datetime}}
2  
-http://github.com/peteboere/css-crush
  2
+http://github.com/peteboere/css-crush ({{version}})
2  CssCrush.php
@@ -22,7 +22,7 @@
22 22
 require_once 'lib/Regex.php';
23 23
 require_once 'lib/Hook.php';
24 24
 
25  
-csscrush::init( dirname( __FILE__ ) );
  25
+csscrush::init( __FILE__ );
26 26
 
27 27
 
28 28
 
19  lib/Core.php
@@ -21,12 +21,17 @@ class csscrush {
21 21
 
22 22
 
23 23
 	// Init called once manually post class definition
24  
-	public static function init ( $current_dir ) {
  24
+	public static function init ( $seed_file ) {
25 25
 
26 26
 		self::$config = new stdclass();
27 27
 
28 28
 		// Path to this installation
29  
-		self::$config->location = $current_dir;
  29
+		self::$config->location = dirname( $seed_file );
  30
+
  31
+		// Get version ID from seed file
  32
+		$seed_file_contents = file_get_contents( $seed_file );
  33
+		$match_count = preg_match( '!@version\s+([\d\.]+)!', $seed_file_contents, $version_match );
  34
+		self::$config->version = $match_count ? $version_match[1] : null;
30 35
 
31 36
 		// Set the docRoot reference
32 37
 		self::setDocRoot();
@@ -468,19 +473,25 @@ protected static function getBoilerplate () {
468 473
 		// Load the file
469 474
 		$boilerplate = file_get_contents( $file );
470 475
 
471  
-		// Process any tags, currently only '{{datetime}}' is supported
  476
+		// Substitute any tags
472 477
 		if ( preg_match_all( '!\{\{([^}]+)\}\}!', $boilerplate, $boilerplate_matches ) ) {
  478
+
473 479
 			$replacements = array();
474 480
 			foreach ( $boilerplate_matches[0] as $index => $tag ) {
475  
-				if ( $boilerplate_matches[1][$index] === 'datetime' ) {
  481
+				$tag_name = $boilerplate_matches[1][$index];
  482
+				if ( $tag_name === 'datetime' ) {
476 483
 					$replacements[] = @date( 'Y-m-d H:i:s O' );
477 484
 				}
  485
+				elseif ( $tag_name === 'version' ) {
  486
+					$replacements[] = 'v' . csscrush::$config->version;
  487
+				}
478 488
 				else {
479 489
 					$replacements[] = '?';
480 490
 				}
481 491
 			}
482 492
 			$boilerplate = str_replace( $boilerplate_matches[0], $replacements, $boilerplate );
483 493
 		}
  494
+
484 495
 		// Pretty print
485 496
 		$boilerplate = explode( PHP_EOL, $boilerplate );
486 497
 		$boilerplate = array_map( 'trim', $boilerplate );

0 notes on commit 3d69390

Please sign in to comment.
Something went wrong with that request. Please try again.