]> git.andy128k.dev Git - ipf-legacy-template.git/commitdiff
initial commit
authorAndrey Kutejko <andy128k@gmail.com>
Sun, 8 Feb 2015 10:21:08 +0000 (12:21 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Sun, 8 Feb 2015 11:24:04 +0000 (13:24 +0200)
.gitignore [new file with mode: 0644]
composer.json [new file with mode: 0644]
composer.lock [new file with mode: 0644]
src/shortcuts.php [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..4acdc48
--- /dev/null
@@ -0,0 +1,3 @@
+.DS_Store
+/vendor
+
diff --git a/composer.json b/composer.json
new file mode 100644 (file)
index 0000000..0e157a8
--- /dev/null
@@ -0,0 +1,25 @@
+{
+  "name": "andy128k/ipf-legacy-template",
+  "authors": [
+    {
+      "name": "Andrey Kutejko",
+      "email": "andy128k@gmail.com"
+    }
+  ],
+  "repositories": [
+    {
+      "type": "composer",
+      "url": "http://packages.andy128k.net/php/"
+    }
+  ],
+  "autoload": {
+    "classmap" : ["src"]
+  },
+  "require": {
+    "andy128k/ipf-template": "0.1.*@dev"
+  },
+  "suggest": {
+    "andy128k/ipf": "Web Framework"
+  }
+}
+
diff --git a/composer.lock b/composer.lock
new file mode 100644 (file)
index 0000000..0df18d8
--- /dev/null
@@ -0,0 +1,53 @@
+{
+    "_readme": [
+        "This file locks the dependencies of your project to a known state",
+        "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "This file is @generated automatically"
+    ],
+    "hash": "7bc61fe1f500d3685ddc2c9ae301e6bf",
+    "packages": [
+        {
+            "name": "andy128k/ipf-template",
+            "version": "0.1.x-dev",
+            "source": {
+                "type": "git",
+                "url": "git://git.andy128k.net/ipf-template.git",
+                "reference": "6b0ee73b0df4689317a975f6c09ecc01fdddad6d"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "4.4.*"
+            },
+            "type": "library",
+            "autoload": {
+                "classmap": [
+                    "lib"
+                ]
+            },
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Alex Litovchenko",
+                    "email": "alex.litovchenko@gmail.com"
+                },
+                {
+                    "name": "Andrey Kutejko",
+                    "email": "andy128k@gmail.com"
+                }
+            ],
+            "description": "Template Engine extracted from IPF Web Framework",
+            "time": "2015-01-11 10:49:36"
+        }
+    ],
+    "packages-dev": [],
+    "aliases": [],
+    "minimum-stability": "stable",
+    "stability-flags": {
+        "andy128k/ipf-template": 20
+    },
+    "prefer-stable": false,
+    "prefer-lowest": false,
+    "platform": [],
+    "platform-dev": []
+}
diff --git a/src/shortcuts.php b/src/shortcuts.php
new file mode 100644 (file)
index 0000000..b5449e3
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+final class IPF_Shortcuts
+{
+    public static function RenderToResponse($tplfile, $params=array(), $request=null)
+    {
+        return new IPF_HTTP_Response(self::RenderToString($tplfile, $params, $request));
+    }
+
+    public static function RenderToString($tplfile, $params=array(), $request=null)
+    {
+        $context = IPF_Project_Template::context($params, $request);
+        $tmpl = new IPF_Template_File($tplfile, self::getDefaultTemplateEnvironment());
+        return $tmpl->render(new IPF_Template_Context($context));
+    }
+
+    private static $defaultEnvironment = null;
+
+    public static function getDefaultTemplateEnvironment()
+    {
+        if (!self::$defaultEnvironment)
+            self::$defaultEnvironment = self::createEnvironment();
+        return self::$defaultEnvironment;
+    }
+
+    private static function createEnvironment()
+    {
+        $e = new IPF_Template_Environment_FileSystem;
+
+        $e->cache = IPF::get('tmp');
+        $e->debug = IPF::get('debug');
+
+        $e->folders = IPF_Project_Template::templateDirs();
+
+        $e->tags['url'] = 'IPF_Template_Tag_Url';
+        $e->tags['params'] = 'IPF_Template_Tag_Params';
+        // extra tags
+        $e->tags = array_merge(IPF::get('template_tags', array()), $e->tags);
+
+        // extra modifiers
+        $e->modifiers = array_merge(IPF::get('template_modifiers', array()), $e->modifiers);
+
+        return $e;
+    }
+}
+
+class IPF_Template_Tag_Url extends IPF_Template_Tag
+{
+    function start()
+    {
+        echo IPF_Project_Template::urlTag(func_get_args());
+    }
+}
+
+class IPF_Template_Tag_Params extends IPF_Template_Tag
+{
+    function start()
+    {
+        echo IPF_Project_Template::paramsTag(func_get_args());
+    }
+}
+