Permalink
Browse files

Demos: Fixed source and built RequireJS + Backbone demo

Fixes gh-6818
  • Loading branch information...
gseguin committed Feb 7, 2014
1 parent aad40a7 commit f029237274a1aef86cdb9d1fcf30a8034bce0f07
View
@@ -2,6 +2,7 @@ module.exports = function( grunt ) {
"use strict";
var _ = require( "underscore" ),
+ cheerio = require( "cheerio" ),
replaceCombinedCssReference = function( content, processedName ) {
return content.replace( /\.\.\/css\//, "css/" )
@@ -393,8 +394,8 @@ module.exports = function( grunt ) {
var processedName = grunt.config.process( name + "<%= versionSuffix %>" );
content = content.replace( /_assets\/js\/">/gi, "_assets/js/index.js\">" );
content = content.replace( /\.\.\/external\/jquery\//gi, "js/" );
+ content = content.replace( /\.\.\/js\/\"/gi, "js/\"" );
content = content.replace( /js\/"/gi, "js/" + processedName + ".min.js\"" );
- content = content.replace( new RegExp( "../js/" + processedName, "gi" ), "js/" + processedName );
content = replaceCombinedCssReference( content, processedName );
content = content.replace( /^\s*<\?php include\(\s*['"]([^'"]+)['"].*$/gmi,
function( match, includePath /*, offset, string */ ) {
@@ -435,15 +436,45 @@ module.exports = function( grunt ) {
},
"demos.backbone": {
options: {
- processContent: function( content /*, srcPath */ ) {
- var processedName = grunt.config.process( name + "<%= versionSuffix %>" );
- content = content.replace( /"jquery": "\.\.\/\.\.\/\.\.\/js\/jquery"/,
- "\"jquery\": \"../../js/jquery\"" );
- content = replaceCombinedCssReference( content, processedName );
+ processContent: function( content, srcPath ) {
+ var $,
+ processedName = grunt.config.process( name + "<%= versionSuffix %>" );
+
+ if ( /\.html$/.test( srcPath ) ) {
+
+ content = replaceCombinedCssReference( content, processedName );
+
+ $ = cheerio.load( content );
+
+ $( "script" ).each( function ( idx, element ) {
+ var script = $( element );
+ if ( /requirejs\.config\.js$/.test( script.attr( "src" ) ) ) {
+
+ // Get rid of the requirejs.config.js script tag since we're using the built bundle
+ script.remove();
+ } else if ( /require.js$/.test( script.attr( "src" ) ) ) {
+
+ // Use the rawgithub.com version for requirejs
+ script.attr( "src",
+ "//rawgithub.com/jrburke/requirejs/" +
+ grunt.template.process( "<%= pkg.devDependencies.requirejs %>" ) +
+ "/require.js" );
+ }
+ });
+
+ // write out newly created file contents
+ content = $.html();
+ } else if ( /\.js$/.test( srcPath ) ) {
+
+ // Redifines paths for compiled demos
+ content = content.replace( /baseUrl:.*$/m, "baseUrl: \"../js\"," );
+ content = content.replace( /\.\.\/external\/jquery\//, "" );
+ content = content.replace( /jquery\.mobile/, processedName );
+ content = content.replace(
+ /"backbone-requirejs-demos".*$/m,
+ "\"backbone-requirejs-demos\": \"../backbone-requirejs/js\"" );
+ }
- // Update dependency to jquery.mobile claimed by jquerymobile.js
- content = content.replace( /\[ "\.\.\/\.\.\/js\/\?noext" \]/,
- "[ \"../../../" + processedName + "\" ]" );
return content;
}
},
@@ -5,7 +5,9 @@
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../../css/themes/default/jquery.mobile.css">
- <script src="js/libs/require.js" data-main="js/mobile"></script>
+ <script src="../../external/requirejs/require.js"></script>
+ <script src="../../js/requirejs.config.js"></script>
+ <script src="js/main.js"></script>
</head>
<body>
@@ -2,7 +2,10 @@
// ===================
// Includes file dependencies
-define([ "jquery","backbone","models/CategoryModel" ], function( $, Backbone, CategoryModel ) {
+define([
+ "jquery",
+ "backbone",
+ "../models/CategoryModel" ], function( $, Backbone, CategoryModel ) {
// Extends Backbone.Router
var Collection = Backbone.Collection.extend( {
Oops, something went wrong.

0 comments on commit f029237

Please sign in to comment.