Skip to content

Commit f975c44

Browse files
committed
First working state
1 parent 38a2f74 commit f975c44

36 files changed

+1661
-1
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.buildpath
2+
/.project
3+
/.settings
4+
/.idea
5+
/build
6+
/tools
7+
/vendor
8+
cache.properties

.travis.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
os:
2+
- linux
3+
- osx
4+
5+
language: php
6+
7+
php:
8+
- 7.0
9+
- hhvm
10+
- hhvm-nightly
11+
12+
matrix:
13+
allow_failures:
14+
- php: hhvm
15+
- php: hhvm-nightly
16+
17+
before_script:
18+
- composer install --prefer-dist --dev
19+
- phpenv rehash
20+
21+
notifications:
22+
email: false

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
All notable changes to Templado are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
4+
5+
## 1.0.0 - ????-??-??
6+
* Initial Release
7+

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# templado
1+
# Templado
22
A pragmatic approach to templating for PHP 7.x

build.xml

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project name="Templado" default="build" basedir=".">
3+
<property name="source" value="src"/>
4+
5+
<target name="clean" description="Clean up and create artifact directories">
6+
<delete dir="${basedir}/build/docs"/>
7+
<delete dir="${basedir}/build/coverage"/>
8+
<delete dir="${basedir}/build/logs"/>
9+
<delete dir="${basedir}/build/pdepend"/>
10+
<delete dir="${basedir}/build/phpab"/>
11+
12+
<mkdir dir="${basedir}/build/docs"/>
13+
<mkdir dir="${basedir}/build/coverage"/>
14+
<mkdir dir="${basedir}/build/logs"/>
15+
<mkdir dir="${basedir}/build/pdepend"/>
16+
<mkdir dir="${basedir}/build/phpab"/>
17+
</target>
18+
19+
<target name="lint">
20+
<apply executable="php" failonerror="true">
21+
<arg value="-l" />
22+
23+
<fileset dir="${basedir}/src">
24+
<include name="**/*.php" />
25+
<modified />
26+
</fileset>
27+
28+
</apply>
29+
</target>
30+
31+
<target name="phpab" description="Build autoloader">
32+
<exec executable="phpab">
33+
<arg line="--cache ${basedir}/build/phpab/autoload.cache -1 -o src/autoload.php" />
34+
<arg path="src" />
35+
</exec>
36+
</target>
37+
38+
<target name="phpunit" description="Run unit tests using PHPUnit">
39+
<exec executable="phpunit" failonerror="true"/>
40+
</target>
41+
42+
<target name="parallelTasks"
43+
description="Run the pdepend, phpmd, phpcpd, phpcs and phploc tasks in parallel using a maximum of 2 threads.">
44+
<parallel threadCount="2">
45+
<sequential>
46+
<antcall target="pdepend"/>
47+
<antcall target="phpmd"/>
48+
</sequential>
49+
<antcall target="phpcpd"/>
50+
<antcall target="phpcs"/>
51+
<antcall target="phploc"/>
52+
</parallel>
53+
</target>
54+
55+
<target name="pdepend" description="Generate jdepend.xml and software metrics charts using PHP_Depend">
56+
<exec executable="pdepend">
57+
<arg line="--jdepend-xml=${basedir}/build/logs/jdepend.xml
58+
--jdepend-chart=${basedir}/build/pdepend/dependencies.svg
59+
--overview-pyramid=${basedir}/build/pdepend/overview-pyramid.svg
60+
${source}"/>
61+
</exec>
62+
</target>
63+
64+
<target name="phpmd" description="Generate pmd.xml using PHPMD">
65+
<exec executable="phpmd">
66+
<arg line="${source}
67+
xml
68+
codesize,design,naming,unusedcode
69+
--reportfile ${basedir}/build/logs/pmd.xml"/>
70+
</exec>
71+
</target>
72+
73+
<target name="phpcpd" description="Generate pmd-cpd.xml using PHPCPD">
74+
<exec executable="phpcpd">
75+
<arg line="--log-pmd ${basedir}/build/logs/pmd-cpd.xml ${source}"/>
76+
</exec>
77+
</target>
78+
79+
<target name="phploc" description="Generate phploc.xml">
80+
<exec executable="phploc">
81+
<arg line="--count-tests --log-xml ${basedir}/build/logs/phploc.xml ${source} tests"/>
82+
</exec>
83+
</target>
84+
85+
<target name="phpcs" description="Generate checkstyle.xml using PHP_CodeSniffer">
86+
<exec executable="phpcs" output="/dev/null">
87+
<arg line="--report=checkstyle
88+
--report-file=${basedir}/build/logs/checkstyle.xml
89+
--standard=phpcs.xml
90+
${source}"/>
91+
</exec>
92+
</target>
93+
94+
<target name="docs">
95+
<delete dir="${basedir}/build/docs" />
96+
<exec executable="${basedir}/phpdox" />
97+
</target>
98+
99+
<target name="build" depends="clean,lint,parallelTasks,phpunit"/>
100+
<target name="test" depends="clean,lint,phpunit"/>
101+
</project>

composer.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name" : "theseer/templado",
3+
"description" : "A pragmatic approach to templating for PHP 7.x",
4+
"license" : "BSD-3-Clause",
5+
"authors" : [
6+
{
7+
"name" : "Arne Blankerts",
8+
"email" : "[email protected]",
9+
"role" : "Developer"
10+
}
11+
],
12+
"support" : {
13+
"issues" : "https://github.com/theseer/templado/issues"
14+
},
15+
"require" : {
16+
"php" : ">=7.0",
17+
"ext-dom" : "*"
18+
},
19+
"autoload": {
20+
"classmap": [
21+
"src/"
22+
]
23+
},
24+
"minimum-stability" : "stable",
25+
"prefer-stable" : true
26+
}

examples/asset.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace TheSeer\Templado;
4+
5+
require __DIR__ . '/../src/autoload.php';
6+
7+
try {
8+
$page = Page::fromFile(
9+
new FileName(__DIR__ . '/html/basic.xhtml')
10+
);
11+
12+
$assetCollection = new AssetCollection();
13+
14+
$sample = new \DOMDocument();
15+
$fragment = $sample->createDocumentFragment();
16+
$fragment->appendXML('This is a first test: <span id="nested" />');
17+
18+
$assetCollection->addAsset(
19+
'test', new Asset($fragment)
20+
);
21+
22+
$assetCollection->addAsset(
23+
'nested', new Asset(new \DOMText('Hello world'))
24+
);
25+
$page->applyAssets(
26+
$assetCollection
27+
);
28+
29+
echo $page->asString();
30+
31+
} catch (PageDomException $e) {
32+
foreach($e->getErrorList() as $error) {
33+
echo (string)$error;
34+
}
35+
}

examples/html/basic.xhtml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" ?>
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8" />
6+
<title>Basic Test</title>
7+
</head>
8+
<body>
9+
<h1 id="test" />
10+
</body>
11+
</html>

examples/html/viewmodel.xhtml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" ?>
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="UTF-8"/>
6+
<title>Basic ViewModel Test</title>
7+
</head>
8+
<body>
9+
<h1 property="headline" title="Original title" class="base">Original Headline</h1>
10+
<div>
11+
<ul>
12+
<li property="test">Original Value 1</li>
13+
<li property="test">Original Value 2</li>
14+
<li property="test">Original Value 3</li>
15+
<li property="test">Original Value 4</li>
16+
</ul>
17+
</div>
18+
<div property="user">
19+
<p>Name: <span property="name">Original Name</span></p>
20+
<div>
21+
<span>EMail:</span>
22+
<ul>
23+
<li property="emailLinks"><a property="email" href="mailto:[email protected]" class="current">[email protected]</a></li>
24+
</ul>
25+
</div>
26+
</div>
27+
</body>
28+
</html>

examples/view.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php declare(strict_types = 1);
2+
namespace TheSeer\Templado;
3+
4+
require __DIR__ . '/../src/autoload.php';
5+
require __DIR__ . '/viewmodel/viewmodel.php';
6+
7+
try {
8+
$page = Page::fromFile(
9+
new FileName(__DIR__ . '/html/viewmodel.xhtml')
10+
);
11+
$page->applyViewModel(new Example\ViewModel());
12+
13+
echo $page->asString() . "\n";
14+
15+
} catch (PageDomException $e) {
16+
foreach($e->getErrorList() as $error) {
17+
echo (string)$error;
18+
}
19+
}

examples/viewmodel/viewmodel.php

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace TheSeer\Templado\Example;
4+
5+
class Headline {
6+
public function asString() {
7+
return 'Hallo welt!';
8+
}
9+
10+
public function class($original) {
11+
return $original . ' added';
12+
}
13+
14+
public function title() {
15+
return 'new Title';
16+
}
17+
}
18+
19+
class Email {
20+
private $addr;
21+
22+
public function __construct(string $addr) {
23+
$this->addr = $addr;
24+
}
25+
26+
public function asString() {
27+
return $this->addr;
28+
}
29+
30+
public function href() {
31+
return 'mailto:' . $this->asString();
32+
}
33+
34+
public function class() {
35+
return false;
36+
}
37+
}
38+
39+
class EMailLink {
40+
41+
/** @var Email */
42+
private $email;
43+
44+
/**
45+
* @param Email $email
46+
*/
47+
public function __construct(Email $email) {
48+
$this->email = $email;
49+
}
50+
51+
public function email() {
52+
return $this->email;
53+
}
54+
}
55+
56+
class User {
57+
58+
public function name() {
59+
return 'Willi Wichtig';
60+
}
61+
62+
public function emailLinks() {
63+
return [
64+
new EMailLink(
65+
new Email('[email protected]')
66+
),
67+
new EMailLink(
68+
new Email('[email protected]')
69+
)
70+
];
71+
}
72+
73+
}
74+
75+
class ViewModel {
76+
77+
public function headline() {
78+
return new Headline();
79+
}
80+
81+
public function test() {
82+
return ['a', 'b'];
83+
}
84+
85+
public function user() {
86+
return new User();
87+
}
88+
}

phive.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpab" version="*" installed="1.20.0" location="./tools/"/>
4+
<phar name="phpunit" version="*" installed="5.7.4" location="./tools/"/>
5+
</phive>

0 commit comments

Comments
 (0)