Skip to content
This repository was archived by the owner on Feb 13, 2020. It is now read-only.
This repository was archived by the owner on Feb 13, 2020. It is now read-only.

Several paths #22

@Vadorequest

Description

@Vadorequest

I tried to override your module to accept in the factory to load another config file than the default one. (BTW, you could have done better instead of repeating X time the same config load...)

<?php defined('SYSPATH') OR die('No direct script access.');

class Assets extends Kohana_Assets {

    /**
     * Contains the config object.
     * @var array
     */
    private static $config;

    public static function require_valid_type($type)
    {
        if ( ! in_array($type, array_keys(Assets::$config['load_paths'])))
        {
            throw new Kohana_Exception('Type :type must be one of [:types]', array(
                    ':type'  => $type,
                    ':types' => join(', ', array_keys(Assets::$config['load_paths'])))
            );
        }
        return TRUE;
    }

    /**
     * Determine if file was modified later then source
     *
     * @param   string  $file
     * @param   string  $source_modified_time
     * @return  bool
     */
    public static function is_modified_later($file, $source_modified_time)
    {
        return ( ! is_file($file) OR filemtime($file) < $source_modified_time);
    }

    /**
     * Set file path
     *
     * @param   string  $type
     * @param   string  $file
     * @return  string
     */
    public static function file_path($type, $file)
    {
        // Set file
        $file = substr($file, 0, strrpos($file, $type)).$type;

        return (isset(Assets::$config['docroot']) ? Assets::$config['docroot'] : '').Assets::$config['folder'].DIRECTORY_SEPARATOR.$type.DIRECTORY_SEPARATOR.$file;
    }

    /**
     * Set web path
     *
     * @param   string  $type
     * @param   string  $file
     * @return  string
     */
    public static function web_path($type, $file)
    {
        // Set file
        $file = substr($file, 0, strrpos($file, $type)).$type;

        return Assets::$config['folder'].'/'.$type.'/'.$file;
    }

    /**
     * Return a new Assets object
     *
     * @param   $name   string
     * @param   $config array|bool
     * @return  Assets
     */
    static public function factory($name, $config = false)
    {
        return new Assets($name, $config);
    }

    /**
     * Create the asset groups, set the file name and enable / disable process
     * and merge
     *
     * @param string $name
     */
    public function __construct($name = 'all', $config = null)
    {
        if($config){
            Assets::$config = $config;
        }else{
            Assets::$config = Kohana::$config->load('asset-merger');
        }

        foreach (array_keys(Assets::$config['load_paths']) as $type)
        {
            // Add asset groups
            $this->_groups[$type] = new Asset_Collection($type, $name);
        }

        // Set the merged file name
        $this->_name = $name;

        // Set process and merge
        $this->_process = $this->_merge = in_array(Kohana::$environment, (array) Assets::$config['merge']);
    }
}

But so far, it just doesn't work. THe problem is that the _destination_file and _destination_web in the _groups instance variable are wrong. Still using the old path.

I think that's because in the asset/collection.php the call to Assets::web_path calls actually your Assets.php class instead of mine. Or I don't understand the problem.

View:

echo Assets::factory('after', App::config('asset-merger-theme'))
            ->js("jquery/jquery-validationEngine.js")
            ->js("jquery/jquery-validationEngine-$lang.js")
            ->render();

A way to do that would be nice, because I use complex paths with theme.
And anyway, load different config file between different call would be useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions