Skip to content

Commit

Permalink
Generate profile URL for each contributor, closes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Feb 11, 2016
1 parent d520014 commit 5d57a40
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions tasks/wp_readme_to_markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function(grunt) {
var options = this.options({
screenshot_url: 'http://ps.w.org/{plugin}/assets/{screenshot}.png',
});

grunt.verbose.writeflags( options );
this.files.forEach(function(f) {

Expand All @@ -29,7 +29,7 @@ module.exports = function(grunt) {
grunt.log.warn('Source file "' + filepath + '" not found.');
return false;
} else {
return true;
return true;
}
}).map(function(filepath) {
// Read file source.
Expand All @@ -38,9 +38,9 @@ module.exports = function(grunt) {

/* The following is a ported version of {@see https://github.com/benbalter/WP-Readme-to-Github-Markdown}*/

//Convert Headings
//Convert Headings
grunt.log.debug("Converting headings");
readme = readme.replace( new RegExp("^=([^=]+)=*?[\\s ]*?$","gim"),"###$1###");
readme = readme.replace( new RegExp("^=([^=]+)=*?[\\s ]*?$","gim"),"###$1###");
readme = readme.replace( new RegExp("^==([^=]+)==*?[\\s ]*?$","mig"),"##$1##");
readme = readme.replace( new RegExp("^===([^=]+)===*?[\\s ]*?$","gim"),"#$1#");

Expand All @@ -53,19 +53,41 @@ module.exports = function(grunt) {
readme = readme.replace( header_search, header_replace );
}

// Include w.org profiles for contributors.
grunt.log.debug("Including contributors profiles");
var contributors_match = readme.match( new RegExp("(\\*\\*Contributors:\\*\\* )(.+)", "m") );
if ( header_match && header_match.length >= 1 ) {
var contributors_search = contributors_match[0];
var contributors_replace = contributors_match[1];
var profiles = [];

// Fill profiles.
contributors_match[2].split(",").forEach(function(value) {
value = value.trim();
profiles.push("[" + value + "](https://profiles.wordpress.org/" + value + ")");
});

contributors_replace += profiles.join(", ");

// Add line break.
contributors_replace += ' ';

readme = readme.replace( contributors_search, contributors_replace );
}

//guess plugin slug from plugin name
//@todo Get this from config instead?
grunt.log.debug("Get plugin name");
var _match = readme.match( new RegExp("^#([^#]+)#[\\s ]*?$","im") );
var _match = readme.match( new RegExp("^#([^#]+)#[\\s ]*?$","im") );

//process screenshots, if any
grunt.log.debug("Get screenshots");
var screenshot_match = readme.match( new RegExp("## Screenshots ##([^#]*)","im") );
if ( _match && screenshot_match && screenshot_match.length > 1 ) {

var plugin = _match[1].trim().toLowerCase().replace(/ /g, '-');
//Collect screenshots content

//Collect screenshots content
var screenshots = screenshot_match[1];

//parse screenshot list into array
Expand All @@ -76,7 +98,7 @@ module.exports = function(grunt) {
nonGlobalMatch = globalMatch[i].match( new RegExp( "^[0-9]+\\. (.*)", 'im' ) );
matchArray.push( nonGlobalMatch[1] );
}

//replace list item with markdown image syntax, hotlinking to plugin repo
//@todo assumes .png, perhaps should check that file exists first?
for( i=1; i <= matchArray.length; i++ ) {
Expand All @@ -86,7 +108,7 @@ module.exports = function(grunt) {
readme = readme.replace( globalMatch[i-1], "### "+i+". "+ matchArray[i-1] +" ###\n!["+matchArray[i-1]+"](" + url + ")\n" );
}
}

//Code blocks
readme = readme.replace( new RegExp("^`$[\n\r]+([^`]*)[\n\r]+^`$","gm"),function( codeblock, codeblockContents ){
var lines = codeblockContents.split("\n");
Expand All @@ -96,7 +118,7 @@ module.exports = function(grunt) {

// Write the destination file.
grunt.file.write( f.dest, readme );

// Print a success message.
grunt.log.writeln('File "' + f.dest + '" created.');
});
Expand Down

0 comments on commit 5d57a40

Please sign in to comment.