Permalink
Browse files

Added title & description metadata extraction

  • Loading branch information...
gseguin committed Jul 26, 2012
1 parent 4121fc0 commit 332705b8e008681c6fec9923c576e41783ccf21d
Showing with 51 additions and 4 deletions.
  1. +51 −4 build/tasks/plugins.js
View
@@ -7,7 +7,10 @@ module.exports = function( grunt ) {
grunt.registerTask( "plugins", function() {
var globalConfig = pluginConfig = grunt.config.get( 'global' ),
pluginConfig = globalConfig.plugins,
- done = this.async(), filenameToPlugin;
+ done = this.async(),
+ filenameToPlugin,
+ escapeRegexString,
+ extractMetadata;
filenameToPlugin = function( filename ) {
var pathless = filename.replace( /js\//, "" ),
@@ -27,6 +30,48 @@ module.exports = function( grunt ) {
.replace( ".js", ".jquery.json" );
};
+ // Thank you Dojo
+ // summary: Regular expressions and Builder resources
+ escapeRegexString = function ( /*String*/str, /*String?*/except ) {
+ // summary:
+ // Adds escape sequences for special characters in regular expressions
+ // except:
+ // a String with special characters to be left unescaped
+
+ return str.replace( /([\.$?*|{}\(\)\[\]\\\/\+^])/g, function ( ch ) {
+ if ( except && except.indexOf( ch ) != -1 ) {
+ return ch;
+ }
+ return "\\" + ch;
+ } ); // String
+ };
+
+ extractMetadata = function( data ) {
+ var lines = data.split( "\n" ),
+ matches = lines.filter( function( line, index ) {
+ return ( /^.*\/\/>>\s*[^:]+:.*$/ ).test( line );
+ }),
+ metadata = {};
+ if ( matches && matches.length ) {
+ matches.forEach( function( meta ) {
+ var attr = meta.replace( /^.*\/\/>>\s*([^:]+):.*$/, "$1" ).trim(),
+ attrLabelRE = new RegExp( "^.*" + escapeRegexString( "//>>" + attr + ":") + "\\s*", "m" ),
+ value = meta.replace( attrLabelRE, "" ).trim(),
+ namespace, name,
+ indexOfDot = attr.indexOf( "." );
+ if ( indexOfDot > 0 ) { // if there is something before the dot
+ namespace = attr.split( "." )[0];
+ name = attr.substring( indexOfDot+1 );
+ metadata[ namespace ] = metadata[ namespace ] || {};
+ metadata[ namespace ][ name ] = value;
+ } else {
+ metadata[ attr ] = value;
+ }
+ });
+ }
+ return metadata;
+ };
+
requirejs.tools.useLib( function ( require ) {
require( [ 'parse' ], function ( parse ) {
// grab all the files that still use the original convention
@@ -44,16 +89,18 @@ module.exports = function( grunt ) {
var data = fs.readFileSync( filename, 'utf8' ),
tree = parse.findDependencies( filename, data ),
- manifest, template;
+ manifest,
+ template,
+ metadata = extractMetadata( data );
template = grunt.file.read( pluginConfig.template );
manifest = filenameToPlugin( filename );
grunt.file.write( manifest, grunt.template.process( template, {
name: filename.replace(".json", ""),
- title: "TODO",
- desc: "TODO",
+ title: metadata.label || "Untitled",
+ desc: metadata.description || "",
version: globalConfig.ver.official
}));
});

0 comments on commit 332705b

Please sign in to comment.