Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion plugins/underscoresme-generator/underscoresme-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function init() {
function do_replacements( $contents, $filename ) {

// Replace only text files, skip png's and other stuff.
$valid_extensions = array( 'php', 'css', 'scss', 'js', 'txt' );
$valid_extensions = array( 'php', 'css', 'scss', 'js', 'txt', 'dist' );
$valid_extensions_regex = implode( '|', $valid_extensions );
if ( ! preg_match( "/\.({$valid_extensions_regex})$/", $filename ) )
return $contents;
Expand Down Expand Up @@ -243,6 +243,21 @@ function do_replacements( $contents, $filename ) {
// Function names can not contain hyphens.
$slug = str_replace( '-', '_', $this->theme['slug'] );

// Special treatment for phpcs.xml.dist
if ( 'phpcs.xml.dist' == $filename ) {
preg_match_all( '/<property name="([a-z_]+)" type="array" value="_s" ?\/>/', $contents, $matches, PREG_SET_ORDER );

foreach ( $matches as $match ) {
if ( 'text_domain' === $match[1] ) {
$replace = str_replace( '_s', $this->theme['slug'], $match[0] );
} elseif ( 'prefixes' === $match[1] ) {
$replace = str_replace( '_s', $slug, $match[0] );
}

$contents = str_replace( $match[0], $replace, $contents );
}
}

// Regular treatment for all other files.
$contents = str_replace( "@package _s", sprintf( "@package %s", str_replace( ' ', '_', $this->theme['name'] ) ), $contents ); // Package declaration.
$contents = str_replace( "_s-", sprintf( "%s-", $this->theme['slug'] ), $contents ); // Script/style handles.
Expand Down