Skip to content

Commit

Permalink
Merge pull request #2 from UberGroupLimited/master
Browse files Browse the repository at this point in the history
wqeqwewqwqeq
  • Loading branch information
strongwazz committed Jul 8, 2013
2 parents e5da080 + ca0e496 commit 4916b9a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 28 deletions.
32 changes: 15 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
The MIT License (MIT)
Copyright (c) 2010 Justin Hileman

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 25 additions & 5 deletions src/Mustache/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
class Mustache_Engine
{
const VERSION = '2.3.0';
const VERSION = '2.3.1';
const SPEC_VERSION = '1.1.2';

const PRAGMA_FILTERS = 'FILTERS';
Expand All @@ -43,6 +43,8 @@ class Mustache_Engine
private $logger;
private $strictCallables = false;

var $dataPoints = 0;

/**
* Mustache class constructor.
*
Expand Down Expand Up @@ -152,22 +154,36 @@ public function __construct(array $options = array())
}
}


public function add_data_point($inc=1)
{
$this->dataPoints += $inc;

return $this;
}


public function count_data_points()
{
return $this->dataPoints;
}

/**
* Shortcut 'render' invocation.
*
* Equivalent to calling `$mustache->loadTemplate($template)->render($data);`
* Equivalent to calling `$mustache->loadTemplate($template)->render($context);`
*
* @see Mustache_Engine::loadTemplate
* @see Mustache_Template::render
*
* @param string $template
* @param mixed $data
* @param mixed $context (default: array())
*
* @return string Rendered template
*/
public function render($template, $data)
public function render($template, $context = array())
{
return $this->loadTemplate($template)->render($data);
return $this->loadTemplate($template)->render($context);
}

/**
Expand Down Expand Up @@ -504,6 +520,10 @@ public function loadTemplate($name)
*/
public function loadPartial($name)
{

//Warren's been hacking at it agian.
#$this->add_data_point(1);

try {
if (isset($this->partialsLoader)) {
$loader = $this->partialsLoader;
Expand Down
30 changes: 30 additions & 0 deletions src/Mustache/Loader/FilesystemImageLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php


class Mustache_Loader_FilesystemImageLoader extends Mustache_Loader_FilesystemLoader implements Mustache_Loader
{

var $map = array(
'png' => 'png',
'jpg' =>'jpeg',
);

function __construct($baseDir, array $options = array())
{
parent::__construct($baseDir, ($options));
}


public function load($name)
{
$type = substr($name, (strrpos($name, '-', -4)+1));

if(!isset($this->map[$type]))
throw new Mustache_Exception_InvalidArgumentException('Image type '.$type.' does not appear to be valid');

$x = parent::load($name);

return 'data:image/'.$this->map[$type].';base64,'.base64_encode($x);
}

}
3 changes: 2 additions & 1 deletion src/Mustache/Loader/FilesystemLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ protected function loadFile($name)
*
* @return string Template file name
*/
protected function getFileName($name)
//protected - whoops..finger slipped..
function getFileName($name)
{
$fileName = $this->baseDir . '/' . $name;
if (substr($fileName, 0 - strlen($this->extension)) !== $this->extension) {
Expand Down
4 changes: 4 additions & 0 deletions src/Mustache/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ protected function prepareContextStack($context = null)
*/
protected function resolveValue($value, Mustache_Context $context, $indent = '')
{

//We need to log the fact we're making a datapoint change;
$this->mustache->add_data_point(1);

if (($this->strictCallables ? is_object($value) : !is_string($value)) && is_callable($value)) {
return $this->mustache
->loadLambda((string) call_user_func($value))
Expand Down
12 changes: 7 additions & 5 deletions src/Mustache/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,21 @@ public function scan($text, $delimiters = null)
$this->flushBuffer();
$this->state = self::IN_TAG_TYPE;
} else {
if ($text[$i] == "\n") {
$char = substr($text, $i, 1);
if ($char == "\n") {
$this->filterLine();
} else {
$this->buffer .= $text[$i];
$this->buffer .= $char;
}
}
break;

case self::IN_TAG_TYPE:

$i += strlen($this->otag) - 1;
if (isset(self::$tagTypes[$text[$i + 1]])) {
$tag = $text[$i + 1];
$char = substr($text, $i + 1, 1);
if (isset(self::$tagTypes[$char])) {
$tag = $char;
$this->tagType = $tag;
} else {
$tag = null;
Expand Down Expand Up @@ -166,7 +168,7 @@ public function scan($text, $delimiters = null)
}
}
} else {
$this->buffer .= $text[$i];
$this->buffer .= substr($text, $i, 1);
}
break;
}
Expand Down

0 comments on commit 4916b9a

Please sign in to comment.