Skip to content

Instantly share code, notes, and snippets.

@krypton
Created October 18, 2012 10:13

Revisions

  1. Tiago Dias revised this gist Oct 18, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -33,12 +33,13 @@ function javascript_include_tag($assets, $options = array())

    function stylesheet_link_tag($assets, $options = array())
    {
    $default = array('rel' => 'stylesheet', 'type' => 'text/css');
    $default = array('rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'all');
    return assets_include_tag($assets, '<link href="%s"%s />', array_merge($default, $options));
    }

    // Examples of usage:
    // <?php echo stylesheet_link_tag(array('stylesheets/all.css')) ?>
    // <?php echo javascript_include_tag(array('javascripts/all.js')) ?>
    // <?php echo javascript_include_tag(array('javascripts/search.js'), array('charset' => 'UTF-8')) ?>

    ?>
  2. Tiago Dias revised this gist Oct 18, 2012. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -2,32 +2,39 @@

    define('_ROOT', dirname(realpath(__FILE__)));

    function assets_include_tag($assets, $tmpl)
    function assets_include_tag($assets, $tmpl, $options)
    {
    if (empty($assets)) {
    return false;
    }

    $allAssets = '';
    $assetOptions = '';
    $assetOutput = array();

    foreach ($options as $key => $value) {
    $assetOptions .= " {$key}=\"{$value}\"";
    }

    foreach ($assets as $asset) {
    $filepath = _ROOT . "/{$asset}";
    if (is_file($filepath)) {
    $allAssets.= sprintf($tmpl, "{$asset}?v=" . filemtime($filepath)) . PHP_EOL;
    array_push($assetOutput, sprintf($tmpl, "{$asset}?v=" . filemtime($filepath), $assetOptions));
    }
    }

    return $allAssets;
    return implode(PHP_EOL, $assetOutput) . PHP_EOL;
    }

    function javascript_include_tag($assets)
    function javascript_include_tag($assets, $options = array())
    {
    return assets_include_tag($assets, '<script src="%s"></script>');
    $default = array('type' => 'text/javascript');
    return assets_include_tag($assets, '<script src="%s"%s></script>', array_merge($default, $options));
    }

    function stylesheet_link_tag($assets)
    function stylesheet_link_tag($assets, $options = array())
    {
    return assets_include_tag($assets, '<link rel="stylesheet" href="%s" type="text/css" />');
    $default = array('rel' => 'stylesheet', 'type' => 'text/css');
    return assets_include_tag($assets, '<link href="%s"%s />', array_merge($default, $options));
    }

    // Examples of usage:
  3. Tiago Dias revised this gist Oct 18, 2012. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -30,4 +30,8 @@ function stylesheet_link_tag($assets)
    return assets_include_tag($assets, '<link rel="stylesheet" href="%s" type="text/css" />');
    }

    // Examples of usage:
    // <?php echo stylesheet_link_tag(array('stylesheets/all.css')) ?>
    // <?php echo javascript_include_tag(array('javascripts/all.js')) ?>

    ?>
  4. Tiago Dias created this gist Oct 18, 2012.
    33 changes: 33 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    <?php

    define('_ROOT', dirname(realpath(__FILE__)));

    function assets_include_tag($assets, $tmpl)
    {
    if (empty($assets)) {
    return false;
    }

    $allAssets = '';

    foreach ($assets as $asset) {
    $filepath = _ROOT . "/{$asset}";
    if (is_file($filepath)) {
    $allAssets.= sprintf($tmpl, "{$asset}?v=" . filemtime($filepath)) . PHP_EOL;
    }
    }

    return $allAssets;
    }

    function javascript_include_tag($assets)
    {
    return assets_include_tag($assets, '<script src="%s"></script>');
    }

    function stylesheet_link_tag($assets)
    {
    return assets_include_tag($assets, '<link rel="stylesheet" href="%s" type="text/css" />');
    }

    ?>