Skip to content

Commit 682ce50

Browse files
committed
Added jQuery UI indexes.
1 parent 6b37b87 commit 682ce50

File tree

5 files changed

+184
-65
lines changed

5 files changed

+184
-65
lines changed

grunt.js

Lines changed: 122 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -51,101 +51,161 @@ grunt.registerTask( "build-wordpress", "check-modules clean lint build" );
5151

5252
grunt.registerTask( "build-index", function() {
5353
var rversion = /^(\d+)\.(\d+)(?:\.(\d+))?-?(.*)$/;
54-
function getVersion( version ) {
54+
function normalizeVersion( version ) {
5555
var match = rversion.exec( version );
5656

5757
return match[ 1 ] + "." + match[ 2 ] + "." + ( match[ 3 ] || 0 ) +
5858
( match[ 4 ] ? "-" + match[ 4 ] : "" );
5959
}
6060

61-
function organize( files ) {
62-
var result = {};
63-
64-
files.forEach(function( file ) {
65-
var version = result[ file.version ] || ( result[ file.version ] = {} );
66-
version[ file.typePretty ] = file;
61+
function getLatestStable( releases ) {
62+
return _.find( releases, function( release ) {
63+
return release.version.indexOf( "-" ) === -1;
6764
});
68-
69-
return result;
7065
}
7166

72-
var prettyTypes = {
73-
"": "uncompressed",
74-
"min": "minified",
75-
"pack": "packed"
76-
};
77-
function parseFiles( files, regex ) {
67+
function parseReleases( files, regex ) {
7868
return files
7969
.map(function( filename ) {
8070
var type,
8171
matches = regex.exec( filename );
8272

83-
if ( !matches ) {
73+
// matches[ 3 ] = "min" or "pack" or ""
74+
if ( !matches || matches[ 3 ] ) {
8475
return null;
8576
}
8677

87-
type = matches[ 3 ] || "";
8878
return {
8979
filename: matches[ 0 ],
90-
version: getVersion( matches[ 2 ] ),
91-
type: type,
92-
typePretty: prettyTypes[ type ]
80+
version: normalizeVersion( matches[ 2 ] )
9381
};
9482
})
9583
// Remove null values from filtering
9684
.filter( _.identity )
9785
.sort(function( a, b ) {
98-
return semver.compare( b.version, a.version ) || ( a.type < b.type ? -1 : 1 );
86+
return semver.compare( b.version, a.version );
9987
});
10088
}
10189

102-
function getLatestStable( organized ) {
103-
return _.find( Object.keys( organized ), function( version ) {
104-
return version.indexOf( "-" ) === -1;
105-
});
106-
}
90+
function getCoreData() {
91+
var files = grunt.file.expandFiles( "cdn/*.js" ),
92+
coreReleases = parseReleases( files,
93+
/(jquery-(\d+\.\d+(?:\.\d+)?[^.]*)(?:\.(min|pack))?\.js)/ ),
94+
jquery2Releases = coreReleases.filter(function( match ) {
95+
return semver.satisfies( match.version, "2.x" );
96+
}),
97+
jquery1Releases = coreReleases.filter(function( match ) {
98+
return semver.satisfies( match.version, "1.x" );
99+
}),
100+
migrateReleases = parseReleases( files,
101+
/(jquery-migrate-(\d+\.\d+(?:\.\d+)?[^.]*)(?:\.(min))?\.js)/ );
102+
103+
function addTypes( release ) {
104+
var minFilename = release.filename.replace( ".js", ".min.js" ),
105+
packFilename = release.filename.replace( ".js", ".pack.js" );
106+
107+
if ( files.indexOf( "cdn/" + minFilename ) !== -1 ) {
108+
release.minified = minFilename;
109+
}
110+
if ( files.indexOf( "cdn/" + packFilename ) !== -1 ) {
111+
release.packed = packFilename;
112+
}
113+
}
114+
115+
jquery1Releases.forEach( addTypes );
116+
jquery2Releases.forEach( addTypes );
117+
migrateReleases.forEach( addTypes );
107118

108-
var allFiles = grunt.file.expandFiles( "cdn/**.js" ),
109-
jQueryCoreFiles = parseFiles( allFiles,
110-
/(jquery-(\d+\.\d+(?:\.\d+)?[^.]*)(?:\.(min|pack))?\.js)/ ),
111-
jQueryMigrateFiles = parseFiles( allFiles,
112-
/(jquery-migrate-(\d+\.\d+(?:\.\d+)?[^.]*)(?:\.min)?\.js)/ ),
113-
jQuery2 = organize( jQueryCoreFiles.filter(function( match ) {
114-
return semver.satisfies( match.version, "2.x" );
115-
})),
116-
jQuery1 = organize( jQueryCoreFiles.filter(function( match ) {
117-
return semver.satisfies( match.version, "1.x" );
118-
})),
119-
jQueryMigrate = organize( jQueryMigrateFiles ),
120-
data = {
119+
return {
121120
jquery2: {
122-
latestStable: jQuery2[ getLatestStable( jQuery2 ) ],
123-
all: jQuery2
121+
latestStable: getLatestStable( jquery2Releases ),
122+
all: jquery2Releases
124123
},
125124
jquery1: {
126-
latestStable: jQuery1[ getLatestStable( jQuery1 ) ],
127-
all: jQuery1
125+
latestStable: getLatestStable( jquery1Releases ),
126+
all: jquery1Releases
128127
},
129128
migrate: {
130-
latestStable: jQueryMigrate[ getLatestStable( jQueryMigrate ) ],
131-
all: jQueryMigrate
129+
latestStable: getLatestStable( migrateReleases ),
130+
all: migrateReleases
132131
}
133132
};
133+
}
134+
135+
function getUiData() {
136+
var majorReleases = {},
137+
uiReleases = grunt.file.expandDirs( "cdn/ui/*" )
138+
.map(function( dir ) {
139+
var version,
140+
filename = dir.substring( 4 ) + "jquery-ui.js";
141+
142+
version = dir.substring( 7 );
143+
version = version.substring( 0, version.length - 1 );
144+
145+
return {
146+
filename: filename,
147+
version: version,
148+
minified: filename.replace( ".js", ".min.js" ),
149+
themes: grunt.file.expandDirs( dir + "themes/*" ).map(function( themeDir ) {
150+
var theme = themeDir.substring( dir.length + 7 );
151+
return theme.substring( 0, theme.length - 1 );
152+
})
153+
};
154+
})
155+
.sort(function( a, b ) {
156+
return semver.compare( b.version, a.version );
157+
});
134158

135-
Handlebars.registerHelper( "listItem", function( prefix, files ) {
136-
var li = "<li>";
137-
Object.keys( files ).forEach(function( type, index ) {
138-
if ( !index ) {
139-
li += prefix + " " + files[ type ].version + " - ";
140-
} else {
141-
li += " or ";
159+
// Group by major release
160+
uiReleases.forEach(function( release ) {
161+
var major = /^\d+\.\d+/.exec( release.version )[ 0 ];
162+
if ( !majorReleases[ major ] ) {
163+
majorReleases[ major ] = [];
142164
}
143165

144-
li += "<a href='/" + files[ type ].filename + "'>" + type + "</a> ";
166+
majorReleases[ major ].push( release );
167+
});
168+
169+
// Convert to array of major release groups
170+
return Object.keys( majorReleases ).map(function( major ) {
171+
var all = majorReleases[ major ],
172+
latestStable = getLatestStable( all );
173+
174+
return {
175+
major: major,
176+
latestStable: latestStable,
177+
all: all.filter(function( release ) {
178+
return release !== latestStable;
179+
})
180+
};
145181
});
146-
li += "</li>";
182+
}
183+
184+
Handlebars.registerHelper( "release", function( prefix, release ) {
185+
var html = prefix + " " + release.version + " - " +
186+
"<a href='/" + release.filename + "'>uncompressed</a>";
147187

148-
return new Handlebars.SafeString( li );
188+
if ( release.minified ) {
189+
html += ", <a href='/" + release.minified + "'>minified</a>";
190+
}
191+
if ( release.packed ) {
192+
html += ", <a href='/" + release.packed + "'>packed</a>";
193+
}
194+
195+
return new Handlebars.SafeString( html );
196+
});
197+
198+
Handlebars.registerHelper( "uiTheme", function( release ) {
199+
var url;
200+
// TODO: link to minified theme if available
201+
if ( release.themes.indexOf( "smoothness" ) !== -1) {
202+
url = "smoothness/jquery-ui.css";
203+
} else {
204+
url = "base/jquery-ui.css";
205+
}
206+
207+
return new Handlebars.SafeString(
208+
"<a href='/ui/" + release.version + "/themes/" + url + "'>theme</a>" );
149209
});
150210

151211
Handlebars.registerHelper( "include", (function() {
@@ -156,15 +216,21 @@ grunt.registerTask( "build-index", function() {
156216
grunt.file.read( "templates/" + template + ".hbs" ) );
157217
}
158218

159-
return new Handlebars.SafeString( templates[ template ]() );
219+
return new Handlebars.SafeString( templates[ template ]( this ) );
160220
};
161221
})());
162222

223+
var data = getCoreData();
224+
data.ui = getUiData();
225+
163226
grunt.file.write( "dist/wordpress/posts/page/index.html",
164227
Handlebars.compile( grunt.file.read( "templates/index.hbs" ) )( data ) );
165228

166229
grunt.file.write( "dist/wordpress/posts/page/jquery.html",
167230
Handlebars.compile( grunt.file.read( "templates/jquery.hbs" ) )( data ) );
231+
232+
grunt.file.write( "dist/wordpress/posts/page/ui.html",
233+
Handlebars.compile( grunt.file.read( "templates/ui.hbs" ) )( data ) );
168234
});
169235

170236
};

templates/index.hbs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
{{#with jquery2}}
1212
<h3>jQuery 2.x - Latest Version (IE &lt;9 not supported)</h3>
1313
<ul>
14-
{{listItem "jQuery Core" latestStable}}
14+
<li>{{release "jQuery Core" latestStable}}</li>
1515
</ul>
1616
{{/with}}
1717

1818
{{#with jquery1}}
1919
<h3>jQuery 1.x - Latest Version</h3>
2020
<ul>
21-
{{listItem "jQuery Core" latestStable}}
21+
<li>{{release "jQuery Core" latestStable}}</li>
2222
</ul>
2323
{{/with}}
2424

@@ -27,6 +27,36 @@
2727
{{#with migrate}}
2828
<h3>jQuery Migrate - Latest Version</h3>
2929
<ul>
30-
{{listItem "jQuery Migrate" latestStable}}
30+
<li>{{release "jQuery Migrate" latestStable}}</li>
31+
</ul>
32+
{{/with}}
33+
34+
<h2>jQuery UI</h2>
35+
<p>
36+
Showing the latest release for the stable and legacy release families.
37+
<a href="/ui/">See all versions of jQuery UI</a>.
38+
</p>
39+
40+
{{#with ui.[0]}}
41+
<h3>jQuery UI {{major}} - Latest Version</h3>
42+
<ul>
43+
<li>{{release "jQuery UI" latestStable}}</li>
44+
<li>Themes:
45+
{{#each latestStable.themes}}
46+
<a href="/ui/{{../latestStable/version}}/themes/{{this}}/jquery-ui.css">{{this}} theme</a>
47+
{{/each}}
48+
</li>
49+
</ul>
50+
{{/with}}
51+
52+
{{#with ui.[1]}}
53+
<h3>jQuery UI {{major}} - Latest Version</h3>
54+
<ul>
55+
<li>{{release "jQuery UI" latestStable}}</li>
56+
<li>Themes:
57+
{{#each latestStable.themes}}
58+
<a href="/ui/{{../latestStable/version}}/themes/{{this}}/jquery-ui.css">{{this}} theme</a>
59+
{{/each}}
60+
</li>
3161
</ul>
3262
{{/with}}

templates/jquery-git.hbs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33

44
<ul>
55
<li>
6-
<a href="/jquery-git2.js">jQuery 2.x git build</a> -
6+
jQuery 2.x git build</a> -
7+
<a href="/jquery-git2.js">uncompressed</a>,
78
<a href="/jquery-git2.min.js">minified</a>
89
</li>
910
<li>
10-
<a href="/jquery-git1.js">jQuery 1.x git build</a> -
11+
jQuery 1.x git build</a> -
12+
<a href="/jquery-git1.js">uncompressed</a>,
1113
<a href="/jquery-git1.min.js">minified</a>
1214
</li>
1315
<li>
14-
<a href="/jquery-migrate-git.js">jQuery Migrate git build</a> -
16+
jQuery Migrate git build</a> -
17+
<a href="/jquery-migrate-git.js">uncompressed</a>,
1518
<a href="/jquery-migrate-git.min.js">minified</a>
1619
</li>
1720
</ul>

templates/jquery.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<h2>jQuery Core - All 2.x Versions</h2>
99
<ul>
1010
{{#each all}}
11-
{{listItem "jQuery Core" this}}
11+
<li>{{release "jQuery Core" this}}</li>
1212
{{/each}}
1313
</ul>
1414
{{/with}}
@@ -17,7 +17,7 @@
1717
<h2>jQuery Core - All 1.x Versions</h2>
1818
<ul>
1919
{{#each all}}
20-
{{listItem "jQuery Core" this}}
20+
<li>{{release "jQuery Core" this}}</li>
2121
{{/each}}
2222
</ul>
2323
{{/with}}
@@ -26,7 +26,7 @@
2626
<h2>jQuery Migrate - All Versions</h2>
2727
<ul>
2828
{{#each all}}
29-
{{listItem "jQuery Core" this}}
29+
<li>{{release "jQuery Migrate" this}}</li>
3030
{{/each}}
3131
</ul>
3232
{{/with}}

templates/ui.hbs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<script>{
2+
"title": "jQuery UI - All Versions"
3+
}</script>
4+
5+
{{#each ui}}
6+
<h2>jQuery UI {{major}}</h2>
7+
{{release "jQuery UI" latestStable}}
8+
<h3>Themes</h3>
9+
{{#each latestStable.themes}}
10+
<a href="/ui/{{../latestStable/version}}/themes/{{this}}/jquery-ui.css">{{this}}</a>
11+
{{/each}}
12+
{{#if all.length}}
13+
<h3>Previous Releases</h3>
14+
{{#each all}}
15+
<li>
16+
{{release "jQuery UI" this}}, {{uiTheme this}}
17+
</li>
18+
{{/each}}
19+
{{/if}}
20+
{{/each}}

0 commit comments

Comments
 (0)