mirror of
https://github.com/there4/markdown-resume.git
synced 2024-12-03 08:59:35 -05:00
Initial commit of Markdown Resume
This includes several vendor libraries: Assetic, LessPHP, Mustache, SmartyPants, Markdown
This commit is contained in:
159
vendor/Assetic/Factory/Loader/BasePhpFormulaLoader.php
vendored
Executable file
159
vendor/Assetic/Factory/Loader/BasePhpFormulaLoader.php
vendored
Executable file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
use Assetic\Factory\AssetFactory;
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* Loads asset formulae from PHP files.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
abstract class BasePhpFormulaLoader implements FormulaLoaderInterface
|
||||
{
|
||||
protected $factory;
|
||||
protected $prototypes;
|
||||
|
||||
public function __construct(AssetFactory $factory)
|
||||
{
|
||||
$this->factory = $factory;
|
||||
$this->prototypes = array();
|
||||
|
||||
foreach ($this->registerPrototypes() as $prototype => $options) {
|
||||
$this->addPrototype($prototype, $options);
|
||||
}
|
||||
}
|
||||
|
||||
public function addPrototype($prototype, array $options = array())
|
||||
{
|
||||
$tokens = token_get_all('<?php '.$prototype);
|
||||
array_shift($tokens);
|
||||
|
||||
$this->prototypes[$prototype] = array($tokens, $options);
|
||||
}
|
||||
|
||||
public function load(ResourceInterface $resource)
|
||||
{
|
||||
if (!$nbProtos = count($this->prototypes)) {
|
||||
throw new \LogicException('There are no prototypes registered.');
|
||||
}
|
||||
|
||||
$buffers = array_fill(0, $nbProtos, '');
|
||||
$bufferLevels = array_fill(0, $nbProtos, 0);
|
||||
$buffersInWildcard = array();
|
||||
|
||||
$tokens = token_get_all($resource->getContent());
|
||||
$calls = array();
|
||||
|
||||
while ($token = array_shift($tokens)) {
|
||||
$current = self::tokenToString($token);
|
||||
// loop through each prototype (by reference)
|
||||
foreach (array_keys($this->prototypes) as $i) {
|
||||
$prototype =& $this->prototypes[$i][0];
|
||||
$options = $this->prototypes[$i][1];
|
||||
$buffer =& $buffers[$i];
|
||||
$level =& $bufferLevels[$i];
|
||||
|
||||
if (isset($buffersInWildcard[$i])) {
|
||||
switch ($current) {
|
||||
case '(': ++$level; break;
|
||||
case ')': --$level; break;
|
||||
}
|
||||
|
||||
$buffer .= $current;
|
||||
|
||||
if (!$level) {
|
||||
$calls[] = array($buffer.';', $options);
|
||||
$buffer = '';
|
||||
unset($buffersInWildcard[$i]);
|
||||
}
|
||||
} elseif ($current == self::tokenToString(current($prototype))) {
|
||||
$buffer .= $current;
|
||||
if ('*' == self::tokenToString(next($prototype))) {
|
||||
$buffersInWildcard[$i] = true;
|
||||
++$level;
|
||||
}
|
||||
} else {
|
||||
reset($prototype);
|
||||
unset($buffersInWildcard[$i]);
|
||||
$buffer = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formulae = array();
|
||||
foreach ($calls as $call) {
|
||||
$formulae += call_user_func_array(array($this, 'processCall'), $call);
|
||||
}
|
||||
|
||||
return $formulae;
|
||||
}
|
||||
|
||||
private function processCall($call, array $protoOptions = array())
|
||||
{
|
||||
$tmp = tempnam(sys_get_temp_dir(), 'assetic');
|
||||
file_put_contents($tmp, implode("\n", array(
|
||||
'<?php',
|
||||
$this->registerSetupCode(),
|
||||
$call,
|
||||
'echo serialize($_call);',
|
||||
)));
|
||||
$args = unserialize(shell_exec('php '.escapeshellarg($tmp)));
|
||||
unlink($tmp);
|
||||
|
||||
$inputs = isset($args[0]) ? self::argumentToArray($args[0]) : array();
|
||||
$filters = isset($args[1]) ? self::argumentToArray($args[1]) : array();
|
||||
$options = isset($args[2]) ? $args[2] : array();
|
||||
|
||||
if (!isset($options['debug'])) {
|
||||
$options['debug'] = $this->factory->isDebug();
|
||||
}
|
||||
|
||||
if (!is_array($options)) {
|
||||
throw new \RuntimeException('The third argument must be omitted, null or an array.');
|
||||
}
|
||||
|
||||
// apply the prototype options
|
||||
$options += $protoOptions;
|
||||
|
||||
if (!isset($options['name'])) {
|
||||
$options['name'] = $this->factory->generateAssetName($inputs, $filters, $options);
|
||||
}
|
||||
|
||||
return array($options['name'] => array($inputs, $filters, $options));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of prototypical calls and options.
|
||||
*
|
||||
* @return array Prototypes and options
|
||||
*/
|
||||
abstract protected function registerPrototypes();
|
||||
|
||||
/**
|
||||
* Returns setup code for the reflection scriptlet.
|
||||
*
|
||||
* @return string Some PHP setup code
|
||||
*/
|
||||
abstract protected function registerSetupCode();
|
||||
|
||||
static protected function tokenToString($token)
|
||||
{
|
||||
return is_array($token) ? $token[1] : $token;
|
||||
}
|
||||
|
||||
static protected function argumentToArray($argument)
|
||||
{
|
||||
return is_array($argument) ? $argument : array_filter(array_map('trim', explode(',', $argument)));
|
||||
}
|
||||
}
|
||||
68
vendor/Assetic/Factory/Loader/CachedFormulaLoader.php
vendored
Executable file
68
vendor/Assetic/Factory/Loader/CachedFormulaLoader.php
vendored
Executable file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
use Assetic\Cache\ConfigCache;
|
||||
use Assetic\Factory\Resource\IteratorResourceInterface;
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* Adds a caching layer to a loader.
|
||||
*
|
||||
* A cached formula loader is a composition of a formula loader and a cache.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class CachedFormulaLoader implements FormulaLoaderInterface
|
||||
{
|
||||
private $loader;
|
||||
private $configCache;
|
||||
private $debug;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* When the loader is in debug mode it will ensure the cached formulae
|
||||
* are fresh before returning them.
|
||||
*
|
||||
* @param FormulaLoaderInterface $loader A formula loader
|
||||
* @param ConfigCache $configCache A config cache
|
||||
* @param Boolean $debug The debug mode
|
||||
*/
|
||||
public function __construct(FormulaLoaderInterface $loader, ConfigCache $configCache, $debug = false)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->configCache = $configCache;
|
||||
$this->debug = $debug;
|
||||
}
|
||||
|
||||
public function load(ResourceInterface $resources)
|
||||
{
|
||||
if (!$resources instanceof IteratorResourceInterface) {
|
||||
$resources = array($resources);
|
||||
}
|
||||
|
||||
$formulae = array();
|
||||
|
||||
foreach ($resources as $resource) {
|
||||
$id = (string) $resource;
|
||||
if (!$this->configCache->has($id) || ($this->debug && !$resource->isFresh($this->configCache->getTimestamp($id)))) {
|
||||
$formulae += $this->loader->load($resource);
|
||||
$this->configCache->set($id, $formulae);
|
||||
} else {
|
||||
$formulae += $this->configCache->get($id);
|
||||
}
|
||||
}
|
||||
|
||||
return $formulae;
|
||||
}
|
||||
}
|
||||
34
vendor/Assetic/Factory/Loader/FormulaLoaderInterface.php
vendored
Executable file
34
vendor/Assetic/Factory/Loader/FormulaLoaderInterface.php
vendored
Executable file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
use Assetic\Factory\Resource\ResourceInterface;
|
||||
|
||||
/**
|
||||
* Loads formulae.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
interface FormulaLoaderInterface
|
||||
{
|
||||
/**
|
||||
* Loads formulae from a resource.
|
||||
*
|
||||
* Formulae should be loaded the same regardless of the current debug
|
||||
* mode. Debug considerations should happen downstream.
|
||||
*
|
||||
* @param ResourceInterface $resource A resource
|
||||
*
|
||||
* @return array An array of formulae
|
||||
*/
|
||||
function load(ResourceInterface $resource);
|
||||
}
|
||||
53
vendor/Assetic/Factory/Loader/FunctionCallsFormulaLoader.php
vendored
Executable file
53
vendor/Assetic/Factory/Loader/FunctionCallsFormulaLoader.php
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Assetic package, an OpenSky project.
|
||||
*
|
||||
* (c) 2010-2011 OpenSky Project Inc
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Assetic\Factory\Loader;
|
||||
|
||||
/**
|
||||
* Loads asset formulae from PHP files.
|
||||
*
|
||||
* @author Kris Wallsmith <kris.wallsmith@gmail.com>
|
||||
*/
|
||||
class FunctionCallsFormulaLoader extends BasePhpFormulaLoader
|
||||
{
|
||||
protected function registerPrototypes()
|
||||
{
|
||||
return array(
|
||||
'assetic_javascripts(*)' => array('output' => 'js/*.js'),
|
||||
'assetic_stylesheets(*)' => array('output' => 'css/*.css'),
|
||||
'assetic_image(*)' => array('output' => 'images/*'),
|
||||
);
|
||||
}
|
||||
|
||||
protected function registerSetupCode()
|
||||
{
|
||||
return <<<'EOF'
|
||||
function assetic_javascripts()
|
||||
{
|
||||
global $_call;
|
||||
$_call = func_get_args();
|
||||
}
|
||||
|
||||
function assetic_stylesheets()
|
||||
{
|
||||
global $_call;
|
||||
$_call = func_get_args();
|
||||
}
|
||||
|
||||
function assetic_image()
|
||||
{
|
||||
global $_call;
|
||||
$_call = func_get_args();
|
||||
}
|
||||
|
||||
EOF;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user