diff --git a/.editorconfig b/.editorconfig index 0f099897b..8f960391f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,7 +3,7 @@ root = true [*] indent_style = space -indent_size = 2 +indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true diff --git a/.gitignore b/.gitignore index 7ebbd94ab..cfd4ba8f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +*.zip build/ -source/ +woocommerce/ vendor/ +!data/templates/woocommerce/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fcfaeac2..a8d804cea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.1.0] - 2020-08-03 +### Added +- PHPDoc 3.0 RC support. +- New template +### Remove +- APIGen support. + ## [0.0.1] - 2019-06-25 ### Added - Initial version. -[Unreleased]: https://github.com/woocommerce/woocommerce-api-docs/compare/0.0.1...HEAD -[0.0.1]: https://github.com/woocommerce/woocommerce-api-docs/compare/749f431...0.0.1 +[Unreleased]: https://github.com/woocommerce/code-reference-generator/compare/0.1.0...HEAD +[0.1.0]: https://github.com/woocommerce/code-reference-generator/compare/0.0.1...0.1.0 +[0.0.1]: https://github.com/woocommerce/code-reference-generator/compare/749f431...0.0.1 diff --git a/README.md b/README.md index b79e84d7c..ef75eb61d 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,29 @@ -# WooCommerce Class API Docs +# WooCommerce Code Reference Generator -Generate WooCommerce [Class API Docs](https://docs.woocommerce.com/wc-apidocs/index.html). +Generate [WooCommerce Code Reference](https://docs.woocommerce.com/wc-apidocs/index.html). ## Install ```bash -git clone https://github.com/woocommerce/woocommerce-api-docs.git +git clone https://github.com/woocommerce/code-reference-generator.git ``` ## Usage ```bash -cd woocommerce-api-docs -./generate.sh -w +cd code-reference-generator +./generate.sh -s ``` ### Options -| Options | Description | -|-------------------------|-------------------------| -| `-h` or `--help` | Shows help message | -| `-v` or `--version` | Shows generator version | -| `-w` or `--woocommerce` | WooCommerce version | - -## TODO - -- Find an alternative to ApiGen or fork ApiGen to fix support for latest PHP versions. +| Options | Description | +|----------------------------|-----------------------------------------------------------------| +| `-h` or `--help` | Shows help message | +| `-v` or `--version` | Shows generator version | +| `-s` or `--source-version` | Version of the source code to release | +| `-r` or `--github-repo` | GitHub repo with username, default to "woocommerce/woocommerce" | ## Changelog -[See changelog for details](https://github.com/woocommerce/woocommerce-api-docs/blob/master/CHANGELOG.md) +[See changelog for details](https://github.com/woocommerce/code-reference-generator/blob/master/CHANGELOG.md) diff --git a/apigen.neon b/apigen.neon deleted file mode 100644 index 1a0810b04..000000000 --- a/apigen.neon +++ /dev/null @@ -1,22 +0,0 @@ -destination: build/apidocs -templateConfig: apigen/theme-woocommerce/config.neon -extensions: [php] -source: - - source/woocommerce/woocommerce.php - - source/woocommerce/includes -exclude: - - source/woocommerce/includes/libraries/ - - source/woocommerce/includes/api/legacy/ - - source/woocommerce/api/legacy/ - - source/woocommerce/libraries/ -charset: [UTF-8] -main: WC -title: WooCommerce Code Reference -baseUrl: https://docs.woocommerce.com/wc-apidocs/ -templateTheme: default -php: false -sourceCode: true -tree: true -deprecated: true -todo: true -download: false diff --git a/apigen/hook-docs.php b/apigen/hook-docs.php deleted file mode 100644 index 81c82304d..000000000 --- a/apigen/hook-docs.php +++ /dev/null @@ -1,228 +0,0 @@ -' . $hook . ''; - } - - public static function process_hooks() { - self::$files_to_scan = array(); - - self::$files_to_scan['Template Files'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'templates/' ); - self::$files_to_scan['Template Functions'] = array( self::SOURCE_PATH . 'includes/wc-template-functions.php', self::SOURCE_PATH . 'includes/wc-template-hooks.php' ); - self::$files_to_scan['Shortcodes'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shortcodes/' ); - self::$files_to_scan['Widgets'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/widgets/' ); - self::$files_to_scan['Data Stores'] = self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/data-stores' ); - self::$files_to_scan['Core Classes'] = array_merge( - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/abstracts/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/customizer/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/emails/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/export/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/gateways/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/import/' ), - self::get_files( '*.php', GLOB_MARK, self::SOURCE_PATH . 'includes/shipping/' ) - ); - - self::$files_to_scan = array_filter( self::$files_to_scan ); - - $scanned = array(); - - ob_start(); - - $index = array(); - - foreach ( self::$files_to_scan as $heading => $files ) { - $index[] = '' . $heading . ''; - } - - echo '
'; - echo '

Action and Filter Hook Reference

'; - echo '
-

This is simply a list of action and filter hooks found within WooCommerce files. View the source to see supported params and usage.

-

' . implode( ', ', $index ) . '

-
'; - - foreach ( self::$files_to_scan as $heading => $files ) { - self::$custom_hooks_found = array(); - - foreach ( $files as $f ) { - self::$current_file = basename( $f ); - $tokens = token_get_all( file_get_contents( $f ) ); - $token_type = false; - $current_class = ''; - $current_function = ''; - - if ( in_array( self::$current_file, $scanned ) ) { - continue; - } - - $scanned[] = self::$current_file; - - foreach ( $tokens as $index => $token ) { - if ( is_array( $token ) ) { - $trimmed_token_1 = trim( $token[1] ); - if ( T_CLASS == $token[0] ) { - $token_type = 'class'; - } elseif ( T_FUNCTION == $token[0] ) { - $token_type = 'function'; - } elseif ( 'do_action' === $token[1] ) { - $token_type = 'action'; - } elseif ( 'apply_filters' === $token[1] ) { - $token_type = 'filter'; - } elseif ( $token_type && ! empty( $trimmed_token_1 ) ) { - switch ( $token_type ) { - case 'class' : - $current_class = $token[1]; - break; - case 'function' : - $current_function = $token[1]; - break; - case 'filter' : - case 'action' : - $hook = trim( $token[1], "'" ); - $hook = str_replace( '_FUNCTION_', strtoupper( $current_function ), $hook ); - $hook = str_replace( '_CLASS_', strtoupper( $current_class ), $hook ); - $hook = str_replace( '$this', strtoupper( $current_class ), $hook ); - $hook = str_replace( array( '.', '{', '}', '"', "'", ' ', ')', '(' ), '', $hook ); - $loop = 0; - - // Keep adding to hook until we find a comma or colon - while ( 1 ) { - $loop ++; - $prev_hook = is_string( $tokens[ $index + $loop - 1 ] ) ? $tokens[ $index + $loop - 1 ] : $tokens[ $index + $loop - 1 ][1]; - $next_hook = is_string( $tokens[ $index + $loop ] ) ? $tokens[ $index + $loop ] : $tokens[ $index + $loop ][1]; - - if ( in_array( $next_hook, array( '.', '{', '}', '"', "'", ' ', ')', '(' ) ) ) { - continue; - } - - if ( in_array( $next_hook, array( ',', ';' ) ) ) { - break; - } - - $hook_first = substr( $next_hook, 0, 1 ); - $hook_last = substr( $next_hook, -1, 1 ); - - if ( '{' === $hook_first || '}' === $hook_last || '$' === $hook_first || ')' === $hook_last || '>' === substr( $prev_hook, -1, 1 ) ) { - $next_hook = strtoupper( $next_hook ); - } - - $next_hook = str_replace( array( '.', '{', '}', '"', "'", ' ', ')', '(' ), '', $next_hook ); - - $hook .= $next_hook; - } - - if ( isset( self::$custom_hooks_found[ $hook ] ) ) { - self::$custom_hooks_found[ $hook ]['file'][] = self::$current_file; - } else { - self::$custom_hooks_found[ $hook ] = array( - 'line' => $token[2], - 'class' => $current_class, - 'function' => $current_function, - 'file' => array( self::$current_file ), - 'type' => $token_type, - ); - } - break; - } - $token_type = false; - } - } - } - } - - foreach ( self::$custom_hooks_found as $hook => $details ) { - if ( ! strstr( $hook, 'woocommerce' ) && ! strstr( $hook, 'product' ) && ! strstr( $hook, 'wc_' ) ) { - //unset( self::$custom_hooks_found[ $hook ] ); - } - } - - ksort( self::$custom_hooks_found ); - - if ( ! empty( self::$custom_hooks_found ) ) { - echo '

' . $heading . '

'; - - echo ''; - - foreach ( self::$custom_hooks_found as $hook => $details ) { - echo ' - - - - ' . "\n"; - } - - echo '
HookTypeFile(s)
' . self::get_hook_link( $hook, $details ) . '' . $details['type'] . '' . implode( ', ', array_unique( $details['file'] ) ) . '
'; - } - } - - echo '