Skip to content

Commit 6fa51ba

Browse files
=4.11
1 parent a886138 commit 6fa51ba

15 files changed

+577
-241
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ Alternatively, BladeOne allows running arbitrary code from any class or method i
205205
## Install (pick one of the next one)
206206

207207
1) Download the file manually then unzip (using WinRAR,7zip or any other program) https://github.com/EFTEC/BladeOne/archive/master.zip
208-
2) git clone https://github.com/EFTEC/BladeOne
208+
2) git clone https://github.com/EFTEC/BladeOne (it doesn't include the examples)
209209
3) Composer. See [usage](#usage)
210210
4) wget https://github.com/EFTEC/BladeOne/archive/master.zip
211211
unzip master.zip
@@ -253,6 +253,14 @@ $blade = new BladeOne(); // MODE_DEBUG allows to pinpoint troubles.
253253
echo $blade->run("hello",array("variable1"=>"value1")); // it calls /views/hello.blade.php
254254
```
255255

256+
### Injection
257+
You can inject the Bladeone using an existing instance of it. If there is no instance, then it will create a new one using
258+
the default folders.
259+
```
260+
$blade=BladeOne::$instance;
261+
echo $blade->run("hello",array("variable1"=>"value1")); // it calls /views/hello.blade.php
262+
```
263+
256264
### Fluent
257265

258266
```php
@@ -341,6 +349,10 @@ or
341349
@endguest
342350
```
343351

352+
### Custom controls.
353+
There are multiples ways to create a new control (tag)
354+
355+
344356

345357

346358
## Extensions Libraries (optional)

composer.json

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
{
2-
"name": "eftec/bladeone",
3-
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
4-
"type": "library",
5-
"keywords": [
6-
"blade",
7-
"template",
8-
"view",
9-
"php",
10-
"templating"
11-
],
12-
"homepage": "https://github.com/EFTEC/BladeOne",
13-
"license": "MIT",
14-
"authors": [
15-
{
16-
"name": "Jorge Patricio Castro Castillo",
17-
"email": "jcastro@eftec.cl"
18-
}
19-
],
20-
"require": {
21-
"php": ">=7.2.5",
22-
"ext-json": "*"
23-
},
24-
"suggest": {
25-
"ext-mbstring": "This extension is used if it's active",
26-
"eftec/bladeonehtml": "Extension to create forms"
27-
},
28-
"archive": {
29-
"exclude": [
30-
"/examples"
31-
]
32-
},
33-
"autoload": {
34-
"psr-4": {
35-
"eftec\\bladeone\\": "lib/"
36-
}
37-
},
38-
"autoload-dev": {
39-
"psr-4": {
40-
"eftec\\tests\\": "tests/"
41-
}
42-
},
43-
"bin": [
44-
"lib/bladeonecli"
45-
],
46-
"require-dev": {
47-
"phpunit/phpunit": "^8.5.23"
48-
}
49-
}
1+
{
2+
"name": "eftec/bladeone",
3+
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
4+
"type": "library",
5+
"keywords": [
6+
"blade",
7+
"template",
8+
"view",
9+
"php",
10+
"templating"
11+
],
12+
"homepage": "https://github.com/EFTEC/BladeOne",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Jorge Patricio Castro Castillo",
17+
"email": "jcastro@eftec.cl"
18+
}
19+
],
20+
"require": {
21+
"php": ">=7.2",
22+
"ext-json": "*"
23+
},
24+
"suggest": {
25+
"ext-mbstring": "This extension is used if it's active",
26+
"eftec/bladeonehtml": "Extension to create forms"
27+
},
28+
"archive": {
29+
"exclude": [
30+
"/examples"
31+
]
32+
},
33+
"autoload": {
34+
"psr-4": {
35+
"eftec\\bladeone\\": "lib/"
36+
}
37+
},
38+
"autoload-dev": {
39+
"psr-4": {
40+
"eftec\\tests\\": "tests/"
41+
}
42+
},
43+
"bin": [
44+
"lib/bladeonecli"
45+
],
46+
"require-dev": {
47+
"phpunit/phpunit": "^8.5.23"
48+
}
49+
}

examples/example_customcontrol.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2024 Jorge Patricio Castro Castillo MIT License.
4+
*/
5+
include "../lib/BladeOne.php";
6+
use eftec\bladeone\BladeOne;
7+
8+
$views = __DIR__ . '/views';
9+
$compiledFolder = __DIR__ . '/compiled';
10+
$blade=new BladeOne($views, $compiledFolder, BladeOne::MODE_DEBUG);
11+
$blade->pipeEnable=true;
12+
13+
14+
$blade->clearMethods();
15+
16+
$blade->addMethod('runtime','table',static function($args) {
17+
// in this context, $this means the autoTest class and not the blade class.
18+
$args=array_merge(['alias'=>'alias'],$args); // you could use array merge to set a default value.
19+
BladeOne::$instance->addControlStackChild('runtimeTable',$args); // we store the current control in the stack.
20+
return '<ul>';
21+
});
22+
$blade->addMethod('runtime','endtable',static function($args) {
23+
BladeOne::$instance->closeControlStack();
24+
return '</ul>';
25+
});
26+
$blade->addMethod('runtime','row',static function() {
27+
$parent=BladeOne::$instance->lastControlStack()['args']; // getting the values of the parent control using the stack
28+
$result='';
29+
foreach($parent['values'] as $v) {
30+
$result.=BladeOne::$instance->runChild('auto.test2_control',[$parent['alias']=>$v]);
31+
}
32+
return $result;
33+
});
34+
$blade->addMethod('runtime','row2',function() {
35+
$parent=BladeOne::$instance->lastControlStack()['args']; // getting the values of the parent control using the stack
36+
$result='';
37+
foreach($parent['values'] as $v) {
38+
$result.="<li>$v</li>\n";
39+
}
40+
return $result;
41+
});
42+
43+
44+
try {
45+
echo $blade->run("auto.test2",['countries' => ["chile","argentina","peru"]]);
46+
} catch (Exception $e) {
47+
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString();
48+
}

examples/example_customcontrol2.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright (c) 2024 Jorge Patricio Castro Castillo MIT License.
4+
*/
5+
include "../lib/BladeOne.php";
6+
use eftec\bladeone\BladeOne;
7+
8+
$views = __DIR__ . '/views';
9+
$compiledFolder = __DIR__ . '/compiled';
10+
$blade=new BladeOne($views, $compiledFolder, BladeOne::MODE_DEBUG);
11+
$blade->pipeEnable=true;
12+
13+
14+
$blade->clearMethods();
15+
16+
17+
$blade->addMethod('runtime','card',static function($args) {
18+
$result='';
19+
$result.=BladeOne::$instance->runChild('auto.card',['value'=>$args[0]]);
20+
return $result;
21+
});
22+
23+
24+
try {
25+
echo $blade->run("auto.test3",['items' => [
26+
['title'=>"chile",'content'=>'lorem ipsum'],
27+
['title'=>"argentina",'content'=>'lorem ipsum'],
28+
['title'=>"peru",'content'=>'lorem ipsum'],
29+
]]);
30+
} catch (Exception $e) {
31+
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString();
32+
}

examples/views/auto/card.blade.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="card" style="width: 18rem;">
2+
<div class="card-body">
3+
<h5 class="card-title">{{$value['title']}}</h5>
4+
<p class="card-text">{{$value['content']}}</p>
5+
<a href="#" class="btn btn-primary">Go somewhere</a>
6+
</div>
7+
</div>

examples/views/auto/test1.blade.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
it is test 1
2+
@one(a1="hola" a2="mundo")
3+
4+
two:@two(1,2,3)

examples/views/auto/test2.blade.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@table(values=$countries alias="alias")
2+
row:
3+
@row()
4+
row2:
5+
@row2()
6+
@endtable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<li>{{$alias}}</li>

examples/views/auto/test3.blade.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<!-- Required meta tags -->
5+
<meta charset="utf-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
7+
8+
<!-- Bootstrap CSS -->
9+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
10+
11+
<title>Hello, world!</title>
12+
</head>
13+
<body>
14+
<h1>Hello, world!</h1>
15+
<div class="container-fluid">
16+
<div class="row">
17+
@foreach($items as $item)
18+
@card($item)
19+
@endforeach
20+
</div>
21+
</div>
22+
23+
<!-- Optional JavaScript -->
24+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
25+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
26+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.14.3/dist/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
27+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)