Skip to content

Commit

Permalink
merge pull request welaika#72 from emzo
Browse files Browse the repository at this point in the history
  • Loading branch information
endorama committed Jun 19, 2012
1 parent 37b5010 commit 61c8ef0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
21 changes: 20 additions & 1 deletion wordless/helpers/asset_tag_helper.php
Expand Up @@ -8,6 +8,23 @@
*/
class AssetTagHelper {

/**
* Appends version information to asset source.
*
* @param string $source
* The path to the asset source.
* @return @e string
* The path to the asset source with version information appended to the query string.
*
* @ingroup helperfunc
*/
function asset_version($source) {
$version = Wordless::preference('assets.version', NULL);
if (isset($version))
$source .= sprintf("?ver=%s", $version);
return $source;
}

/**
* Builds a valid \<audio /\> HTML tag.
*
Expand Down Expand Up @@ -187,7 +204,7 @@ public function get_feed_url($model, $type = "rss") {
*/
public function image_tag($source, $attributes = NULL) {
if (!preg_match("/^(https?|\/)/", $source)) {
$source = image_url($source);
$source = asset_version(image_url($source));
}

$info = pathinfo($source);
Expand Down Expand Up @@ -270,6 +287,7 @@ function stylesheet_link_tag() {
if (!preg_match("/^https?:\/\//", $source)) {
$source = stylesheet_url($source);
if (!preg_match("/\.css$/", $source)) $source .= ".css";
$source = asset_version($source);
}
$options = array(
"href" => $source,
Expand Down Expand Up @@ -315,6 +333,7 @@ function javascript_include_tag() {
if (!preg_match("/^https?:\/\//", $source)) {
$source = javascript_url($source);
if (!preg_match("/\.js$/", $source)) $source .= ".js";
$source = asset_version($source);
}
$options = array(
"src" => $source,
Expand Down
24 changes: 21 additions & 3 deletions wordless/helpers/theme_helper.php
Expand Up @@ -17,8 +17,7 @@ class ThemeHelper {
* @ingroup helperfunc
*/
function get_theme_name() {
$temp = explode("wp-content/themes/", get_bloginfo("template_url"));
return $temp[1]; // The second value will be the theme name
return get_template();
}

/**
Expand All @@ -32,7 +31,26 @@ function get_theme_name() {
* @ingroup helperfunc
*/
function get_theme_path() {
return get_theme_root() . '/' . get_theme_name();
return get_template_directory();
}

/**
* Returns the version of the the current theme.
*
* @return string
* The version of the current theme.
*
* @ingroup helperfunc
*/
function get_theme_version() {
if (class_exists('WP_Theme')) {
$theme = new WP_Theme(get_theme_name(), get_theme_root());
return $theme->get('Version');
}
else {
$theme_data = get_theme_data(get_template_directory() . '/style.css');
return $theme_data['Version'];
}
}
}

Expand Down
Expand Up @@ -6,6 +6,7 @@

Wordless::set_preference("assets.preprocessors", array("SprocketsPreprocessor", "CompassPreprocessor"));
// Wordless::set_preference("assets.cache_enabled", true);
// Wordless::set_preference("assets.version", get_theme_version());

// Wordless::set_preference("css.compass_path", "/usr/bin/compass");
// Wordless::set_preference("css.output_style", "compressed");
Expand Down

0 comments on commit 61c8ef0

Please sign in to comment.