Skip to content

Commit

Permalink
=4.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc-business-account committed Feb 4, 2024
1 parent a886138 commit 6fa51ba
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 241 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Alternatively, BladeOne allows running arbitrary code from any class or method i
## Install (pick one of the next one)

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

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

### Fluent

```php
Expand Down Expand Up @@ -341,6 +349,10 @@ or
@endguest
```

### Custom controls.
There are multiples ways to create a new control (tag)




## Extensions Libraries (optional)
Expand Down
98 changes: 49 additions & 49 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"name": "eftec/bladeone",
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
"type": "library",
"keywords": [
"blade",
"template",
"view",
"php",
"templating"
],
"homepage": "https://github.com/EFTEC/BladeOne",
"license": "MIT",
"authors": [
{
"name": "Jorge Patricio Castro Castillo",
"email": "jcastro@eftec.cl"
}
],
"require": {
"php": ">=7.2.5",
"ext-json": "*"
},
"suggest": {
"ext-mbstring": "This extension is used if it's active",
"eftec/bladeonehtml": "Extension to create forms"
},
"archive": {
"exclude": [
"/examples"
]
},
"autoload": {
"psr-4": {
"eftec\\bladeone\\": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"eftec\\tests\\": "tests/"
}
},
"bin": [
"lib/bladeonecli"
],
"require-dev": {
"phpunit/phpunit": "^8.5.23"
}
}
{
"name": "eftec/bladeone",
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
"type": "library",
"keywords": [
"blade",
"template",
"view",
"php",
"templating"
],
"homepage": "https://github.com/EFTEC/BladeOne",
"license": "MIT",
"authors": [
{
"name": "Jorge Patricio Castro Castillo",
"email": "jcastro@eftec.cl"
}
],
"require": {
"php": ">=7.2",
"ext-json": "*"
},
"suggest": {
"ext-mbstring": "This extension is used if it's active",
"eftec/bladeonehtml": "Extension to create forms"
},
"archive": {
"exclude": [
"/examples"
]
},
"autoload": {
"psr-4": {
"eftec\\bladeone\\": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"eftec\\tests\\": "tests/"
}
},
"bin": [
"lib/bladeonecli"
],
"require-dev": {
"phpunit/phpunit": "^8.5.23"
}
}
48 changes: 48 additions & 0 deletions examples/example_customcontrol.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Copyright (c) 2024 Jorge Patricio Castro Castillo MIT License.
*/
include "../lib/BladeOne.php";
use eftec\bladeone\BladeOne;

$views = __DIR__ . '/views';
$compiledFolder = __DIR__ . '/compiled';
$blade=new BladeOne($views, $compiledFolder, BladeOne::MODE_DEBUG);
$blade->pipeEnable=true;


$blade->clearMethods();

$blade->addMethod('runtime','table',static function($args) {
// in this context, $this means the autoTest class and not the blade class.
$args=array_merge(['alias'=>'alias'],$args); // you could use array merge to set a default value.
BladeOne::$instance->addControlStackChild('runtimeTable',$args); // we store the current control in the stack.
return '<ul>';
});
$blade->addMethod('runtime','endtable',static function($args) {
BladeOne::$instance->closeControlStack();
return '</ul>';
});
$blade->addMethod('runtime','row',static function() {
$parent=BladeOne::$instance->lastControlStack()['args']; // getting the values of the parent control using the stack
$result='';
foreach($parent['values'] as $v) {
$result.=BladeOne::$instance->runChild('auto.test2_control',[$parent['alias']=>$v]);
}
return $result;
});
$blade->addMethod('runtime','row2',function() {
$parent=BladeOne::$instance->lastControlStack()['args']; // getting the values of the parent control using the stack
$result='';
foreach($parent['values'] as $v) {
$result.="<li>$v</li>\n";
}
return $result;
});


try {
echo $blade->run("auto.test2",['countries' => ["chile","argentina","peru"]]);
} catch (Exception $e) {
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString();
}
32 changes: 32 additions & 0 deletions examples/example_customcontrol2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright (c) 2024 Jorge Patricio Castro Castillo MIT License.
*/
include "../lib/BladeOne.php";
use eftec\bladeone\BladeOne;

$views = __DIR__ . '/views';
$compiledFolder = __DIR__ . '/compiled';
$blade=new BladeOne($views, $compiledFolder, BladeOne::MODE_DEBUG);
$blade->pipeEnable=true;


$blade->clearMethods();


$blade->addMethod('runtime','card',static function($args) {
$result='';
$result.=BladeOne::$instance->runChild('auto.card',['value'=>$args[0]]);
return $result;
});


try {
echo $blade->run("auto.test3",['items' => [
['title'=>"chile",'content'=>'lorem ipsum'],
['title'=>"argentina",'content'=>'lorem ipsum'],
['title'=>"peru",'content'=>'lorem ipsum'],
]]);
} catch (Exception $e) {
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString();
}
7 changes: 7 additions & 0 deletions examples/views/auto/card.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">{{$value['title']}}</h5>
<p class="card-text">{{$value['content']}}</p>
<a href="#" class="btn btn-primary">Go somewhere</a>
</div>
</div>
4 changes: 4 additions & 0 deletions examples/views/auto/test1.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it is test 1
@one(a1="hola" a2="mundo")

two:@two(1,2,3)
6 changes: 6 additions & 0 deletions examples/views/auto/test2.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@table(values=$countries alias="alias")
row:
@row()
row2:
@row2()
@endtable
1 change: 1 addition & 0 deletions examples/views/auto/test2_control.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<li>{{$alias}}</li>
29 changes: 29 additions & 0 deletions examples/views/auto/test3.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<div class="container-fluid">
<div class="row">
@foreach($items as $item)
@card($item)
@endforeach
</div>
</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<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>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>
Loading

0 comments on commit 6fa51ba

Please sign in to comment.