mirror of
https://github.com/flextype/flextype.git
synced 2025-08-07 13:46:42 +02:00
feat(icon-plugin): add Icon Plugin for Font Awesome icons collection #371
This commit is contained in:
21
site/plugins/icon/LICENSE.txt
Executable file
21
site/plugins/icon/LICENSE.txt
Executable file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018-2020 Sergey Romanenko
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
8
site/plugins/icon/README.md
Executable file
8
site/plugins/icon/README.md
Executable file
@@ -0,0 +1,8 @@
|
||||
# Icon Plugin for [Flextype](http://flextype.org/)
|
||||

|
||||
|
||||
Icon Plugin for Flextype.
|
||||
|
||||
## LICENSE
|
||||
[The MIT License (MIT)](https://github.com/flextype/flextype/blob/master/LICENSE.txt)
|
||||
Copyright (c) 2018-2020 [Sergey Romanenko](https://github.com/Awilum)
|
36
site/plugins/icon/app/Controllers/IconController.php
Normal file
36
site/plugins/icon/app/Controllers/IconController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @link http://digital.flextype.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Flextype\Component\Filesystem\Filesystem;
|
||||
|
||||
class IconController extends Controller
|
||||
{
|
||||
public static function icon($value)
|
||||
{
|
||||
$icon_parts = explode(" ", $value);
|
||||
|
||||
if ($icon_parts[0] == 'fas') {
|
||||
$icon_category = 'solid';
|
||||
} elseif ($icon_parts[0] == 'fab') {
|
||||
$icon_category = 'brands';
|
||||
} elseif ($icon_parts[0] == 'far') {
|
||||
$icon_category = 'regular';
|
||||
}
|
||||
|
||||
$icon_name = str_replace("fa-", "", $icon_parts[1]);
|
||||
|
||||
$icon = Filesystem::read(PATH['plugins'] . '/icon/assets/dist/fontawesome/svgs/' . $icon_category . '/' . $icon_name . '.svg');
|
||||
|
||||
return $icon;
|
||||
}
|
||||
}
|
40
site/plugins/icon/bootstrap.php
Normal file
40
site/plugins/icon/bootstrap.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @link http://digital.flextype.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use function is_file;
|
||||
|
||||
/**
|
||||
* Ensure vendor libraries exist
|
||||
*/
|
||||
! is_file($form_autoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: <i>composer install</i> for icon plugin');
|
||||
|
||||
/**
|
||||
* Register The Auto Loader
|
||||
*
|
||||
* Composer provides a convenient, automatically generated class loader for
|
||||
* our application. We just need to utilize it! We'll simply require it
|
||||
* into the script here so that we don't have to worry about manual
|
||||
* loading any of our classes later on. It feels nice to relax.
|
||||
* Register The Auto Loader
|
||||
*/
|
||||
$form_loader = require_once $form_autoload;
|
||||
|
||||
/**
|
||||
* Include dependencies
|
||||
*/
|
||||
include_once 'shortcodes/IconShortcodeExtension.php';
|
||||
|
||||
/**
|
||||
* Include dependencies
|
||||
*/
|
||||
include_once 'dependencies.php';
|
34
site/plugins/icon/composer.json
Normal file
34
site/plugins/icon/composer.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "flextype-plugins/icon",
|
||||
"type": "project",
|
||||
"description": "Icon plugin for Flextype",
|
||||
"keywords": ["icon", "plugin", "flextype", "php", "html"],
|
||||
"homepage": "https://github.com/flextype",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sergey Romanenko",
|
||||
"email": "hello@romanenko.digital",
|
||||
"homepage": "http://digital.flextype.org"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/flextype/issues"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2.0"
|
||||
},
|
||||
"config": {
|
||||
"apcu-autoloader": true,
|
||||
"optimize-autoloader": true,
|
||||
"platform": {
|
||||
"php": "7.2.0"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"app",
|
||||
"twig"
|
||||
]
|
||||
}
|
||||
}
|
15
site/plugins/icon/dependencies.php
Normal file
15
site/plugins/icon/dependencies.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @link http://digital.flextype.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
// Add Icon Twig Extension
|
||||
$flextype->view->addExtension(new IconTwigExtension($flextype));
|
16
site/plugins/icon/gulpfile.js
Executable file
16
site/plugins/icon/gulpfile.js
Executable file
@@ -0,0 +1,16 @@
|
||||
const gulp = require('gulp');
|
||||
|
||||
/**
|
||||
* Task: gulp fontawesome-icons
|
||||
*/
|
||||
gulp.task('fontawesome-icons', function(){
|
||||
return gulp.src(['node_modules/@fortawesome/fontawesome-free/svgs/**/*'])
|
||||
.pipe(gulp.dest('assets/dist/fontawesome/svgs'));
|
||||
});
|
||||
|
||||
/**
|
||||
* Task: gulp default
|
||||
*/
|
||||
gulp.task('default', gulp.series(
|
||||
'fontawesome-icons'
|
||||
));
|
2
site/plugins/icon/lang/en_US.yaml
Executable file
2
site/plugins/icon/lang/en_US.yaml
Executable file
@@ -0,0 +1,2 @@
|
||||
icon: "Icon"
|
||||
icon_description: "Icon plugin for Flextype"
|
2
site/plugins/icon/lang/ru_RU.yaml
Executable file
2
site/plugins/icon/lang/ru_RU.yaml
Executable file
@@ -0,0 +1,2 @@
|
||||
icon: "Icon"
|
||||
icon_description: "Icon plugin for Flextype"
|
23
site/plugins/icon/package.json
Normal file
23
site/plugins/icon/package.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "Icon",
|
||||
"version": "0.9.7",
|
||||
"description": "Icon plugin for Flextype",
|
||||
"homepage": "http://flextype.org",
|
||||
"author": "Sergey Romanenko",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"flextype",
|
||||
"cms",
|
||||
"flat cms",
|
||||
"flatfile cms",
|
||||
"css",
|
||||
"html"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/flextype/flextype/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "5.12.1",
|
||||
"gulp": "4.0.2"
|
||||
}
|
||||
}
|
11
site/plugins/icon/plugin.yaml
Executable file
11
site/plugins/icon/plugin.yaml
Executable file
@@ -0,0 +1,11 @@
|
||||
name: Icon
|
||||
version: 0.9.7
|
||||
description: Icon plugin for Flextype
|
||||
icon: fas fa-check-circle
|
||||
author:
|
||||
name: Sergey Romanenko
|
||||
email: hello@romanenko.digital
|
||||
url: http://flextype.org
|
||||
homepage: https://github.com/flextype
|
||||
bugs: https://github.com/flextype/issues
|
||||
license: MIT
|
1
site/plugins/icon/settings.yaml
Normal file
1
site/plugins/icon/settings.yaml
Normal file
@@ -0,0 +1 @@
|
||||
enabled: true
|
17
site/plugins/icon/shortcodes/IconShortcodeExtension.php
Normal file
17
site/plugins/icon/shortcodes/IconShortcodeExtension.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (http://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
|
||||
|
||||
// Shortcode: [icon value="fab fa-apple"]
|
||||
$flextype['shortcodes']->addHandler('icon', static function (ShortcodeInterface $s) {
|
||||
return IconController::icon($s->getParameter('value'));
|
||||
});
|
36
site/plugins/icon/twig/IconTwigExtension.php
Normal file
36
site/plugins/icon/twig/IconTwigExtension.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (http://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
class IconTwigExtension extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Callback for twig.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFunctions() : array
|
||||
{
|
||||
return [
|
||||
new Twig_SimpleFunction('icon', [$this, 'icon'], ['is_safe' => ['html']])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Icon
|
||||
*/
|
||||
public function icon(string $value) : string
|
||||
{
|
||||
return IconController::icon($value);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user