Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested theme folders #130

Merged
merged 6 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions features/makepot.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,32 @@ Feature: Generate a POT file of a WordPress project
Extracted 2 strings
"""

Scenario: Detects theme in sub folder
Given an empty foo-themes directory
And an empty foo-themes/theme-a directory
And a foo-themes/theme-a/style.css file:
"""
/*
Theme Name: Theme A
Theme URI: https://example.com
Description:
Author:
Author URI:
Version: 0.1.0
License: GPL-2.0+
Text Domain: foo-theme
Domain Path: /languages
*/
"""

When I try `wp i18n make-pot foo-themes`
Then STDOUT should be:
"""
Theme stylesheet detected.
Success: POT file successfully generated!
"""
And STDERR should be empty

Scenario: Ignore strings that are part of the exception list
Given an empty directory
And a exception.pot file:
Expand Down
60 changes: 35 additions & 25 deletions src/MakePotCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Gettext\Merge;
use Gettext\Translation;
use Gettext\Translations;
use Symfony\Component\Finder\SplFileInfo;
use WP_CLI;
use WP_CLI_Command;
use WP_CLI\Utils;
Expand Down Expand Up @@ -415,44 +416,53 @@ protected function unslashit( $string ) {
* @return array
*/
protected function get_main_file_data() {
$stylesheet = sprintf( '%s/style.css', $this->source );
$files = new IteratorIterator( new DirectoryIterator( $this->source ) );

if ( is_file( $stylesheet ) && is_readable( $stylesheet ) ) {
$theme_data = static::get_file_data( $stylesheet, array_combine( $this->get_file_headers( 'theme' ), $this->get_file_headers( 'theme' ) ) );
/** @var DirectoryIterator $file */
foreach ( $files as $file ) {
// wp-content/themes/my-theme/style.css
if ( $file->isFile() && 'style' === $file->getBasename( '.css' ) && $file->isReadable() ) {
$theme_data = static::get_file_data( $file->getRealPath(), array_combine( $this->get_file_headers( 'theme' ), $this->get_file_headers( 'theme' ) ) );

// Stop when it contains a valid Theme Name header.
if ( ! empty( $theme_data['Theme Name'] ) ) {
WP_CLI::log( 'Theme stylesheet detected.' );
WP_CLI::debug( sprintf( 'Theme stylesheet: %s', $stylesheet ), 'make-pot' );
// Stop when it contains a valid Theme Name header.
if ( ! empty( $theme_data['Theme Name'] ) ) {
WP_CLI::log( 'Theme stylesheet detected.' );
WP_CLI::debug( sprintf( 'Theme stylesheet: %s', $file->getRealPath() ), 'make-pot' );

$this->project_type = 'theme';
$this->project_type = 'theme';

return $theme_data;
return $theme_data;
}
}
}

$plugin_files = [];
// wp-content/themes/my-themes/theme-a/style.css
if ( $file->isDir() && ! $file->isDot() && is_readable( $file->getRealPath() . '/style.css' ) ) {
$theme_data = static::get_file_data( $file->getRealPath() . '/style.css', array_combine( $this->get_file_headers( 'theme' ), $this->get_file_headers( 'theme' ) ) );

$files = new IteratorIterator( new DirectoryIterator( $this->source ) );
// Stop when it contains a valid Theme Name header.
if ( ! empty( $theme_data['Theme Name'] ) ) {
WP_CLI::log( 'Theme stylesheet detected.' );
WP_CLI::debug( sprintf( 'Theme stylesheet: %s', $file->getRealPath() . '/style.css' ), 'make-pot' );

/** @var DirectoryIterator $file */
foreach ( $files as $file ) {
if ( $file->isFile() && $file->isReadable() && 'php' === $file->getExtension() ) {
$plugin_files[] = $file->getRealPath();
$this->project_type = 'theme';

return $theme_data;
}
}
}

foreach ( $plugin_files as $plugin_file ) {
$plugin_data = static::get_file_data( $plugin_file, array_combine( $this->get_file_headers( 'plugin' ), $this->get_file_headers( 'plugin' ) ) );
// wp-content/plugins/my-plugin/my-plugin.php
if ( $file->isFile() && $file->isReadable() && 'php' === $file->getExtension() ) {
$plugin_data = static::get_file_data( $file->getRealPath(), array_combine( $this->get_file_headers( 'plugin' ), $this->get_file_headers( 'plugin' ) ) );

// Stop when we find a file with a valid Plugin Name header.
if ( ! empty( $plugin_data['Plugin Name'] ) ) {
WP_CLI::log( 'Plugin file detected.' );
WP_CLI::debug( sprintf( 'Plugin file: %s', $plugin_file ), 'make-pot' );
// Stop when we find a file with a valid Plugin Name header.
if ( ! empty( $plugin_data['Plugin Name'] ) ) {
WP_CLI::log( 'Plugin file detected.' );
WP_CLI::debug( sprintf( 'Plugin file: %s', $file->getRealPath() ), 'make-pot' );

$this->project_type = 'plugin';
$this->project_type = 'plugin';

return $plugin_data;
return $plugin_data;
}
}
}

Expand Down