-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from mindkomm/feat-timber-2
- Loading branch information
Showing
7 changed files
with
152 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.DS_Store | ||
composer.lock | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
require_once 'lib/functions.php'; | ||
|
||
/** | ||
* Require functionality in filter only if WordPress is loaded. | ||
*/ | ||
if ( function_exists( 'add_filter' ) ) { | ||
require_once 'lib/twig.php'; | ||
if (function_exists('add_filter')) { | ||
require_once 'lib/twig.php'; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,56 @@ | ||
{ | ||
"name": "mindkomm/theme-lib-links", | ||
"type": "library", | ||
"description": "Collection of link helper functions for WordPress themes", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=7.0.0" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"autoload.php" | ||
] | ||
}, | ||
"type": "library", | ||
"authors": [ | ||
{ | ||
"name": "Lukas Gaechter", | ||
"email": "[email protected]", | ||
"homepage": "https://www.mind.ch" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": ">=7.0.0" | ||
}, | ||
"require-dev": { | ||
"mindkomm/qa": "^0.4.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"autoload": { | ||
"files": [ | ||
"autoload.php" | ||
] | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"phpro/grumphp-shim": true, | ||
"dealerdirect/phpcodesniffer-composer-installer": true, | ||
"phpstan/extension-installer": true, | ||
"ergebnis/composer-normalize": true | ||
} | ||
}, | ||
"extra": { | ||
"grumphp": { | ||
"config-default-path": "vendor/mindkomm/qa/config/grumphp.yml" | ||
} | ||
}, | ||
"scripts": { | ||
"analyse": [ | ||
"phpstan analyse --memory-limit=1G" | ||
], | ||
"cs": "phpcs --colors", | ||
"cs:fix": "phpcbf --filter=GitModified", | ||
"grump": [ | ||
"grumphp git:pre-commit" | ||
], | ||
"lint-composer": "@composer normalize --dry-run", | ||
"lint-composer:fix": "@composer normalize", | ||
"qa": [ | ||
"@lint-composer", | ||
"@cs", | ||
"@analyse" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
<?php | ||
|
||
use Timber\Twig_Function as Timber_Twig_Function; | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Customize Twig | ||
* | ||
* @param Twig_Environment $twig | ||
* @return $twig | ||
* Add Twig functions. | ||
*/ | ||
add_filter( 'timber/twig', function( Twig_Environment $twig ) { | ||
/** | ||
* Checks if a URL is external or internal. | ||
* | ||
* Usage: | ||
* {% if is_external_url(partner.url) %} | ||
* {# Do something special #} | ||
* {% endif %} | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @see is_external_url() | ||
*/ | ||
$twig->addFunction( new Timber_Twig_Function( 'is_external_url', 'is_external_url' ) ); | ||
|
||
/** | ||
* Get href attribute for an <a> tag with proper target and rel attributes. | ||
* | ||
* Usage: | ||
* <a {{ get_link_attributes( post.link ) }}>Your link text</a> | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @see get_link_attributes() | ||
*/ | ||
$twig->addFunction( new Timber_Twig_Function( 'get_link_attributes', 'get_link_attributes' ) ); | ||
add_filter('timber/twig/functions', static function (array $functions): array { | ||
/** | ||
* Checks if a URL is external or internal. | ||
* | ||
* Usage: | ||
* {% if is_external_url(partner.url) %} | ||
* {# Do something special #} | ||
* {% endif %} | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @see is_external_url() | ||
*/ | ||
$functions['is_external_url'] = [ | ||
'callable' => 'is_external_url', | ||
]; | ||
|
||
/** | ||
* Convert a URL to just the domain name together with the TLD. | ||
* | ||
* Usage: | ||
* <a href={{ url }}>{{ url_to_domain(url) }}</a> | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @see url_to_domain() | ||
*/ | ||
$twig->addFunction( new Timber_Twig_Function( 'url_to_domain', 'url_to_domain' ) ); | ||
/** | ||
* Get href attribute for an <a> tag with proper target and rel attributes. | ||
* | ||
* Usage: | ||
* <a {{ get_link_attributes( post.link ) }}>Your link text</a> | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @see get_link_attributes() | ||
*/ | ||
$functions['get_link_attributes'] = [ | ||
'callable' => 'get_link_attributes', | ||
]; | ||
|
||
return $twig; | ||
/** | ||
* Convert a URL to just the domain name together with the TLD. | ||
* | ||
* Usage: | ||
* <a href={{ url }}>{{ url_to_domain(url) }}</a> | ||
* | ||
* @since 1.0.0 | ||
* | ||
* @see url_to_domain() | ||
*/ | ||
$functions['url_to_domain'] = [ | ||
'callable' => 'url_to_domain', | ||
]; | ||
|
||
return $functions; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<ruleset> | ||
<rule ref="MIND"></rule> | ||
<file>.</file> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
includes: | ||
- vendor/mindkomm/qa/phpstan.neon.dist | ||
parameters: | ||
level: 5 | ||
paths: | ||
- lib | ||
- autoload.php |