From a54d1c23d26a49b344208f4badefeb875da5627d Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 25 Jan 2012 11:28:16 +0100 Subject: [PATCH] Add mustache loader --- lib/Alchemy/Phrasea/Application/Prod.php | 1 + .../Controller/Prod/MustacheLoader.php | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php diff --git a/lib/Alchemy/Phrasea/Application/Prod.php b/lib/Alchemy/Phrasea/Application/Prod.php index a0cd775f00..ce93329c2d 100644 --- a/lib/Alchemy/Phrasea/Application/Prod.php +++ b/lib/Alchemy/Phrasea/Application/Prod.php @@ -43,6 +43,7 @@ return call_user_func(function() $app->mount('/story', new Controller\Story()); $app->mount('/WorkZone', new Controller\WorkZone()); $app->mount('/lists', new Controller\UsrLists()); + $app->mount('/MustacheLoader', new Controller\MustacheLoader()); $app->mount('/records/edit', new Controller\Edit()); $app->mount('/records/movecollection', new Controller\MoveCollection()); $app->mount('/bridge/', new Controller\Bridge()); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php b/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php new file mode 100644 index 0000000000..78c33dae7e --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Prod/MustacheLoader.php @@ -0,0 +1,54 @@ +get('/', function(Application $app, Request $request) + { + $template_name = $request->get('template'); + + if (!preg_match('/[a-zA-Z0-9-_]+/', $template_name)) + { + throw new \Exception_BadRequest('Wrong template name : ' . $template_name); + } + + $template_path = realpath(__DIR__ . '/../../../../../templates/web/Mustache/Prod/' . $template_name . '.Mustache.html'); + + if (!file_exists($template_path)) + { + throw new \Exception_NotFound('Template does not exists : ' . $template_path); + } + + return new \Symfony\Component\HttpFoundation\Response(include $template_path); + }); + + return $controllers; + } + +}