Permalink
Browse files

add basic eco templates support

This adds support for Eco (https://github.com/sstephenson/eco)
client-side templates, under the mimetype 'text/x-eco'.

Define SACY_TRANSFORMER_ECO to point to the eco executable.
  • Loading branch information...
1 parent ccefe85 commit e6adb1f1c77e7fdb8d0527847fa305fcbcd63ee7 @brainlock committed May 18, 2012
Showing with 39 additions and 2 deletions.
  1. +1 −0 NEWS
  2. +5 −0 README.markdown
  3. +23 −0 src/sacy/ext-translators.php
  4. +10 −2 src/sacy/sacy.php
View
1 NEWS
@@ -1,4 +1,5 @@
Version 0.4 (2012-??-??):
+ - Support for eco templates
- Also write statically precompressed files for use with MultiViews
in Apache or gzip_static in nginx
- Support for inline-content-tags
View
@@ -11,6 +11,7 @@ Sacy turns
<script type="text/javascript" src="/jslib/file1.js"></script>
<script type="text/coffeescript" src="/jslib/file2.coffee"></script>
<script type="text/javascript" src="/jslib/file3.js"></script>
+ <script type="text/x-eco" src="/jslib/sometemplate.eco"></script>
{/asset_compile}
into
@@ -527,6 +528,10 @@ define()'ing some constants pointing sacy to the path of the respecive tools:
requires a working ruby installation (1.8.7 or later) and you would install
it using `gem install sass`, giving you an executable at `/usr/bin/sass`
+- `SACY_TRANSFORMER_ECO` specifies the path to the eco compiler. You can
+ install it using `npm install -g eco`, which will likely put the eco
+ executable in `/usr/local/bin/eco`.
+
If you are not sure what you are doing, always install these utilities to
their global locations. If you install them as a user account, chances are
that the user the web server runs as will not be able to find them or if they
@@ -92,6 +92,25 @@ protected function getCommandLine($filename){
}
}
+class ProcessorEco extends ExternalProcessor{
+ protected function getType(){
+ return 'text/x-eco';
+ }
+
+ protected function getCommandLine($filename){
+ if (!is_executable(SACY_TRANSFORMER_ECO)){
+ throw new Exception('SACY_TRANSFORMER_ECO defined but not executable');
+ }
+ // Calling eco with the filename here. Using stdin wouldn't
+ // cut it, as eco uses the filename to figure out the name of
+ // the js function it outputs.
+ return sprintf('%s -p %s',
+ SACY_TRANSFORMER_ECO,
+ escapeshellarg($filename)
+ );
+ }
+}
+
class ProcessorSass extends ExternalProcessor{
protected function getType(){
@@ -140,6 +159,10 @@ protected function getCommandLine($filename){
ExternalProcessorRegistry::registerTransformer('text/coffeescript', 'sacy\ProcessorCoffee');
}
+if (defined('SACY_TRANSFORMER_ECO')){
+ ExternalProcessorRegistry::registerTransformer('text/x-eco', 'sacy\ProcessorEco');
+}
+
if (defined('SACY_TRANSFORMER_SASS')){
ExternalProcessorRegistry::registerTransformer('text/x-sass', 'sacy\ProcessorSass');
ExternalProcessorRegistry::registerTransformer('text/x-scss', 'sacy\ProcessorScss');
View
@@ -449,9 +449,15 @@ static public function willTransformType($type){
class JavaScriptRenderHandler extends ConfiguredRenderHandler{
static function supportedTransformations(){
+ $supported = array();
+
if (function_exists('CoffeeScript\compile') || ExternalProcessorRegistry::typeIsSupported('text/coffeescript'))
- return array('text/coffeescript');
- return array();
+ $supported[] = 'text/coffeescript';
+
+ if (ExternalProcessorRegistry::typeIsSupported('text/x-eco'))
+ $supported[] = 'text/x-eco';
+
+ return $supported;
}
static function willTransformType($type){
@@ -485,6 +491,8 @@ function getOutput($work_unit){
$js = ExternalProcessorRegistry::typeIsSupported('text/coffeescript') ?
ExternalProcessorRegistry::getTransformerForType('text/coffeescript')->transform($js, $source_file) :
\Coffeescript::build($js);
+ } else if ($work_unit['type'] == 'text/x-eco'){
+ $js = ExternalProcessorRegistry::getTransformerForType('text/x-eco')->transform($js, $source_file);
}
if ($debug){
return $js;

0 comments on commit e6adb1f

Please sign in to comment.