Skip to content

Commit 831c982

Browse files
author
almchung
committed
Merge branch 'friendly-err-sys' of https://github.com/processing/p5.js into friendly-err-sys
2 parents afcfa1a + a570d3c commit 831c982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4240
-1438
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ node_modules/*
44
experiments/*
55
lib_old/*
66
lib/p5.*
7+
lib/modules
78
lib/addons/p5.dom.min.js
89
docs/reference/*
910
docs/yuidoc-p5-theme/assets/js/reference.js*
1011
!*.gitkeep
1112
examples/3d/
1213
.idea
13-
.vscode
14+
.vscode

Gruntfile.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function getYuidocOptions() {
6161
helpers: [],
6262
preprocessor: './docs/preprocessor.js',
6363
outdir: 'docs/reference/'
64-
//, quiet: false
6564
}
6665
};
6766

@@ -92,6 +91,7 @@ module.exports = function(grunt) {
9291

9392
// read in the package, used for knowing the current version, et al.
9493
pkg: grunt.file.readJSON('package.json'),
94+
9595
// Configure style consistency checking for this file, the source, and the tests.
9696
jscs: {
9797
options: {
@@ -214,18 +214,20 @@ module.exports = function(grunt) {
214214
logErrors: true,
215215
timeout: 100000
216216
}
217-
},
217+
}
218218
},
219219

220220
// This is a standalone task, used to automatically update the bower.json
221-
// file to match the values in package.json. It is (likely) used as part
221+
// file to match the values in package.json. It is (likely) used as part
222222
// of the manual release strategy.
223223
update_json: {
224+
224225
// set some task-level options
225226
options: {
226227
src: 'package.json',
227228
indent: '\t'
228229
},
230+
229231
// update bower.json with data from package.json
230232
bower: {
231233
src: 'package.json', // where to read from
@@ -235,12 +237,9 @@ module.exports = function(grunt) {
235237
}
236238
},
237239

238-
// The actual compile step: This should collect all the dependencies
239-
// and compile them into a single file.
240+
// This generates the theme for the documentation from the theme source
241+
// files.
240242
requirejs: {
241-
242-
// This generates the theme for the documentation from the theme source
243-
// files.
244243
yuidoc_theme: {
245244
options: {
246245
baseUrl: './docs/yuidoc-p5-theme-src/scripts/',
@@ -297,6 +296,7 @@ module.exports = function(grunt) {
297296
}
298297
}
299298
},
299+
300300
// This is a static server which is used when testing connectivity for the
301301
// p5 library. This avoids needing an internet connection to run the tests.
302302
// It serves all the files in the test directory at http://localhost:9001/
@@ -343,7 +343,13 @@ module.exports = function(grunt) {
343343
}
344344
});
345345

346-
// Load task definitions
346+
// Load build tasks.
347+
// This contains the complete build task ("browserify")
348+
// and the task to generate user select modules of p5
349+
// ("combineModules") which can be invoked directly by
350+
// `grunt combineModules:module_1:module_2` where core
351+
// is included by default in all combinations always.
352+
// NOTE: "module_x" is the name of it's folder in /src.
347353
grunt.loadTasks('build/tasks');
348354

349355
// Load the external libraries used.
@@ -363,7 +369,6 @@ module.exports = function(grunt) {
363369
grunt.loadNpmTasks('grunt-minjson');
364370

365371
// Create the multitasks.
366-
// TODO: "requirejs" is in here to run the "yuidoc_themes" subtask. Is this needed?
367372
grunt.registerTask('build', ['browserify', 'uglify', 'requirejs']);
368373
grunt.registerTask('test', ['jshint', 'jscs', 'build', 'yuidoc:dev', 'connect', 'mocha', 'mochaTest']);
369374
grunt.registerTask('test:nobuild', ['jshint:test', 'jscs:test', 'connect', 'mocha']);

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ If you have found a bug in the p5.js library, you can file it here under the [
1414

1515
## p5.js library
1616

17-
To use p5.js, you can [download the p5.js library here](http://p5js.org/download). If you are interested in the most recent, less stable version, you can clone this repository and run `grunt` from the command line to generate the library from source. See the [development](https://github.com/processing/p5.js/wiki/Development) wiki for more information about our build process.
17+
To use p5.js, you can [download the p5.js library here](http://p5js.org/download). If you are interested in the most recent, less stable version, you can clone this repository and run `grunt` from the command line to generate the library from source. See the [development](https://github.com/processing/p5.js/wiki/Development) wiki for more information about our build process.
1818

1919
## Issues
2020

@@ -23,12 +23,12 @@ Please post bugs in the proper repository:
2323
* p5.js general and p5.dom: [https://github.com/processing/p5.js/issues](https://github.com/processing/p5.js/issues)
2424
* p5.sound: [https://github.com/processing/p5.js-sound/issues](https://github.com/processing/p5.js-sound/issues)
2525
* p5.js website: [https://github.com/processing/p5.js-website/issues](https://github.com/processing/p5.js-website/issues)
26-
* p5.js web editor: [https://github.com/processing/p5.js-website/issues](https://github.com/processing/p5.js-web-editor/issues)
26+
* p5.js web editor: [https://github.com/processing/p5.js-web-editor/issues](https://github.com/processing/p5.js-web-editor/issues)
2727

2828

2929
## Learning
3030

31-
Check out [p5js.org](http://p5js.org) for lots more! Here are some quicklinks:
31+
Check out [p5js.org](http://p5js.org) for lots more! Here are some quick-links:
3232

3333
* [Get Started](http://p5js.org/get-started) — Create and run your first sketch!
3434
* [p5.js overview](https://github.com/processing/p5.js/wiki/p5.js-overview) — An overview of the main features and functionality of p5.js.
@@ -43,7 +43,3 @@ Check out [p5js.org](http://p5js.org) for lots more! Here are some quicklinks:
4343
p5.js is a collaborative project created by many individuals, and you are invited to help. All types of involvement are welcome. See the [community section](http://p5js.org/community) to get started!
4444

4545
Developers, check out the [development](https://github.com/processing/p5.js/wiki/Development) wiki page for more in-depth details about contributing code, bug fixes, and documentation.
46-
47-
48-
49-

build/tasks/combineModules.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'use strict';
2+
3+
var fs = require('fs');
4+
var path = require('path');
5+
var browserify = require('browserify');
6+
var derequire = require('derequire');
7+
8+
module.exports = function(grunt) {
9+
10+
grunt.registerTask('combineModules', 'Compile and combine certain modules with Browserify', function(args) {
11+
// Reading and writing files is asynchronous
12+
var done = this.async();
13+
14+
// Module sources are space separated names in a single string (enter within quotes)
15+
var module_src, temp = [];
16+
for (var i in arguments) {
17+
temp.push(arguments[i]);
18+
}
19+
module_src = temp.join(', ');
20+
21+
// Render the banner for the top of the file. Includes the Module name.
22+
var bannerTemplate = '/*! Custom p5.js v<%= pkg.version %> <%= grunt.template.today("mmmm dd, yyyy") %> \nContains the following modules : ' + module_src + '*/';
23+
var banner = grunt.template.process(bannerTemplate);
24+
25+
// Make a list of sources from app.js in that sequence only
26+
var sources = [];
27+
var dump = fs.readFileSync('./src/app.js', 'utf8');
28+
var regexp = /\(\'.+\'/g;
29+
var match;
30+
while( (match = regexp.exec(dump)) != null) {
31+
var text = match[0];
32+
text = text.substring(text.indexOf('./')+2, text.length-1);
33+
sources.push(text);
34+
}
35+
36+
// Populate the source file path array with concerned files' path
37+
var srcDirPath = './src';
38+
var srcFilePath = [];
39+
for (var j = 0; j < sources.length; j++) {
40+
var source = sources[j];
41+
var base = source.substring(0,source.lastIndexOf('/'));
42+
if(base === 'core' || module_src.search(base) !== -1) {
43+
// Push the resolved paths directly
44+
var filePath = (source.search('.js') !== -1) ? source : source + '.js';
45+
var fullPath = path.resolve(srcDirPath, filePath);
46+
srcFilePath.push(fullPath);
47+
}
48+
}
49+
50+
console.log(srcFilePath);
51+
// Target file path
52+
var libFilePath = path.resolve('lib/modules/p5Custom.js');
53+
54+
// Invoke Browserify programatically to bundle the code
55+
var bundle = browserify(srcFilePath, {
56+
standalone: 'p5'
57+
})
58+
.transform('brfs')
59+
.bundle();
60+
61+
// Start the generated output with the banner comment,
62+
var code = banner + '\n';
63+
64+
// Then read the bundle into memory so we can run it through derequire
65+
bundle.on('data', function(data) {
66+
code += data;
67+
}).on('end', function() {
68+
grunt.file.write(libFilePath, derequire(code));
69+
70+
// Print a success message
71+
grunt.log.writeln('>>'.green + ' Module ' + libFilePath.blue + ' created.');
72+
73+
// Complete the task
74+
done();
75+
});
76+
});
77+
};

docs/preprocessor.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,27 @@ function mergeOverloadedMethods(data) {
7373
assertEqual(classitem.description || '', '',
7474
'additional overloads should have no description');
7575

76-
if (!method.overloads) {
77-
method.overloads = [{
76+
function makeOverload(method) {
77+
var overload = {
7878
line: method.line,
79-
params: processOverloadedParams(method.params)
80-
}];
79+
params: processOverloadedParams(method.params || [])
80+
};
81+
// TODO: the doc renderer assumes (incorrectly) that
82+
// these are the same for all overrides
83+
if (method.static)
84+
overload.static = method.static;
85+
if (method.chainable)
86+
overload.chainable = method.chainable;
87+
if (method.return)
88+
overload.return = method.return;
89+
return overload;
90+
}
91+
92+
if (!method.overloads) {
93+
method.overloads = [makeOverload(method)];
8194
delete method.params;
8295
}
83-
method.overloads.push({
84-
line: classitem.line,
85-
params: processOverloadedParams(classitem.params)
86-
});
96+
method.overloads.push(makeOverload(classitem));
8797
return false;
8898
} else {
8999
methodsByFullName[fullName] = classitem;

docs/yuidoc-p5-theme-src/scripts/tpl/class.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
<% } %>
88

9-
<% var fields = _.filter(things, function(item) { return item.itemtype === 'property' }); %>
9+
<% var fields = _.filter(things, function(item) { return item.itemtype === 'property' && item.access !== 'private' }); %>
1010
<% if (fields.length > 0) { %>
1111
<h4>Fields</h4>
1212
<p>
@@ -17,7 +17,7 @@ <h4>Fields</h4>
1717
</p>
1818
<% } %>
1919

20-
<% var methods = _.filter(things, function(item) { return item.itemtype === 'method' }); %>
20+
<% var methods = _.filter(things, function(item) { return item.itemtype === 'method' && item.access !== 'private' }); %>
2121
<% if (methods.length > 0) { %>
2222
<h4>Methods</h4>
2323
<p>
@@ -29,4 +29,4 @@ <h4>Methods</h4>
2929
<% }); %>
3030
</table>
3131
</p>
32-
<% } %>
32+
<% } %>

docs/yuidoc-p5-theme-src/scripts/tpl/item.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ <h4>Description</h4>
1717

1818
<span class='description-text'><%= item.description %></span>
1919

20+
<% if (item.extends) { %>
21+
<p>Extends <a href="/reference/#/<%=item.extends%>" title="<%=item.extends%> reference"><%=item.extends%></a></p>
22+
<% } %>
23+
2024
<% if (item.module === 'p5.dom') { %>
2125
<p>This function requires you include the p5.dom library. Add the following into the head of your index.html file:
2226
<pre><code class="language-javascript">&lt;script language="javascript" type="text/javascript" src="path/to/p5.dom.js"&gt;&lt;/script&gt;</code></pre>
@@ -135,12 +139,13 @@ <h4>Parameters</h4>
135139
</div>
136140
<% } %>
137141

138-
<% if (item.return) { %>
142+
<% if (item.constructor || item.return) { %>
139143
<div>
140-
<h4>Returns</h4>
141-
<% if (item.return.type) { %>
144+
<h4>Returns</h4>
145+
<% if (item.constructor) { %>
146+
<p class='returns'><span class="param-type label label-info"><%=item.name%></span>: a new object</p>
147+
<% } else if (item.return.type) { %>
142148
<p class='returns'><span class="param-type label label-info"><%=item.return.type%></span>: <%= item.return.description %></p>
143149
<% } %>
144150
</div>
145-
<% } %>
146-
151+
<% } %>

docs/yuidoc-p5-theme-src/scripts/tpl/library.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ <h3><%= module.name %> library</h3>
1313
<% if (group.name !== module.name && group.name !== 'p5') { %>
1414
<a href="<%=group.hash%>" <% if (group.module !== module.name) { %>class="core"<% } %>><h4 class="group-name <% if (t == 0) { %> first<%}%>"><%=group.name%></h4></a>
1515
<% } %>
16-
<% _.each(group.items, function(item) { %>
16+
<% _.each(group.items.filter(function(item) {return item.access !== 'private'}), function(item) { %>
1717
<a href="<%=item.hash%>" <% if (item.module !== module.name) { %>class="core"<% } %>><%=item.name%><% if (item.itemtype === 'method') { %>()<%}%></a><br>
1818
<% t++; %>
1919
<% }); %>
2020
<% if (t >= Math.floor(totalItems/4)) { col++; t = 0; %>
2121
</div>
2222
<% } %>
2323
<% }); %>
24-
</div>
24+
</div>

docs/yuidoc-p5-theme-src/scripts/tpl/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ <h4 class="group-name" id="group-<%=group.name%>"><%=group.name%></h4>
44
<% _.each(group.subgroups, function(subgroup, ind) { %>
55
<dl>
66
<% if (subgroup.name !== '0') { %>
7-
<dt class="subgroup-<%=subgroup.name%>"><%=subgroup.name%></dt>
7+
<dt class="subgroup-name subgroup-<%=subgroup.name%>"><%=subgroup.name%></dt>
88
<% } %>
99
<% _.each(subgroup.items, function(item) { %>
1010
<dd><a href="<%=item.hash%>" title="<%- striptags(item.description) %>"><%=item.name%><% if (item.itemtype === 'method') { %>()<%}%></a></dd>

docs/yuidoc-p5-theme-src/scripts/views/itemView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ define([
2727
var isConstructor = cleanItem.is_constructor;
2828
var syntax = '';
2929
if (isConstructor) syntax += 'new ';
30+
else if (cleanItem.static && cleanItem.class) syntax += cleanItem.class + '.';
3031
syntax += cleanItem.name;
3132

3233
if (isMethod || isConstructor) {

0 commit comments

Comments
 (0)