Skip to content

Commit c6ce835

Browse files
authored
Merge pull request #480 from limzykenneth/master
Include p5.js version on p5-widgets used in tutorials
2 parents 188313e + ac00b96 commit c6ce835

File tree

13 files changed

+214
-170
lines changed

13 files changed

+214
-170
lines changed

Gruntfile.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// use this if you want to match all subfolders:
77
// '<%= config.src %>/templates/pages/**/*.hbs'
88

9+
const yaml = require('js-yaml');
10+
const fs = require('fs').promises;
911
const pkg = require('./package.json');
1012

1113
module.exports = function(grunt) {
@@ -317,6 +319,23 @@ module.exports = function(grunt) {
317319
}
318320
});
319321

322+
grunt.registerTask('update-version', function(){
323+
const done = this.async();
324+
325+
const version = require('./src/templates/pages/reference/data.json').project.version;
326+
327+
fs.readFile('./src/data/data.yml').then((str) => {
328+
const data = yaml.safeLoad(str);
329+
data.version = version;
330+
331+
const dump = yaml.safeDump(data);
332+
333+
return fs.writeFile('./src/data/data.yml', dump);
334+
}).then(() => {
335+
done();
336+
});
337+
});
338+
320339
grunt.loadNpmTasks('grunt-exec');
321340
grunt.loadNpmTasks('grunt-assemble');
322341
grunt.loadNpmTasks('grunt-file-append');
@@ -351,6 +370,7 @@ module.exports = function(grunt) {
351370

352371
// runs three tasks in order
353372
grunt.registerTask('build', [
373+
'update-version',
354374
'exec',
355375
'clean',
356376
'requirejs',

src/data/data.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
title: p5.js
1+
title: p5.js
2+
version: 0.9.0

src/templates/pages/learn/basics.hbs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ img {
2929
When you open p5, your first sketch will look like this. There are two parts: setup and draw. Inside the curly brackets after setup and draw we will add code to create a drawing.
3030
</p>
3131

32-
<script type="text/p5" data-height="400" data-preview-width="300">
32+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
3333
function setup() {
3434
3535
}
@@ -45,7 +45,7 @@ function draw() {
4545
<span class='try'>Try changing the numbers inside the parentheses to see what happens.</span>
4646
</p>
4747

48-
<script type="text/p5" data-height="400" data-preview-width="300">
48+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
4949
function setup() {
5050
5151
}
@@ -62,7 +62,7 @@ function draw() {
6262
<span class='try'>Try making your canvas different sizes by changing the width and height.</span>
6363
</p>
6464

65-
<script type="text/p5" data-height="400" data-preview-width="300">
65+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
6666
function setup() {
6767
createCanvas(100, 100)
6868
}
@@ -78,7 +78,7 @@ function draw() {
7878
<img src='{{assets}}/learn/basics/line.svg'>
7979
</p>
8080

81-
<script type="text/p5" data-height="400" data-preview-width="300">
81+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
8282
function setup() {
8383
createCanvas(300, 300)
8484
}
@@ -95,7 +95,7 @@ function draw() {
9595
<img src='{{assets}}/learn/basics/rect.svg'>
9696
</p>
9797

98-
<script type="text/p5" data-height="400" data-preview-width="300">
98+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
9999
function setup() {
100100
createCanvas(300, 300)
101101
}
@@ -115,7 +115,7 @@ function draw() {
115115
<img src='{{assets}}/learn/basics/ellipse.svg'>
116116
</p>
117117

118-
<script type="text/p5" data-height="400" data-preview-width="300">
118+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
119119
function setup() {
120120
createCanvas(300, 300)
121121
}
@@ -129,7 +129,7 @@ function draw() {
129129
<h2>fill(red, green, blue)</h2>
130130
<p>You can set the color of your shapes by using fill(). You give it three numbers – the red, green, and blue mixture you want, just like background.
131131
</p>
132-
<script type="text/p5" data-height="400" data-preview-width="300">
132+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
133133
function setup() {
134134
createCanvas(300, 300)
135135
}
@@ -139,12 +139,12 @@ function draw() {
139139
fill(255, 0, 0)
140140
ellipse(150, 150, 50, 50)
141141
}
142-
</script>
142+
</script>
143143

144144
<h2>stroke(red, green, blue)</h2>
145145
<p>You can set the outline color of your shapes by using stroke(). You give it three numbers – the red, green, and blue mixture you want, just like fill() and background().
146146
</p>
147-
<script type="text/p5" data-height="400" data-preview-width="300">
147+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
148148
function setup() {
149149
createCanvas(300, 300)
150150
}
@@ -160,7 +160,7 @@ function draw() {
160160
<h2>strokeWeight(weight)</h2>
161161
<p>You can set the thickness of the outline for your shapes by using strokeWeight(). The default stroke weight is 1.
162162
</p>
163-
<script type="text/p5" data-height="400" data-preview-width="300">
163+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
164164
function setup() {
165165
createCanvas(300, 300)
166166
}
@@ -176,7 +176,7 @@ function draw() {
176176
<p>mouseX and mouseY can be used to get the current position of your mouse. They are called <b>variables</b>. You can replace a number in your code with mouseX or mouseY and that number will change as you move your mouse.
177177
</p>
178178

179-
<script type="text/p5" data-height="400" data-preview-width="300">
179+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
180180
function setup() {
181181
createCanvas(300, 300)
182182
}
@@ -190,7 +190,7 @@ function draw() {
190190
<h2>random(max)</h2>
191191
<p>random() will choose a random number for you, anywhere from 0 - max.</p>
192192

193-
<script type="text/p5" data-height="400" data-preview-width="300">
193+
<script type="text/p5" data-height="400" data-preview-width="300" data-p5-version="{{ version }}">
194194
function setup() {
195195
createCanvas(300, 300)
196196
}

src/templates/pages/learn/color.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ slug: learn/
3939

4040
<!-- this script only needs to get added once even if there are multiple widget instances -->
4141
<script src="//toolness.github.io/p5.js-widget/p5-widget.js"></script>
42-
<script type="text/p5" data-autoplay>
42+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
4343
function draw() {
4444
background(150);
4545
stroke(0);
@@ -69,7 +69,7 @@ slug: learn/
6969

7070
<p>{{#i18n "color-rgb-p2x1"}}{{/i18n}}</p>
7171

72-
<script type="text/p5" data-autoplay>
72+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
7373
function draw() {
7474
background(255);
7575
noStroke();
@@ -97,7 +97,7 @@ function draw() {
9797

9898
<p>{{#i18n "color-transparency-p3x1"}}{{/i18n}}</p>
9999

100-
<script type="text/p5" data-autoplay>
100+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
101101
createCanvas(100, 100);
102102
fill(0,0,255);
103103
rect(0,0,50,100);

src/templates/pages/learn/coordinate-system-and-shapes.hbs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ slug: learn/
4040
<p>{{#i18n "coordinate-system-simple-shapes-p3x1"}}{{/i18n}}<a href="/reference/#/p5/point">point()</a>{{#i18n "coordinate-system-simple-shapes-p3x2"}}{{/i18n}}</p>
4141
<!-- this script only needs to get added once even if there are multiple widget instances -->
4242
<script src="//toolness.github.io/p5.js-widget/p5-widget.js"></script>
43-
<script type="text/p5" data-autoplay>
43+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
4444
function setup(){
4545
createCanvas(100, 100);
4646
}
@@ -50,7 +50,7 @@ function draw(){
5050
</script>
5151

5252
<p>{{#i18n "coordinate-system-simple-shapes-p4x1"}}{{/i18n}}<a href="/reference/#/p5/line">line()</a>{{#i18n "coordinate-system-simple-shapes-p4x2"}}{{/i18n}}</p>
53-
<script type="text/p5" data-autoplay>
53+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
5454
function setup(){
5555
createCanvas(100, 100);
5656
}
@@ -60,7 +60,7 @@ function draw(){
6060
</script>
6161

6262
<p>{{#i18n "coordinate-system-simple-shapes-p5x1"}}{{/i18n}}<a href="/reference/#/p5/rect">rect()</a>{{#i18n "coordinate-system-simple-shapes-p5x2"}}{{/i18n}}</p>
63-
<script type="text/p5" data-autoplay>
63+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
6464
function setup(){
6565
createCanvas(100, 100);
6666
}
@@ -70,7 +70,7 @@ function draw(){
7070
</script>
7171

7272
<p>{{#i18n "coordinate-system-simple-shapes-p6x1"}}{{/i18n}}<a href="/reference/#/p5/CENTER">CENTER</a>{{#i18n "coordinate-system-simple-shapes-p6x2"}}{{/i18n}}</p>
73-
<script type="text/p5" data-autoplay>
73+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
7474
function setup(){
7575
createCanvas(100, 100);
7676
rectMode(CENTER);
@@ -81,7 +81,7 @@ function draw(){
8181
</script>
8282

8383
<p>{{#i18n "coordinate-system-simple-shapes-p7x1"}}{{/i18n}}<a href="/reference/#/p5/CORNERS">CORNERS</a>{{#i18n "coordinate-system-simple-shapes-p7x2"}}{{/i18n}}</p>
84-
<script type="text/p5" data-autoplay>
84+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
8585
function setup(){
8686
createCanvas(100, 100);
8787
rectMode(CORNERS);
@@ -92,7 +92,7 @@ function draw(){
9292
</script>
9393

9494
<p>{{#i18n "coordinate-system-simple-shapes-p8x1"}}{{/i18n}}<a href="/reference/#/p5/ellipse">ellipse()</a>{{#i18n "coordinate-system-simple-shapes-p8x2"}}{{/i18n}}<a href="/reference/#/p5/rect">rect()</a>{{#i18n "coordinate-system-simple-shapes-p8x3"}}{{/i18n}}<a href="/reference/#/p5/ellipse">ellipse()</a>{{#i18n "coordinate-system-simple-shapes-p8x4"}}{{/i18n}}<a href="/reference/#/p5/CENTER">CENTER</a>{{#i18n "coordinate-system-simple-shapes-p8x5"}}{{/i18n}}<a href="/reference/#/p5/CORNER">CORNER</a>{{#i18n "coordinate-system-simple-shapes-p8x6"}}{{/i18n}}</p>
95-
<script type="text/p5" data-autoplay>
95+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
9696
function setup(){
9797
createCanvas(100, 100);
9898
ellipseMode(CENTER);
@@ -102,7 +102,7 @@ function draw(){
102102
}
103103
</script>
104104

105-
<script type="text/p5" data-autoplay>
105+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
106106
function setup(){
107107
createCanvas(100, 100);
108108
ellipseMode(CORNER);
@@ -112,7 +112,7 @@ function draw(){
112112
}
113113
</script>
114114

115-
<script type="text/p5" data-autoplay>
115+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
116116
function setup(){
117117
createCanvas(100, 100);
118118
ellipseMode(CORNERS);
@@ -124,7 +124,7 @@ function draw(){
124124

125125
<p>{{#i18n "coordinate-system-simple-shapes-p9x1"}}{{/i18n}}</p>
126126

127-
<script type="text/p5" data-autoplay>
127+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
128128
function setup(){
129129
createCanvas(200, 200);
130130
rectMode(CENTER);

src/templates/pages/learn/curves.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ slug: learn/
4040

4141
<!-- this script only needs to get added once even if there are multiple widget instances -->
4242
<script src="//toolness.github.io/p5.js-widget/p5-widget.js"></script>
43-
<script type="text/p5" data-autoplay>
43+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
4444
function draw() {
4545
createCanvas(150,200);
4646
background(150);
@@ -92,7 +92,7 @@ slug: learn/
9292
</p>
9393

9494

95-
<script type="text/p5" data-autoplay>
95+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
9696
let coords = [40, 40, 80, 60, 100, 100, 60, 120, 50, 150];
9797
9898
function setup() {
@@ -158,7 +158,7 @@ slug: learn/
158158
the last point of A, and the first control point of B have to be on a straight line.
159159
</P>
160160

161-
<script type="text/p5" data-autoplay>
161+
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
162162
function setup() {
163163
createCanvas(150,200);
164164
}

0 commit comments

Comments
 (0)