Skip to content

Commit a0a7211

Browse files
committed
Start explaining Phug Component concept
1 parent fede282 commit a0a7211

7 files changed

Lines changed: 180 additions & 6 deletions

File tree

.gitignore

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
composer.phar
2+
composer.lock
3+
*.cache
4+
/coverage/
25
/vendor/
3-
4-
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
5-
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6-
# composer.lock

.travis.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
language: php
2+
3+
php:
4+
- 7.2
5+
- 7.3
6+
- 7.4
7+
- nightly
8+
9+
before_script:
10+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11+
- chmod +x ./cc-test-reporter
12+
- ./cc-test-reporter before-build
13+
- travis_retry composer self-update
14+
- travis_retry composer install --no-interaction --prefer-source --dev
15+
16+
script:
17+
- vendor/bin/phpunit --verbose --coverage-text --coverage-clover=coverage.xml
18+
19+
after_script:
20+
- vendor/bin/test-reporter --coverage-report coverage.xml
21+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
22+
23+
after_success:
24+
- bash <(curl -s https://codecov.io/bash)
25+
26+
env:
27+
global:
28+
- CC_TEST_REPORTER_ID=985c432a65a5dabaacffbd031324ecd0390128f73c99b7e3fe04dcec307262c2

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,48 @@
1-
# component
2-
Extension for pug-php/phug to use components in templates
1+
# Phug Component
2+
3+
Extension for pug-php and phug to use components in templates
4+
5+
## Install
6+
7+
```
8+
composer require phug/component
9+
```
10+
11+
Enable it globally:
12+
```php
13+
\Phug\Component\ComponentExtension::enable();
14+
```
15+
16+
## Usage
17+
18+
```pug
19+
//- Register a component
20+
component alert
21+
.alert.alert-danger
22+
.alert-title
23+
slot title
24+
25+
slot
26+
27+
section
28+
//- Somewhere later in your template
29+
@alert
30+
slot title
31+
| Hello #[em world]!
32+
33+
p This is an alert!
34+
```
35+
36+
Output:
37+
38+
```html
39+
<section>
40+
<div class="alert alert-danger">
41+
<div class="alert-title">
42+
Hello <em>world</em>!
43+
</div>
44+
45+
<p>This is an alert!</p>
46+
</div>
47+
</section>
48+
```

composer.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"name": "phug/component",
3+
"type": "library",
4+
"keywords": ["phug", "pug", "html", "component"],
5+
"description": "Extension for pug-php and phug to use components in templates",
6+
"license": "MIT",
7+
"homepage": "http://phug-lang.com",
8+
"authors": [
9+
{
10+
"name": "KyleKatarn",
11+
"email": "jade-php@selfbuild.fr",
12+
"homepage": "http://github.com/kylekatarnls"
13+
}
14+
],
15+
"support": {
16+
"email": "support@phug-lang.com",
17+
"issues": "https://github.com/phug-php/phug/issues",
18+
"source": "https://github.com/phug-php/phug",
19+
"docs": "http://phug-lang.com/docs"
20+
},
21+
"minimum-stability": "stable",
22+
"require": {
23+
"php": ">=7.2",
24+
"phug/renderer": "^1.3"
25+
},
26+
"require-dev": {
27+
"phpunit/phpunit": "^8"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"Phug\\Component\\": "./src/Phug/Component/"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"Phug\\Test\\Component\\": "./tests/Phug/Component/"
37+
}
38+
}
39+
}

phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<phpunit
2+
bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
colors="true"
5+
convertErrorsToExceptions="true"
6+
convertNoticesToExceptions="true"
7+
convertWarningsToExceptions="true"
8+
forceCoversAnnotation="true"
9+
>
10+
<testsuites>
11+
<testsuite name="plug">
12+
<directory suffix="Test.php">tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<filter>
16+
<whitelist processUncoveredFilesFromWhitelist="true">
17+
<directory suffix=".php">src</directory>
18+
</whitelist>
19+
</filter>
20+
<logging>
21+
<log type="coverage-clover" target="./coverage/result.xml"/>
22+
<log type="coverage-html" target="./coverage/result"/>
23+
<log type="coverage-text" target="./coverage/result.txt"/>
24+
</logging>
25+
</phpunit>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Phug\Component;
4+
5+
class ComponentExtension
6+
{
7+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Phug\Test\Component;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ComponentExtensionTest extends TestCase
8+
{
9+
public function getReadmeExamples()
10+
{
11+
preg_match_all(
12+
'/```pug\n(?<pug>[\s\S]+)\n```[\s\S]*```html\n(?<html>[\s\S]+)\n```/U',
13+
file_get_contents(__DIR__.'/../../../README.md'),
14+
$examples,
15+
PREG_SET_ORDER
16+
);
17+
18+
foreach ($examples as $example) {
19+
yield [$example['html'], $example['pug']];
20+
}
21+
}
22+
23+
/**
24+
* @dataProvider getReadmeExamples
25+
*/
26+
public function testReadme($htmlCode, $pugCode)
27+
{
28+
$this->assertSame($htmlCode, $pugCode);
29+
}
30+
}

0 commit comments

Comments
 (0)