Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
Add option to change icon function names
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Walbø Johnsgård committed Sep 19, 2018
1 parent eab996d commit 2df1b40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/heisenberg-scripts/assets/icons/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
}
}

if ( ! function_exists( '{{name}}_the_icon' ) ) {
if ( ! function_exists( '{{name}}_{{theName}}' ) ) {
/**
* Prints SVG Icon
*
* @param string $icon Icon id.
* @param array $args Arguments.
*/
function {{name}}_the_icon( string $icon, array $args = [] ) {
echo {{name}}_get_icon( $icon, $args ); // WPCS: XSS OK.
function {{name}}_{{theName}}( string $icon, array $args = [] ) {
echo {{name}}_{{getName}}( $icon, $args ); // WPCS: XSS OK.
}
}
4 changes: 2 additions & 2 deletions packages/heisenberg-scripts/assets/icons/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

declare( strict_types=1 );

if ( ! function_exists( '{{name}}_get_icon' ) ) {
if ( ! function_exists( '{{name}}_{{getName}}' ) ) {
/**
* Get SVG Icon
*
* @param string $icon Icon id.
* @param array $args Arguments.
* @return string <svg /> markup.
*/
function {{name}}_get_icon( string $icon, array $args = [] ) : string {
function {{name}}_{{getName}}( string $icon, array $args = [] ) : string {
$defaults = [
'classname' => '',
'height' => '',
Expand Down
8 changes: 7 additions & 1 deletion packages/heisenberg-scripts/scripts/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function build( customConfig ) {
name: 'heisenberg',
src: 'src/icons',
dest: 'inc/icons.php',
getName: 'get_icon',
theName: 'the_icon',
options: {
plugins: [
{ removeAttrs: {} },
Expand Down Expand Up @@ -71,7 +73,11 @@ function build( customConfig ) {
phpFile += fs.readFileSync( path.resolve( __dirname, '../assets/icons/footer.php' ), 'utf8' );

// Replace with config vars.
phpFile = phpFile.replace( /{{package}}/g, config.package ).replace( /{{name}}/g, config.name );
phpFile = phpFile
.replace( /{{package}}/g, config.package )
.replace( /{{name}}/g, config.name )
.replace( /{{getName}}/g, config.getName )
.replace( /{{theName}}/g, config.theName );

fs.writeFile( paths.resolveApp( config.dest ), phpFile, err => {
if ( err ) {
Expand Down

0 comments on commit 2df1b40

Please sign in to comment.