<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WEBPIRATEN &#187; template</title>
	<atom:link href="http://webpiraten.de/index.php/tag/template/feed/" rel="self" type="application/rss+xml" />
	<link>http://webpiraten.de</link>
	<description>Techblog / Photographie</description>
	<lastBuildDate>Fri, 18 May 2012 10:03:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>der Kohana Script Collector Helper</title>
		<link>http://webpiraten.de/index.php/frameworks/der-kohana-script-collector-helper/</link>
		<comments>http://webpiraten.de/index.php/frameworks/der-kohana-script-collector-helper/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 19:26:49 +0000</pubDate>
		<dc:creator>webpirat</dc:creator>
				<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Kohana]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[collector]]></category>
		<category><![CDATA[controller]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[helper]]></category>
		<category><![CDATA[kohana]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[stylesheet]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://webpiraten.de/?p=89</guid>
		<description><![CDATA[Um modular und agil in Kohana zu entwickeln, wurde ein Skript Kollektor notwendig, der aus allen Controllern (Template- oder Standard-Controllern) Skripte (CSS, Javascript) sammeln kann. Diese Scripte werden dann auf den jeweiligen Mastertemplates wieder an den richtigen Stellen eingebunden. Dazu &#8230; <a href="http://webpiraten.de/index.php/frameworks/der-kohana-script-collector-helper/">weiterlesen <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Um modular und agil in Kohana zu entwickeln, wurde ein Skript Kollektor notwendig, der aus allen Controllern (Template- oder Standard-Controllern) Skripte (CSS, Javascript) sammeln kann.</p>
<p>Diese Scripte werden dann auf den jeweiligen Mastertemplates wieder an den richtigen Stellen eingebunden.<br />
Dazu habe ich einen neuen Helper unter application/helpers/collector.php eingerichtet.</p>
<pre class="brush: php; title: ; notranslate">

class Collector_Core
{
    /**
     * Arrays containing URL's to scripts/styles (fill with standards)
     * @var string
     */
    static protected $scripts       = array();
    static protected $styles        = array();

    /**
     * Adds a url to store
     * @param string $file the local path to file
     * @return void
     */
    static public function addJs($file)
    {
        self::$scripts[] = $file;
    }

    /**
     * Adds a url to store
     * @param string $file the local path to file
     * @return void
     */
    static public function addCss($file)
    {
        self::$styles[] = $file;
    }

    /**
     * Generates/renders collectors items
     * @param boolean      $print whether to echo the output or just return rendered string
     * @return string      the rendered output
     */
    static public function renderJs($print = false)
    {
        $scripts    = array_unique(self::$scripts);
        $output     = html::script($scripts);
        if ($print)
        {
            echo $output;
        }
        else
        {
            return $output;
        }
    }

    /**
     * Generates/renders collectors items
     * @param boolean      $print whether to echo the output or just return rendered string
     * @param string|array $media type for this style (all, screen, print, media)
     * @return string      the rendered output
     */
    static public function renderCss($print = false, $media = 'all')
    {
        $styles = array_unique(self::$styles);
        $output = html::stylesheet($styles, $media);
        if ($print)
        {
            echo $output;
        }
        else
        {
            return $output;
        }
    }
} // end of Collector_Core
</pre>
<p>Dieser Helper kann nun aus allen Controllern heraus befüllt werden.</p>
<pre class="brush: php; title: ; notranslate">

class Welcome_Controller extends Template_Controller
{
    /**
     * set master template
     */
    public $template = 'master_default.tpl';

    /**
     * default constructor
     * @param void
     * @return void
     */
    public function __construct()
    {
        // load parent constructor
        parent::__construct();

        // collect scripts and styles
        collector::addCss('/css/fancybox');
        collector::addJs('/js/jquery.1.3.2');
        collector::addJs('/js/jquery.fancybox');
    }
    /** more code here */
} // end of Welcome_Controller
</pre>
<p>Nachdem nun alle relevanten Skripte eingesammelt wurden, kann man diese auf dem Template wieder ausgeben lassen.</p>
<pre class="brush: xml; title: ; notranslate">

&lt;?php collector::renderCss(true, 'all'); ?&gt;

&lt;!-- html code here --&gt;

&lt;?php collector::renderJs(true); ?&gt;
</pre>
<p>Der Kollektor sorgt dafür das keine doppelten Skripte geladen werden.</p>
]]></content:encoded>
			<wfw:commentRss>http://webpiraten.de/index.php/frameworks/der-kohana-script-collector-helper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

