Skip to content

Commit 53b3396

Browse files
committed
Squashed 'bin/' changes from 5614813..cc5a003
cc5a003 Reference master branch in TravisCI build badge 2e82c85 Merge commit '85f0b269038cb772d9353f7236a28757c10295af' 234a146 Merge pull request #25 from GaryJones/patch-1 5c6fae7 Remove smarttabs option from .jshintrc 9fcac99 Add Generic.ControlStructures.InlineControlStructure 218f007 Merge commit '6a9b2c7f6a8044f337152fb406ebe58f1c26b5ac' into develop 894d120 Merge pull request #18 from x-team/issue-16 de1db88 Remove wordpress- from url 5581e97 Get latest trunk file from github 256b0a0 Embed YouTube demo video in readme; add markdown support 9d1d025 Add base phpcs ruleset for plugins 5de1b8e Update .jshintrc to match new in core ab7b9cd Update .tavis.yml to check against master and latest. This closes #16 and #15 9aa3e33 Merge pull request #17 from jonathanbardo/master 63a11a4 Correct small typo 8e3bab1 Merge pull request #15 from jonathanbardo/master ed0b379 Update WP version to latest stable release 6956ba1 Merge pull request #13 from jonathanbardo/master a864385 Update WP_VERSION to 3.7 0c545c3 Merge commit '4cd538fd0b8e6fcbe68cd4e4a8e39206103023b2' into develop 4cd538f Merge branch 'master' of github.com:x-team/wp-plugin-dev-lib 258cdf9 Fix reference from jshint to phpcs c9f45eb Add formatting 7d26511 Add git-subtree instructions 528bd0e Only apply jshint to staged JS files 9c1e6ea Update svn-push to work with svn repo out of git repo 86d46a9 Explicitly reference bash (not dash) for pre-commit hook 64a6d09 Move WordPress.org SVN checkout outside of Git root a4aa443 Fix symlinked dirs for Travis; remove PHP 5.2 for Travis fd97d04 Finish with 5.2 compat; exclude bin from syntax check ff49315 Improve relative paths for phpunit; update install-wp-tests.sh c213c44 Run Travis tests on PHP 5.2 4eaa28e Account for renamed files in pre-commit hook 8001c36 Eliminate PHP 5.3 requirement, replacing namespaces and closures 774bdc3 Check modified files, pass select JS to jshint, run phpunit in vagrant bc955c7 Fix pre-commit detection of staged_php_files d0194bb Add PHP syntax checks for travis-ci and pre-commit hook c98d9c4 Merge branch 'master' of github.com:x-team/wp-plugin-dev-lib 2e1b928 Remove dependency on WP_CLI 0e07a75 Note how add .travis.yml and .jshintrc to host plugin via symlinks da3555c Also check for presence of phpunit.xml.dist 0ae29af Update pre-commit hook so PHPCS only looks at staged PHP files 00d36fb Merge commit '7ef48bd5aa6680d02589a9f5697b35cd9a9520ca' into develop f5f2c1c Update pre-commit hook to look for staged php files 3ddac64 Revamp pre-commit hook, adding jshint 9f7df05 Rename .jshint => .jshintrc 817f4c2 Add travis-ci with support for jshint, phpcs, phpunit a3a984d Add jshint and fix warnings 730cf4f Merge commit '32585ea10effb3de33aa7136424364359c199969' 1095520 Apply phpcs fixes git-subtree-dir: bin git-subtree-split: cc5a003aca81eb3af6c01f556446168e3e71263d
1 parent dbbb15a commit 53b3396

8 files changed

Lines changed: 288 additions & 64 deletions

File tree

.jshintrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"boss": true,
3+
"curly": true,
4+
"eqeqeq": true,
5+
"eqnull": true,
6+
"expr": true,
7+
"immed": true,
8+
"noarg": true,
9+
"quotmark": "single",
10+
"trailing": true,
11+
"undef": true,
12+
"unused": true,
13+
14+
"browser": true,
15+
16+
"globals": {
17+
"jQuery": false,
18+
"wp": false
19+
}
20+
}

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
language:
2+
- php
3+
- node_js
4+
5+
php:
6+
- 5.3
7+
- 5.4
8+
9+
node_js:
10+
- 0.10
11+
12+
env:
13+
- WP_VERSION=master WP_MULTISITE=0
14+
- WP_VERSION=master WP_MULTISITE=1
15+
- WP_VERSION=latest WP_MULTISITE=0
16+
- WP_VERSION=latest WP_MULTISITE=1
17+
18+
before_script:
19+
- export WP_TESTS_DIR=/tmp/wordpress-tests/
20+
- export PLUGIN_DIR=$(pwd)
21+
- export PLUGIN_SLUG=$(basename $(pwd) | sed 's/^wp-//')
22+
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then bash bin/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
23+
- pear config-set auto_discover 1
24+
- pear install PHP_CodeSniffer
25+
- git clone git://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $(pear config-get php_dir)/PHP/CodeSniffer/Standards/WordPress
26+
- phpenv rehash
27+
- npm install -g jshint
28+
29+
script:
30+
- find . -path ./bin -prune -o \( -name '*.php' -o -name '*.inc' \) -exec php -lf {} \;
31+
- if [ -e phpunit.xml ] || [ -e phpunit.xml.dist ]; then phpunit; fi
32+
- phpcs --standard=$(if [ -e ruleset.xml ]; then echo ruleset.xml; else echo WordPress; fi) $(find . -name '*.php')
33+
- jshint .

class-wordpress-readme-parser.php

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,43 @@ class WordPress_Readme_Parser {
1919

2020
function __construct( $args = array() ) {
2121
$args = array_merge( get_object_vars( $this ), $args );
22-
foreach ($args as $key => $value) {
22+
foreach ( $args as $key => $value ) {
2323
$this->$key = $value;
2424
}
2525

2626
$this->source = file_get_contents( $this->path );
2727
if ( ! $this->source ) {
28-
throw new \Exception( 'readme.txt was empty or unreadable' );
28+
throw new Exception( 'readme.txt was empty or unreadable' );
2929
}
3030

3131
// Parse metadata
3232
$syntax_ok = preg_match( '/^=== (.+?) ===\n(.+?)\n\n(.+?)\n(.+)/s', $this->source, $matches );
3333
if ( ! $syntax_ok ) {
34-
throw new \Exception( 'Malformed metadata block' );
34+
throw new Exception( 'Malformed metadata block' );
3535
}
3636
$this->title = $matches[1];
3737
$this->short_description = $matches[3];
3838
$readme_txt_rest = $matches[4];
3939
$this->metadata = array_fill_keys( array( 'Contributors', 'Tags', 'Requires at least', 'Tested up to', 'Stable tag', 'License', 'License URI' ), null );
40-
foreach( explode( "\n", $matches[2] ) as $metadatum ) {
41-
preg_match( '/^(.+?):\s+(.+)$/', $metadatum, $metadataum_matches ) || \WP_CLI::error( "Parse error in $metadatum" );
42-
list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 );
40+
foreach ( explode( "\n", $matches[2] ) as $metadatum ) {
41+
if ( ! preg_match( '/^(.+?):\s+(.+)$/', $metadatum, $metadataum_matches ) ) {
42+
throw new Exception( "Parse error in $metadatum" );
43+
}
44+
list( $name, $value ) = array_slice( $metadataum_matches, 1, 2 );
4345
$this->metadata[$name] = $value;
4446
}
4547
$this->metadata['Contributors'] = preg_split( '/\s*,\s*/', $this->metadata['Contributors'] );
4648
$this->metadata['Tags'] = preg_split( '/\s*,\s*/', $this->metadata['Tags'] );
4749

4850
$syntax_ok = preg_match_all( '/(?:^|\n)== (.+?) ==\n(.+?)(?=\n== |$)/s', $readme_txt_rest, $section_matches, PREG_SET_ORDER );
4951
if ( ! $syntax_ok ) {
50-
throw new \Exception( 'Failed to parse sections from readme.txt' );
52+
throw new Exception( 'Failed to parse sections from readme.txt' );
5153
}
5254
foreach ( $section_matches as $section_match ) {
5355
array_shift( $section_match );
5456

55-
$heading = array_shift( $section_match );
56-
$body = trim( array_shift( $section_match ) );
57+
$heading = array_shift( $section_match );
58+
$body = trim( array_shift( $section_match ) );
5759
$subsections = array();
5860

5961
// @todo Parse out front matter /(.+?)(\n=\s+.+$)/s
@@ -76,25 +78,37 @@ function __construct( $args = array() ) {
7678

7779
/**
7880
* Convert the parsed readme.txt into Markdown
81+
* @param array|string [$params]
7982
* @return string
8083
*/
8184
function to_markdown( $params = array() ) {
8285

86+
$general_section_formatter = function ( $body ) use ( $params ) {
87+
$body = preg_replace(
88+
'#\[youtube\s+(?:http://www\.youtube\.com/watch\?v=|http://youtu\.be/)(.+?)\]#',
89+
'[![Play video on YouTube](http://i1.ytimg.com/vi/$1/hqdefault.jpg)](http://www.youtube.com/watch?v=$1)',
90+
$body
91+
);
92+
return $body;
93+
};
94+
8395
// Parse sections
8496
$section_formatters = array(
8597
'Description' => function ( $body ) use ( $params ) {
8698
if ( isset( $params['travis_ci_url'] ) ) {
87-
$body .= sprintf( "\n\n[![Build Status](%s.png)](%s)", $params['travis_ci_url'], $params['travis_ci_url'] );
99+
$body .= sprintf( "\n\n[![Build Status](%s.png?branch=master)](%s)", $params['travis_ci_url'], $params['travis_ci_url'] );
88100
}
89101
return $body;
90102
},
91103
'Screenshots' => function ( $body ) {
92104
$body = trim( $body );
93105
$new_body = '';
94-
$screenshots = array();
95-
preg_match_all( '/^\d+\. (.+?)$/m', $body, $screenshot_matches, PREG_SET_ORDER ) || \WP_CLI::error( 'Malformed screenshot section' );
106+
if ( ! preg_match_all( '/^\d+\. (.+?)$/m', $body, $screenshot_matches, PREG_SET_ORDER ) ) {
107+
throw new Exception( 'Malformed screenshot section' );
108+
}
96109
foreach ( $screenshot_matches as $i => $screenshot_match ) {
97-
foreach ( array( 'jpg', 'gif', 'png' ) as $ext ) {
110+
$img_extensions = array( 'jpg', 'gif', 'png' );
111+
foreach ( $img_extensions as $ext ) {
98112
$filepath = sprintf( 'assets/screenshot-%d.%s', $i + 1, $ext );
99113
if ( file_exists( dirname( $this->path ) . DIRECTORY_SEPARATOR . $filepath ) ) {
100114
break;
@@ -119,28 +133,34 @@ function to_markdown( $params = array() ) {
119133

120134
// Format metadata
121135
$formatted_metadata = $this->metadata;
122-
$formatted_metadata['Contributors'] = join(', ', array_map(
123-
function ( $contributor ) {
124-
$contributor = strtolower( $contributor );
125-
// @todo Map to GitHub account
126-
return sprintf( '[%1$s](http://profiles.wordpress.org/%1$s)', $contributor );
127-
},
128-
$this->metadata['Contributors']
129-
));
130-
$formatted_metadata['Tags'] = join(', ', array_map(
131-
function ( $tag ) {
132-
return sprintf( '[%1$s](http://wordpress.org/plugins/tags/%1$s)', $tag );
133-
},
134-
$this->metadata['Tags']
135-
));
136+
$formatted_metadata['Contributors'] = join(
137+
', ',
138+
array_map(
139+
function ( $contributor ) {
140+
$contributor = strtolower( $contributor );
141+
// @todo Map to GitHub account
142+
return sprintf( '[%1$s](http://profiles.wordpress.org/%1$s)', $contributor );
143+
},
144+
$this->metadata['Contributors']
145+
)
146+
);
147+
$formatted_metadata['Tags'] = join(
148+
', ',
149+
array_map(
150+
function ( $tag ) {
151+
return sprintf( '[%1$s](http://wordpress.org/plugins/tags/%1$s)', $tag );
152+
},
153+
$this->metadata['Tags']
154+
)
155+
);
136156
$formatted_metadata['License'] = sprintf( '[%s](%s)', $formatted_metadata['License'], $formatted_metadata['License URI'] );
137157
unset( $formatted_metadata['License URI'] );
138158
if ( $this->metadata['Stable tag'] === 'trunk' ) {
139159
$formatted_metadata['Stable tag'] .= ' (master)';
140160
}
141161

142162
// Render metadata
143-
$markdown = "<!-- DO NOT EDIT THIS FILE; it is auto-generated from readme.txt -->\n";
163+
$markdown = "<!-- DO NOT EDIT THIS FILE; it is auto-generated from readme.txt -->\n";
144164
$markdown .= sprintf( "# %s\n", $this->title );
145165
$markdown .= "\n";
146166
if ( file_exists( 'assets/banner-1544x500.png' ) ) {
@@ -159,9 +179,12 @@ function ( $tag ) {
159179
$markdown .= "\n";
160180

161181
$body = $section['body'];
182+
183+
$body = call_user_func( $general_section_formatter, $body );
162184
if ( isset( $section_formatters[$section['heading']] ) ) {
163-
$body = trim(call_user_func( $section_formatters[$section['heading']], $body ));
185+
$body = trim( call_user_func( $section_formatters[$section['heading']], $body ) );
164186
}
187+
165188
if ( $body ) {
166189
$markdown .= sprintf( "%s\n", $body );
167190
}

install-wp-tests.sh

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,65 @@
11
#!/usr/bin/env bash
22

33
if [ $# -lt 3 ]; then
4-
echo "usage: $0 <db-name> <db-user> <db-pass> [wp-version]"
4+
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version]"
55
exit 1
66
fi
77

88
DB_NAME=$1
99
DB_USER=$2
1010
DB_PASS=$3
11-
WP_VERSION=${4-master}
11+
DB_HOST=${4-localhost}
12+
WP_VERSION=${5-master}
1213

1314
set -ex
1415

1516
# set up a WP install
1617
WP_CORE_DIR=/tmp/wordpress/
1718
mkdir -p $WP_CORE_DIR
18-
wget -nv -O /tmp/wordpress.tar.gz https://github.com/WordPress/WordPress/tarball/$WP_VERSION
19+
20+
if [ $WP_VERSION == 'latest' ]; then
21+
ARCHIVE_URL='http://wordpress.org/latest.tar.gz'
22+
else
23+
ARCHIVE_URL="https://github.com/WordPress/WordPress/tarball/$WP_VERSION"
24+
fi
25+
26+
wget -nv -O /tmp/wordpress.tar.gz $ARCHIVE_URL
1927
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
2028

2129
# set up testing suite
2230
svn co --ignore-externals --quiet http://unit-tests.svn.wordpress.org/trunk/ $WP_TESTS_DIR
2331

32+
# portable in-place argument for both GNU sed and Mac OSX sed
33+
if [[ $(uname -s) == 'Darwin' ]]; then
34+
ioption='-i ""'
35+
else
36+
ioption='-i'
37+
fi
38+
39+
# generate testing config file
2440
cd $WP_TESTS_DIR
2541
cp wp-tests-config-sample.php wp-tests-config.php
26-
sed -i "s:dirname( __FILE__ ) . '/wordpress/':'$WP_CORE_DIR':" wp-tests-config.php
27-
sed -i "s/yourdbnamehere/$DB_NAME/" wp-tests-config.php
28-
sed -i "s/yourusernamehere/$DB_USER/" wp-tests-config.php
29-
sed -i "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
42+
sed $ioption "s:dirname( __FILE__ ) . '/wordpress/':'$WP_CORE_DIR':" wp-tests-config.php
43+
sed $ioption "s/yourdbnamehere/$DB_NAME/" wp-tests-config.php
44+
sed $ioption "s/yourusernamehere/$DB_USER/" wp-tests-config.php
45+
sed $ioption "s/yourpasswordhere/$DB_PASS/" wp-tests-config.php
46+
sed $ioption "s|localhost|${DB_HOST}|" wp-tests-config.php
47+
48+
# parse DB_HOST for port or socket references
49+
PARTS=(${DB_HOST//\:/ })
50+
DB_HOSTNAME=${PARTS[0]};
51+
DB_SOCK_OR_PORT=${PARTS[1]};
52+
EXTRA=""
53+
54+
if ! [ -z $DB_HOSTNAME ] ; then
55+
if [[ "$DB_SOCK_OR_PORT" =~ ^[0-9]+$ ]] ; then
56+
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
57+
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
58+
EXTRA=" --socket=$DB_SOCK_OR_PORT"
59+
elif ! [ -z $DB_HOSTNAME ] ; then
60+
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
61+
fi
62+
fi
3063

3164
# create database
32-
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"
65+
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA

phpcs.ruleset.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WordPress Coding Standards for Plugins">
3+
<description>Generally-applicable sniffs for WordPress plugins</description>
4+
5+
<rule ref="WordPress">
6+
<exclude name="WordPress.VIP.RestrictedFunctions"/>
7+
<exclude name="WordPress.VIP.SuperGlobalInputUsage"/>
8+
<exclude name="WordPress.VIP.ValidatedSanitizedInput"/>
9+
</rule>
10+
<rule ref="WordPress.NamingConventions.ValidFunctionName">
11+
<exclude-pattern>/tests/*</exclude-pattern><!-- because of PHPUnit method names -->
12+
</rule>
13+
14+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
15+
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
16+
<rule ref="Generic.Files.ByteOrderMark"/>
17+
<rule ref="Generic.PHP.LowerCaseConstant"/>
18+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
19+
<rule ref="Generic.PHP.NoSilencedErrors" />
20+
<rule ref="Generic.ControlStructures.InlineControlStructure" />
21+
<rule ref="Generic.Files.LineEndings">
22+
<properties>
23+
<property name="eolChar" value="\n"/>
24+
</properties>
25+
</rule>
26+
27+
</ruleset>

0 commit comments

Comments
 (0)