Skip to content

Commit 56d295a

Browse files
author
Josh Lockhart
committed
Import custom views from primary repo
1 parent d00f670 commit 56d295a

File tree

11 files changed

+961
-0
lines changed

11 files changed

+961
-0
lines changed

Views/BlitzView.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Slim - a micro PHP 5 framework
4+
*
5+
* @author Josh Lockhart
6+
* @link http://www.slimframework.com
7+
* @copyright 2011 Josh Lockhart
8+
*
9+
* MIT LICENSE
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining
12+
* a copy of this software and associated documentation files (the
13+
* "Software"), to deal in the Software without restriction, including
14+
* without limitation the rights to use, copy, modify, merge, publish,
15+
* distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to
17+
* the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be
20+
* included in all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
*/
30+
31+
/**
32+
* BlitzView
33+
*
34+
* The BlitzView provides native support for the Blitz templating system
35+
* for PHP. Blitz is written as C and compiled to a PHP extension. Which means
36+
* it is FAST. You can learn more about Blitz at:
37+
*
38+
* <http://alexeyrybak.com/blitz/blitz_en.html>
39+
*
40+
* The xBlitz extended blitz class provides better block handling
41+
* (load assoc arrays correctly, one level)
42+
*
43+
* @author Tobias O. <https://github.com/tobsn>
44+
*/
45+
class xBlitz extends Blitz{function xblock($k,$a){foreach($a as $v){$this->block('/'.$k,$v,true);}}}
46+
class BlitzView extends Slim_View {
47+
48+
private $blitzEnvironment = null;
49+
50+
public function render( $template ) {
51+
$env = $this->getEnvironment( $template );
52+
return $env->parse( $this->getData() );
53+
}
54+
55+
private function getEnvironment( $template ) {
56+
if ( !$this->blitzEnvironment ) {
57+
ini_set( 'blitz.path', $this->getTemplatesDirectory() . '/' );
58+
$this->blitzEnvironment = new xBlitz( $template );
59+
}
60+
return $this->blitzEnvironment;
61+
}
62+
63+
}
64+
65+
?>

Views/DwooView.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Slim - a micro PHP 5 framework
4+
*
5+
* @author Josh Lockhart
6+
* @link http://www.slimframework.com
7+
* @copyright 2011 Josh Lockhart
8+
*
9+
* MIT LICENSE
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining
12+
* a copy of this software and associated documentation files (the
13+
* "Software"), to deal in the Software without restriction, including
14+
* without limitation the rights to use, copy, modify, merge, publish,
15+
* distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to
17+
* the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be
20+
* included in all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
*/
30+
31+
/**
32+
* DwooView
33+
*
34+
* The DwooView is a Custom View class that renders templates using the
35+
* Dwoo template language (http://dwoo.org/).
36+
*
37+
* There are two fields that you, the developer, will need to change:
38+
* - dwooDirectory
39+
* - dwooTemplatesDirectory
40+
*
41+
* @package Slim
42+
* @author Matthew Callis <http://superfamicom.org/>
43+
*/
44+
class DwooView extends Slim_View {
45+
46+
/**
47+
* @var string The path to the directory containing the Dwoo folder without trailing slash.
48+
*/
49+
public static $dwooDirectory = null;
50+
51+
/**
52+
* @var persistent instance of the Smarty object
53+
*/
54+
private static $dwooInstance = null;
55+
56+
/**
57+
* @var string The path to the templates folder WITH the trailing slash
58+
*/
59+
public static $dwooTemplatesDirectory = 'templates';
60+
61+
/**
62+
* Renders a template using Dwoo.php.
63+
*
64+
* @see View::render()
65+
* @param string $template The template name specified in Slim::render()
66+
* @return string
67+
*/
68+
public function render( $template ) {
69+
$dwoo = $this->getInstance();
70+
return $dwoo->get(self::$dwooTemplatesDirectory.$template, $this->data);
71+
}
72+
73+
/**
74+
* Creates new Dwoo instance if it doesn't already exist, and returns it.
75+
*
76+
* @throws RuntimeException If Dwoo lib directory does not exist.
77+
* @return DwooInstance
78+
*/
79+
private function getInstance() {
80+
if ( !self::$dwooInstance ) {
81+
if ( !is_dir(self::$dwooDirectory) ) {
82+
throw new RuntimeException('Cannot set the Dwoo lib directory : ' . self::$dwooDirectory . '. Directory does not exist.');
83+
}
84+
require_once self::$dwooDirectory . '/dwooAutoload.php';
85+
self::$dwooInstance = new Dwoo();
86+
}
87+
return self::$dwooInstance;
88+
}
89+
}
90+
91+
?>

Views/HaangaView.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Slim - a micro PHP 5 framework
4+
*
5+
* @author Josh Lockhart
6+
* @link http://www.slimframework.com
7+
* @copyright 2011 Josh Lockhart
8+
*
9+
* MIT LICENSE
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining
12+
* a copy of this software and associated documentation files (the
13+
* "Software"), to deal in the Software without restriction, including
14+
* without limitation the rights to use, copy, modify, merge, publish,
15+
* distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to
17+
* the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be
20+
* included in all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
*/
30+
31+
/**
32+
* HaangaView
33+
*
34+
* The HaangaView is a custom View class that renders templates using the Haanga
35+
* template language (http://haanga.org/).
36+
*
37+
* Currently, to use HaangaView, developer must instantiate this class and pass these params:
38+
* - path to Haanga directory which contain `lib`
39+
* - path to templates directory
40+
* - path to compiled templates directory
41+
*
42+
* Example:
43+
* {{{
44+
* require_once 'views/HaangaView.php';
45+
* Slim::init(array(
46+
* 'view' => new HaangaView('/path/to/Haanga/dir', '/path/to/templates/dir', '/path/to/compiled/dir')
47+
* ));
48+
* }}}
49+
*
50+
* @package Slim
51+
* @author Isman Firmansyah
52+
*/
53+
class HaangaView extends Slim_View {
54+
55+
/**
56+
* Configure Haanga environment
57+
*/
58+
public function __construct( $haangaDir, $templatesDir, $compiledDir ) {
59+
require_once $haangaDir . '/lib/Haanga.php';
60+
Haanga::configure(array(
61+
'template_dir' => $templatesDir,
62+
'cache_dir' => $compiledDir
63+
));
64+
}
65+
66+
/**
67+
* Render Haanga Template
68+
*
69+
* This method will output the rendered template content
70+
*
71+
* @param string $template The path to the Haanga template, relative to the Haanga templates directory.
72+
* @return string|NULL
73+
*/
74+
public function render( $template ) {
75+
return Haanga::load($template, $this->data);
76+
}
77+
}
78+
?>

Views/HamlView.php

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
/**
3+
* Slim - a micro PHP 5 framework
4+
*
5+
* @author Josh Lockhart
6+
* @link http://www.slimframework.com
7+
* @copyright 2011 Josh Lockhart
8+
*
9+
* MIT LICENSE
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining
12+
* a copy of this software and associated documentation files (the
13+
* "Software"), to deal in the Software without restriction, including
14+
* without limitation the rights to use, copy, modify, merge, publish,
15+
* distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to
17+
* the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be
20+
* included in all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
*/
30+
31+
/**
32+
* HamlView
33+
*
34+
* The HamlView is a Custom View class that renders templates using the
35+
* HAML template language (http://haml-lang.com/) through the use of
36+
* HamlPHP (https://github.com/sniemela/HamlPHP).
37+
*
38+
* There are three field that you, the developer, will need to change:
39+
* - hamlDirectory
40+
* - hamlTemplatesDirectory
41+
* - hamlCacheDirectory
42+
*
43+
* @package Slim
44+
* @author Matthew Callis <http://superfamicom.org/>
45+
*/
46+
47+
class HamlView extends Slim_View {
48+
49+
/**
50+
* @var string The path to the directory containing the "HamlPHP" folder without trailing slash.
51+
*/
52+
public static $hamlDirectory = null;
53+
54+
/**
55+
* @var string The path to the templates folder WITH the trailing slash
56+
*/
57+
public static $hamlTemplatesDirectory = 'templates/';
58+
59+
/**
60+
* @var string The path to the templates folder WITH the trailing slash
61+
*/
62+
public static $hamlCacheDirectory = null;
63+
64+
65+
/**
66+
* Renders a template using Haml.php.
67+
*
68+
* @see View::render()
69+
* @throws RuntimeException If Haml lib directory does not exist.
70+
* @param string $template The template name specified in Slim::render()
71+
* @return string
72+
*/
73+
public function render( $template ) {
74+
if ( !is_dir(self::$hamlDirectory) ) {
75+
throw new RuntimeException('Cannot set the HamlPHP lib directory : ' . self::$hamlDirectory . '. Directory does not exist.');
76+
}
77+
78+
require_once self::$hamlDirectory . '/HamlPHP/HamlPHP.php';
79+
require_once self::$hamlDirectory . '/HamlPHP/Storage/FileStorage.php';
80+
81+
$parser = new HamlPHP(new FileStorage(self::$hamlCacheDirectory));
82+
return $parser->parseFile(self::$hamlTemplatesDirectory.$template, $this->data);
83+
}
84+
}
85+
86+
?>

Views/MustacheView.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Slim - a micro PHP 5 framework
4+
*
5+
* @author Josh Lockhart
6+
* @link http://www.slimframework.com
7+
* @copyright 2011 Josh Lockhart
8+
*
9+
* MIT LICENSE
10+
*
11+
* Permission is hereby granted, free of charge, to any person obtaining
12+
* a copy of this software and associated documentation files (the
13+
* "Software"), to deal in the Software without restriction, including
14+
* without limitation the rights to use, copy, modify, merge, publish,
15+
* distribute, sublicense, and/or sell copies of the Software, and to
16+
* permit persons to whom the Software is furnished to do so, subject to
17+
* the following conditions:
18+
*
19+
* The above copyright notice and this permission notice shall be
20+
* included in all copies or substantial portions of the Software.
21+
*
22+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
*/
30+
31+
/**
32+
* MustacheView
33+
*
34+
* The MustacheView is a Custom View class that renders templates using the
35+
* Mustache template language (http://mustache.github.com/) and the
36+
* [Mustache.php library](github.com/bobthecow/mustache.php).
37+
*
38+
* There is one field that you, the developer, will need to change:
39+
* - mustacheDirectory
40+
*
41+
* @package Slim
42+
* @author Johnson Page <http://johnsonpage.org>
43+
*/
44+
class MustacheView extends Slim_View {
45+
46+
/**
47+
* @var string The path to the directory containing Mustache.php
48+
*/
49+
public static $mustacheDirectory = null;
50+
51+
/**
52+
* Renders a template using Mustache.php.
53+
*
54+
* @see View::render()
55+
* @param string $template The template name specified in Slim::render()
56+
* @return string
57+
*/
58+
public function render( $template ) {
59+
require_once self::$mustacheDirectory . '/Mustache.php';
60+
$m = new Mustache();
61+
$contents = file_get_contents($this->getTemplatesDirectory() . '/' . ltrim($template, '/'));
62+
return $m->render($contents, $this->data);
63+
}
64+
65+
}
66+
67+
?>

0 commit comments

Comments
 (0)