Skip to content
This repository was archived by the owner on Oct 23, 2018. It is now read-only.

Commit 88e3168

Browse files
committed
new placeholders {{checksum}} {{timestamp}} & add timestamp to placeholder {{sprite}}
1 parent 344f5e4 commit 88e3168

File tree

3 files changed

+39
-23
lines changed

3 files changed

+39
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v1.2.2 - 2015-03
44

55
* [feature] configuration: add possibility to configure tile margins
6+
* [feature] new placeholders {{checksum}} {{timestamp}} & add timestamp to placeholder {{sprite}}
67
* [maintenance] new placeholder {{sprite}} in ratio template
78

89
## v1.2.1 - 2015-01-29

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ Spriter comes with the following default template:
105105

106106
The following placeholders can be used inside the global template:
107107

108-
* {{namespace}} = configured namespace
109-
* {{width}} = generated sprite width
110-
* {{height}} = generated sprite height
111108
* {{spriteFilepath}} = configured sprite directory
112109
* {{spriteFilename}} = configured sprite filename
113-
* {{sprite}} = {{spriteFilepath}}/{{spriteFilename}}.png
110+
* {{sprite}} = {{spriteFilepath}}/{{spriteFilename}}.png?{{timestamp}}
111+
* {{width}} = generated sprite width
112+
* {{height}} = generated sprite height
113+
* {{namespace}} = configured namespace
114+
* {{checksum}} = sprite checksum
115+
* {{timestamp}} = generation time
114116

115117
### Each Template
116118

@@ -160,15 +162,17 @@ This is the default template:
160162

161163
You can use the following placeholders:
162164

165+
* {{spriteFilepath}} = configured sprite directory
166+
* {{spriteFilename}} = configured sprite filename
167+
* {{sprite}} = {{spriteFilepath}}/{{spriteFilename}}{{delimiter}}{{ratio}}x.png?{{timestamp}}
163168
* {{ratio}} = the retina ratio value
164169
* {{ratioFrag}} = the retina ratio value as a fragment (for opera)
165-
* {{delimiter}} = the configured delimiter
166-
* {{namespace}} = configured namespace
167170
* {{width}} = generated sprite width
168171
* {{height}} = generated sprite height
169-
* {{spriteFilepath}} = configured sprite directory
170-
* {{spriteFilename}} = configured sprite filename
171-
* {{sprite}} = {{spriteFilepath}}/{{spriteFilename}}{{delimiter}}{{ratio}}x.png
172+
* {{delimiter}} = the configured delimiter
173+
* {{namespace}} = configured namespace
174+
* {{checksum}} = sprite checksum
175+
* {{timestamp}} = generation time
172176

173177
## Contributing
174178

spriter/spriter.class.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Spriter {
2424
protected $eachTemplate;
2525
protected $eachHoverTemplate;
2626
protected $ratioTemplate;
27+
protected $timestamp;
2728
protected $forceGenerate = false;
2829
protected $ignoreHover = false;
2930
protected $hoverSuffix = "-hover";
@@ -49,6 +50,7 @@ public function __construct( $config = array() ) {
4950
// setup & generation
5051
$this->setupIcons();
5152
if ( $this->hasChanged() || $this->forceGenerate ) {
53+
$this->timestamp = date( 'YmdHis', time() );
5254
$this->generateChecksum();
5355
$this->generateSprite();
5456
$this->generateCSS();
@@ -105,6 +107,15 @@ private function hasChanged() {
105107
return true;
106108
}
107109
}
110+
111+
// Check if the generated css file exists
112+
foreach ( $this->targets as $target ) {
113+
if ( !file_exists( $target['cssDirectory'] . "/" . $target['cssFilename'] ) ) {
114+
return true;
115+
}
116+
}
117+
118+
// Checksum comparison
108119
if ( file_exists( __DIR__ . "/" . $this->getChecksumName() ) ) {
109120
$lastChecksum = file_get_contents( __DIR__ . "/" . $this->getChecksumName() );
110121

@@ -115,12 +126,6 @@ private function hasChanged() {
115126
else {
116127
return true;
117128
}
118-
// Check if the generated css file exists
119-
foreach ( $this->targets as $target ) {
120-
if ( !file_exists( $target['cssDirectory'] . "/" . $target['cssFilename'] ) ) {
121-
return true;
122-
}
123-
}
124129

125130
return false;
126131
}
@@ -317,13 +322,16 @@ private function generateCSS() {
317322
$result = "";
318323

319324
$replacements = array(
320-
"{{spriteDirectory}}" => $this->spriteFilepath, // deprecated
321325
"{{spriteFilepath}}" => $this->spriteFilepath,
322326
"{{spriteFilename}}" => $this->spriteFilename,
323-
"{{sprite}}" => $this->spriteFilepath . "/" . $this->spriteFilename . ".png",
324-
"{{namespace}}" => $this->namespace,
327+
"{{sprite}}" => $this->spriteFilepath . "/" . $this->spriteFilename . ".png?" . $this->timestamp,
325328
"{{width}}" => $this->width . "px",
326-
"{{height}}" => $this->height . "px"
329+
"{{height}}" => $this->height . "px",
330+
"{{namespace}}" => $this->namespace,
331+
"{{checksum}}" => $this->spriteChecksum,
332+
"{{timestamp}}" => $this->timestamp,
333+
334+
"{{spriteDirectory}}" => $this->spriteFilepath // deprecated
327335
);
328336

329337
$result .= str_replace(
@@ -344,16 +352,19 @@ private function generateCSS() {
344352
foreach ( $this->retina as $ratio ) {
345353
if ( $ratio > 1 ) {
346354
$replacements = array(
347-
"{{spriteDirectory}}" => $this->spriteFilepath, // deprecated
348355
"{{spriteFilepath}}" => $this->spriteFilepath,
349356
"{{spriteFilename}}" => $this->spriteFilename,
350-
"{{sprite}}" => $this->spriteFilepath . "/" . $this->spriteFilename . $this->retinaDelimiter . $ratio . "x.png",
351-
"{{namespace}}" => $this->namespace,
357+
"{{sprite}}" => $this->spriteFilepath . "/" . $this->spriteFilename . $this->retinaDelimiter . $ratio . "x.png?" . $this->timestamp,
352358
"{{ratio}}" => $ratio,
353359
"{{ratioFrag}}" => $ratio . "/1",
354360
"{{width}}" => $this->width . "px",
355361
"{{height}}" => $this->height . "px",
356-
"{{delimiter}}" => $this->retinaDelimiter
362+
"{{delimiter}}" => $this->retinaDelimiter,
363+
"{{namespace}}" => $this->namespace,
364+
"{{checksum}}" => $this->spriteChecksum,
365+
"{{timestamp}}" => $this->timestamp,
366+
367+
"{{spriteDirectory}}" => $this->spriteFilepath, // deprecated
357368
);
358369
$ratios = str_replace(
359370
array_keys( $replacements ),

0 commit comments

Comments
 (0)