Sha256: c535c015f69beec07a98dd660c19c0013e4a7b3447918c8dc0d757a4b93c4db8

Contents?: true

Size: 1006 Bytes

Versions: 10

Compression:

Stored size: 1006 Bytes

Contents

<?php

namespace MtHaml\Filter;

use MtHaml\NodeVisitor\RendererAbstract as Renderer;
use MtHaml\Node\Filter;
use CoffeeScript\Compiler;

class CoffeeScript extends AbstractFilter
{
    private $coffeescript;
    private $options;

    public function __construct(Compiler $coffeescript, array $options = array())
    {
        $this->coffeescript = $coffeescript;
        $this->options = $options;
    }

    public function optimize(Renderer $renderer, Filter $node, $options)
    {
        $renderer->write($this->filter($this->getContent($node), array(), $options));
    }

    public function filter($content, array $context, $options)
    {
        if (isset($options['cdata']) && $options['cdata'] === true) {
            return "<script type=\"text/javascript\">\n//<![CDATA[\n".$this->coffeescript->compile($content, $this->options)."\n//]]\n</script>";
        }

        return "<script type=\"text/javascript\">\n".$this->coffeescript->compile($content, $this->options)."\n</script>";
    }
}

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
guard-mthaml-0.4.0 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.3.1 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.3.0 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.2.5 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.2.4 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.2.3 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.2.2 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.2.1 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.2.0 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php
guard-mthaml-0.1.0 vendor/mthaml/mthaml/lib/MtHaml/Filter/CoffeeScript.php