This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
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 #16 from x-team/develop
0.2
- Loading branch information
Showing
24 changed files
with
2,144 additions
and
527 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/.jshintrc |
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 @@ | ||
bin/.travis.yml |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,4 @@ | ||
service_name: travis-ci | ||
src_dir: . | ||
coverage_clover: build/logs/clover.xml | ||
json_path: build/logs/coveralls-upload.json |
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,20 @@ | ||
{ | ||
"boss": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"eqnull": true, | ||
"expr": true, | ||
"immed": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"trailing": true, | ||
"undef": true, | ||
"unused": true, | ||
|
||
"browser": true, | ||
|
||
"globals": { | ||
"jQuery": false, | ||
"wp": false | ||
} | ||
} |
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,45 @@ | ||
language: | ||
- php | ||
- node_js | ||
|
||
php: | ||
- 5.3 | ||
- 5.4 | ||
|
||
node_js: | ||
- 0.10 | ||
|
||
env: | ||
- WP_VERSION=latest WP_MULTISITE=0 | ||
- WP_VERSION=latest WP_MULTISITE=1 | ||
- WP_VERSION=3.8 WP_MULTISITE=0 | ||
- WP_VERSION=3.8 WP_MULTISITE=1 | ||
|
||
before_script: | ||
- export WP_TESTS_DIR=/tmp/wordpress-tests/ | ||
- export PLUGIN_DIR=$(pwd) | ||
- export PLUGIN_SLUG=$(basename $(pwd) | sed 's/^wp-//') | ||
- export PHPCS_DIR=/tmp/phpcs | ||
- export PHPCS_GITHUB_SRC=squizlabs/PHP_CodeSniffer | ||
- export PHPCS_GIT_TREE=master | ||
- export PHPCS_IGNORE='tests/*,vendor/*' | ||
- export WPCS_DIR=/tmp/wpcs | ||
- export WPCS_GITHUB_SRC=WordPress-Coding-Standards/WordPress-Coding-Standards | ||
- export WPCS_GIT_TREE=master | ||
- export WPCS_STANDARD=$(if [ -e phpcs.ruleset.xml ]; then echo phpcs.ruleset.xml; else echo WordPress-Core; fi) | ||
- if [ -e .ci-env.sh ]; then source .ci-env.sh; fi | ||
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then wget -O /tmp/install-wp-tests.sh https://raw.githubusercontent.com/wp-cli/wp-cli/master/templates/install-wp-tests.sh; bash /tmp/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION; cd /tmp/wordpress/wp-content/plugins; ln -s $PLUGIN_DIR $PLUGIN_SLUG; cd $PLUGIN_DIR; fi | ||
- mkdir -p $PHPCS_DIR && curl -L https://github.com/$PHPCS_GITHUB_SRC/archive/$PHPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $PHPCS_DIR | ||
- mkdir -p $WPCS_DIR && curl -L https://github.com/$WPCS_GITHUB_SRC/archive/$WPCS_GIT_TREE.tar.gz | tar xvz --strip-components=1 -C $WPCS_DIR | ||
- $PHPCS_DIR/scripts/phpcs --config-set installed_paths $WPCS_DIR | ||
- npm install -g jshint | ||
- if [ -e composer.json ]; then wget http://getcomposer.org/composer.phar && php composer.phar install --dev; fi | ||
|
||
script: | ||
- find . -path ./bin -prune -o \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \; | ||
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit $( if [ -e .coveralls.yml ]; then echo --coverage-clover build/logs/clover.xml; fi ); fi | ||
- $PHPCS_DIR/scripts/phpcs --standard=$WPCS_STANDARD $(if [ -n "$PHPCS_IGNORE" ]; then echo --ignore=$PHPCS_IGNORE; fi) $(find . -name '*.php') | ||
- jshint . | ||
|
||
after_script: | ||
- if [ -e .coveralls.yml ]; then php vendor/bin/coveralls; fi |
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,206 @@ | ||
<?php | ||
/** | ||
* Lightweight WordPress readme.txt parser and converter to Markdown | ||
* The WordPress-Plugin-Readme-Parser project is too heavy and has too many dependencies for what we need (we don't need conversion to HTML) | ||
* @link https://github.com/markjaquith/WordPress-Plugin-Readme-Parser Alternative to WordPress-Plugin-Readme-Parser | ||
* @version 1.1.1 | ||
* @author Weston Ruter <weston@x-team.com> (@westonruter) | ||
* @copyright Copyright (c) 2013, X-Team <http://x-team.com/wordpress/> | ||
* @license GPLv2+ | ||
*/ | ||
|
||
class WordPress_Readme_Parser { | ||
public $path; | ||
public $source; | ||
public $title = ''; | ||
public $short_description = ''; | ||
public $metadata = array(); | ||
public $sections = array(); | ||
|
||
function __construct( $args = array() ) { | ||
$args = array_merge( get_object_vars( $this ), $args ); | ||
foreach ( $args as $key => $value ) { | ||
$this->$key = $value; | ||
} | ||
|
||
$this->source = file_get_contents( $this->path ); | ||
if ( ! $this->source ) { | ||
throw new Exception( 'readme.txt was empty or unreadable' ); | ||
} | ||
|
||
// Parse metadata | ||
$syntax_ok = preg_match( '/^=== (.+?) ===\n(.+?)\n\n(.+?)\n(.+)/s', $this->source, $matches ); | ||
if ( ! $syntax_ok ) { | ||
throw new Exception( 'Malformed metadata block' ); | ||
} | ||
$this->title = $matches[1]; | ||
$this->short_description = $matches[3]; | ||
$readme_txt_rest = $matches[4]; | ||
$this->metadata = array_fill_keys( array( 'Contributors', 'Tags', 'Requires at least', 'Tested up to', 'Stable tag', 'License', 'License URI' ), null ); | ||
foreach ( explode( "\n", $matches[2] ) as $metadatum ) { | ||
if ( ! preg_match( '/^(.+?):\s+(.+)$/', $metadatum, $metadataum_matches ) ) { | ||
throw new Exception( "Parse error in $metadatum" ); | ||
} | ||
list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 ); | ||
$this->metadata[ $name ] = $value; | ||
} | ||
$this->metadata['Contributors'] = preg_split( '/\s*,\s*/', $this->metadata['Contributors'] ); | ||
$this->metadata['Tags'] = preg_split( '/\s*,\s*/', $this->metadata['Tags'] ); | ||
|
||
$syntax_ok = preg_match_all( '/(?:^|\n)== (.+?) ==\n(.+?)(?=\n== |$)/s', $readme_txt_rest, $section_matches, PREG_SET_ORDER ); | ||
if ( ! $syntax_ok ) { | ||
throw new Exception( 'Failed to parse sections from readme.txt' ); | ||
} | ||
foreach ( $section_matches as $section_match ) { | ||
array_shift( $section_match ); | ||
|
||
$heading = array_shift( $section_match ); | ||
$body = trim( array_shift( $section_match ) ); | ||
$subsections = array(); | ||
|
||
// @todo Parse out front matter /(.+?)(\n=\s+.+$)/s | ||
|
||
// Parse subsections | ||
if ( preg_match_all( '/(?:^|\n)= (.+?) =\n(.+?)(?=\n= |$)/s', $body, $subsection_matches, PREG_SET_ORDER ) ) { | ||
$body = null; | ||
foreach ( $subsection_matches as $subsection_match ) { | ||
array_shift( $subsection_match ); | ||
$subsections[] = array( | ||
'heading' => array_shift( $subsection_match ), | ||
'body' => trim( array_shift( $subsection_match ) ), | ||
); | ||
} | ||
} | ||
|
||
$this->sections[] = compact( 'heading', 'body', 'subsections' ); | ||
} | ||
} | ||
|
||
/** | ||
* Convert the parsed readme.txt into Markdown | ||
* @param array|string [$params] | ||
* @return string | ||
*/ | ||
function to_markdown( $params = array() ) { | ||
|
||
$general_section_formatter = function ( $body ) use ( $params ) { | ||
$body = preg_replace( | ||
'#\[youtube\s+(?:http://www\.youtube\.com/watch\?v=|http://youtu\.be/)(.+?)\]#', | ||
'[![Play video on YouTube](http://i1.ytimg.com/vi/$1/hqdefault.jpg)](http://www.youtube.com/watch?v=$1)', | ||
$body | ||
); | ||
return $body; | ||
}; | ||
|
||
// Parse sections | ||
$section_formatters = array( | ||
'Description' => function ( $body ) use ( $params ) { | ||
if ( isset( $params['travis_ci_url'] ) ) { | ||
$body .= sprintf( "\n\n[![Build Status](%s.png?branch=master)](%s)", $params['travis_ci_url'], $params['travis_ci_url'] ); | ||
} | ||
if ( isset( $params['coveralls_url'] ) ) { | ||
$body .= sprintf( "\n\n[![Build Status](%s?branch=master)](%s)", $params['coveralls_badge_src'], $params['coveralls_url'] ); | ||
} | ||
return $body; | ||
}, | ||
'Screenshots' => function ( $body ) { | ||
$body = trim( $body ); | ||
$new_body = ''; | ||
if ( ! preg_match_all( '/^\d+\. (.+?)$/m', $body, $screenshot_matches, PREG_SET_ORDER ) ) { | ||
throw new Exception( 'Malformed screenshot section' ); | ||
} | ||
foreach ( $screenshot_matches as $i => $screenshot_match ) { | ||
$img_extensions = array( 'jpg', 'gif', 'png' ); | ||
foreach ( $img_extensions as $ext ) { | ||
$filepath = sprintf( 'assets/screenshot-%d.%s', $i + 1, $ext ); | ||
if ( file_exists( dirname( $this->path ) . DIRECTORY_SEPARATOR . $filepath ) ) { | ||
break; | ||
} | ||
else { | ||
$filepath = null; | ||
} | ||
} | ||
if ( empty( $filepath ) ) { | ||
continue; | ||
} | ||
|
||
$screenshot_name = $screenshot_match[1]; | ||
$new_body .= sprintf( "### %s\n", $screenshot_name ); | ||
$new_body .= "\n"; | ||
$new_body .= sprintf( "![%s](%s)\n", $screenshot_name, $filepath ); | ||
$new_body .= "\n"; | ||
} | ||
return $new_body; | ||
}, | ||
); | ||
|
||
// Format metadata | ||
$formatted_metadata = $this->metadata; | ||
$formatted_metadata['Contributors'] = join( | ||
', ', | ||
array_map( | ||
function ( $contributor ) { | ||
$contributor = strtolower( $contributor ); | ||
// @todo Map to GitHub account | ||
return sprintf( '[%1$s](http://profiles.wordpress.org/%1$s)', $contributor ); | ||
}, | ||
$this->metadata['Contributors'] | ||
) | ||
); | ||
$formatted_metadata['Tags'] = join( | ||
', ', | ||
array_map( | ||
function ( $tag ) { | ||
return sprintf( '[%1$s](http://wordpress.org/plugins/tags/%1$s)', $tag ); | ||
}, | ||
$this->metadata['Tags'] | ||
) | ||
); | ||
$formatted_metadata['License'] = sprintf( '[%s](%s)', $formatted_metadata['License'], $formatted_metadata['License URI'] ); | ||
unset( $formatted_metadata['License URI'] ); | ||
if ( $this->metadata['Stable tag'] === 'trunk' ) { | ||
$formatted_metadata['Stable tag'] .= ' (master)'; | ||
} | ||
|
||
// Render metadata | ||
$markdown = "<!-- DO NOT EDIT THIS FILE; it is auto-generated from readme.txt -->\n"; | ||
$markdown .= sprintf( "# %s\n", $this->title ); | ||
$markdown .= "\n"; | ||
if ( file_exists( 'assets/banner-1544x500.png' ) ) { | ||
$markdown .= '![Banner](assets/banner-1544x500.png)'; | ||
$markdown .= "\n"; | ||
} | ||
$markdown .= sprintf( "%s\n", $this->short_description ); | ||
$markdown .= "\n"; | ||
foreach ( $formatted_metadata as $name => $value ) { | ||
$markdown .= sprintf( "**%s:** %s \n", $name, $value ); | ||
} | ||
$markdown .= "\n"; | ||
|
||
foreach ( $this->sections as $section ) { | ||
$markdown .= sprintf( "## %s ##\n", $section['heading'] ); | ||
$markdown .= "\n"; | ||
|
||
$body = $section['body']; | ||
|
||
$body = call_user_func( $general_section_formatter, $body ); | ||
if ( isset( $section_formatters[ $section['heading'] ] ) ) { | ||
$body = trim( call_user_func( $section_formatters[ $section['heading'] ], $body ) ); | ||
} | ||
|
||
if ( $body ) { | ||
$markdown .= sprintf( "%s\n", $body ); | ||
} | ||
foreach ( $section['subsections'] as $subsection ) { | ||
$markdown .= sprintf( "### %s ###\n", $subsection['heading'] ); | ||
$markdown .= sprintf( "%s\n", $subsection['body'] ); | ||
$markdown .= "\n"; | ||
} | ||
|
||
$markdown .= "\n"; | ||
} | ||
|
||
return $markdown; | ||
} | ||
|
||
} |
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,3 @@ | ||
Pull requests should be opened with the `develop` branch as the base. Do not | ||
open pull requests into the `master` branch, as this branch contains the latest | ||
stable release. |
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,63 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/** | ||
* Look for WordPress readme in current directory or above and convert into markdown readme in same directory | ||
* @version 1.0.1 | ||
* @author Weston Ruter <weston@x-team.com> (@westonruter) | ||
* @copyright Copyright (c) 2013, X-Team <http://x-team.com/wordpress/> | ||
* @license GPLv2+ | ||
*/ | ||
|
||
try { | ||
if ( php_sapi_name() !== 'cli' ) { | ||
throw new Exception( 'Only allowed in CLI mode.' ); | ||
} | ||
|
||
$readme_txt_path = null; | ||
while ( true ) { | ||
foreach ( array( 'readme.txt', 'README.txt' ) as $readme_filename ) { | ||
if ( file_exists( $readme_filename ) ) { | ||
$readme_txt_path = realpath( $readme_filename ); | ||
break; | ||
} | ||
} | ||
|
||
$old_cwd = getcwd(); | ||
if ( ! empty( $readme_txt_path ) || ! chdir( '..' ) || getcwd() === $old_cwd ) { | ||
break; | ||
} | ||
} | ||
if ( empty( $readme_txt_path ) ) { | ||
throw new Exception( 'Failed to find a readme.txt or README.txt above the current working directory.' ); | ||
} | ||
|
||
$readme_root = dirname( $readme_txt_path ); | ||
$readme_md_path = preg_replace( '/txt$/', 'md', $readme_txt_path ); | ||
|
||
require_once __DIR__ . '/class-wordpress-readme-parser.php'; | ||
|
||
$readme = new WordPress_Readme_Parser( array( 'path' => $readme_txt_path ) ); | ||
|
||
$md_args = array(); | ||
$github_url_regex = '#.+github\.com[:/]([^/]+/[^/]+)\.git$#'; | ||
$origin_url = trim( `git config --get remote.origin.url` ); | ||
if ( file_exists( $readme_root . '/.travis.yml' ) ) { | ||
$md_args['travis_ci_url'] = preg_replace( $github_url_regex, 'https://travis-ci.org/$1', $origin_url ); | ||
} | ||
if ( file_exists( $readme_root . '/.coveralls.yml' ) ) { | ||
$md_args['coveralls_badge_src'] = preg_replace( $github_url_regex, 'https://coveralls.io/repos/$1/badge.png', $origin_url ); | ||
$md_args['coveralls_url'] = preg_replace( $github_url_regex, 'https://coveralls.io/r/$1', $origin_url ); | ||
} | ||
$markdown = $readme->to_markdown( $md_args ); | ||
|
||
$is_written = file_put_contents( $readme_md_path, $markdown ); | ||
if ( ! $is_written ) { | ||
throw new Exception( sprintf( 'Failed to write to %s', $readme_md_path ) ); | ||
} | ||
fwrite( STDERR, 'Successfully converted WordPress README to Markdown' . PHP_EOL ); | ||
fwrite( STDOUT, $readme_md_path . PHP_EOL ); | ||
} | ||
catch( Exception $e ) { | ||
fwrite( STDERR, $e->getMessage() . PHP_EOL ); | ||
exit( 1 ); | ||
} |
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,9 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="WordPress Coding Standards for Plugins"> | ||
<description>Generally-applicable sniffs for WordPress plugins</description> | ||
|
||
<rule ref="WordPress-Extra" /> | ||
|
||
<exclude-pattern>/tests/*,/vendor/*</exclude-pattern> | ||
|
||
</ruleset> |
Oops, something went wrong.