Skip to content

Commit 1a71ea8

Browse files
committed
first public release
0 parents  commit 1a71ea8

22 files changed

+829
-0
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
indent_size = 4
9+
indent_style = space
10+
end_of_line = lf
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor
2+
composer.phar
3+
composer.lock
4+
.DS_Store
5+
.idea

.scrutinizer.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
3+
php:
4+
- 7.2
5+
- 7.3
6+
7+
env:
8+
matrix:
9+
- COMPOSER_FLAGS="--prefer-lowest"
10+
- COMPOSER_FLAGS=""
11+
12+
before_script:
13+
- travis_retry composer self-update
14+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
15+
16+
script:
17+
- phpunit --coverage-text --coverage-clover=coverage.clover

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
All notable changes to `laravel-db-blade` will be documented in this file
4+
5+
## 0.1.0 - 2019-04-16
6+
- first public release

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2019 © Javier Pérez — [email protected]
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Laravel DB Blade
2+
3+
4+
## Render Blade templates from Eloquent Model Fields
5+
6+
This package allows you to render Blade templates from a database model instead of files. It is based on [Flynsarmy](https://github.com/Flynsarmy/)'s [**laravel-db-blade-compiler**](https://github.com/Flynsarmy/laravel-db-blade-compiler).
7+
8+
9+
## Installation
10+
11+
You can install the package via composer:
12+
13+
``` bash
14+
composer require kiroushi/laravel-db-blade
15+
```
16+
17+
Publish the assets using artisan:
18+
19+
```bash
20+
php artisan vendor:publish
21+
```
22+
23+
And then set up your DbView model in the `config/db-blade.php` configuration file. A default model (**Kiroushi\DbBlade\Models\DbView**) is included in the package:
24+
25+
```php
26+
return [
27+
28+
'model_name' => 'Kiroushi\DbBlade\Models\DbView',
29+
'table_name' => 'db_views',
30+
31+
/**
32+
* The default name field used to look up for the model.
33+
* e.g. DbView::make($viewName) or dbview($viewName)
34+
*/
35+
'name_field' => 'name',
36+
37+
/**
38+
* The default model field to be compiled when not explicitly specified
39+
* with DbView::field($fieldName) or DbView::model($modelName, $fieldName)
40+
*/
41+
'content_field' => 'content',
42+
43+
/**
44+
* This property will be added to models being compiled with DbView
45+
* to keep track of which field in the model is being compiled
46+
*/
47+
'model_property' => '__db_blade_compiler_content_field',
48+
49+
'cache' => false,
50+
'cache_path' => 'app/db-blade/cache/views'
51+
52+
];
53+
```
54+
55+
After the configuration and ensuring that the migration has been published, you can create the database views table by running the migrations:
56+
57+
```bash
58+
php artisan migrate
59+
```
60+
61+
## Usage
62+
63+
This package offers a `DbView` facade with the exact same syntax and functionality than `View`:
64+
65+
```php
66+
return DbView::make('home')->with(['foo' => 'bar']);
67+
```
68+
69+
You can also use the `dbview()` helper matching Laravel's base `view()` helper functionality. If no arguments are supplied, the factory is returned:
70+
71+
```php
72+
return dbview()->make('home')->with(['foo' => 'bar']);
73+
```
74+
75+
If a string is supplied, a view with that name will be looked up for and rendered:
76+
77+
```php
78+
return dbview('home')->with(['foo' => 'bar']);
79+
```
80+
81+
### Overriding settings at runtime
82+
83+
You can override individual settings for the model, name field and content field by using associated methods:
84+
85+
```php
86+
return DbView::make('home')->model('App\Template');
87+
88+
return DbView::make('home')->field('template_name');
89+
90+
// You can also pass the model and name field as a shorthand:
91+
return DbView::make('home')->model('App\Template', 'template_name');
92+
93+
// Override content field
94+
return DbView::make('home')->contentField('template_content');
95+
96+
// ... or a combination of these
97+
return DbView::make('home')->model('App\Template', 'template_name')->contentField('template_content');
98+
```
99+
100+
### Cache
101+
102+
By default, cache is disabled in config file. If you enable the setting, a compiled version of the views will be stored at the desired path. If the model is updated, the *updated_at* field will be checked against the file modification date and the view will be re-rendered and cached.
103+
104+
## Changelog
105+
106+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
107+
108+
## To do list
109+
110+
- Expose view finder callback
111+
- Separate standard view composers from dbview composers.
112+
- Unit tests
113+
114+
## License
115+
116+
**laravel-db-blade** is open-sourced software licensed under the MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "kiroushi/laravel-db-blade",
3+
"description": "Render Blade templates from Eloquent Model Fields",
4+
"keywords": [
5+
"laravel",
6+
"blade",
7+
"compiler",
8+
"eloquent",
9+
"model"
10+
],
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Javier Pérez <Kiroushi>",
15+
"email": "[email protected]",
16+
"role": "Developer"
17+
}
18+
],
19+
"require": {
20+
"php": "^7.2",
21+
"laravel/framework": "~5.8.0"
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^8.0"
25+
},
26+
"autoload": {
27+
"psr-4": {
28+
"Kiroushi\\DbBlade\\": "src/"
29+
},
30+
"files": [
31+
"src/helpers.php"
32+
]
33+
},
34+
"minimum-stability": "stable",
35+
"extra": {
36+
"laravel": {
37+
"providers": [
38+
"Kiroushi\\DbBlade\\DbBladeCompilerServiceProvider"
39+
],
40+
"aliases": {
41+
"DbView": "Kiroushi\\DbBlade\\Facades\\DbView"
42+
}
43+
}
44+
}
45+
}

config/.gitkeep

Whitespace-only changes.

config/db-blade.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
return [
4+
5+
'model_name' => 'Kiroushi\DbBlade\Models\DbView',
6+
'table_name' => 'db_views',
7+
8+
/**
9+
* The default name field used to look up for the model.
10+
* e.g. DbView::make($viewName) or dbview($viewName)
11+
*/
12+
'name_field' => 'name',
13+
14+
/**
15+
* The default model field to be compiled when not explicitly specified
16+
* with DbView::field($fieldName) or DbView::model($modelName, $fieldName)
17+
*/
18+
'content_field' => 'content',
19+
20+
/**
21+
* This property will be added to models being compiled with DbView
22+
* to keep track of which field in the model is being compiled
23+
*/
24+
'model_property' => '__db_blade_compiler_content_field',
25+
26+
'cache' => false,
27+
'cache_path' => 'app/db-blade/cache/views'
28+
29+
];

0 commit comments

Comments
 (0)