Skip to content

Commit f4526fa

Browse files
author
Josh Lory
committed
Merge branch 'staging' into icon-color-picker
Conflicts: apps/src/applab/designElements/button.jsx
2 parents ba63a4d + 42b176a commit f4526fa

File tree

121 files changed

+2090
-1473
lines changed

Some content is hidden

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

121 files changed

+2090
-1473
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ crowdin.yaml
3333
/apps/build
3434
/apps/node_modules/
3535
/apps/npm-debug.log
36+
/apps/src/color.js
3637
*_temp.json
3738
/.ruby-version
3839
/levelbuilder_ci_last_run

.haml-lint.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ linters:
88
ClassesBeforeIds:
99
enabled: false
1010

11-
ConsecutiveComments:
12-
enabled: false
13-
1411
ConsecutiveSilentScripts:
1512
enabled: false
1613

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ gem 'dalli' # memcached
2121
gem 'parallel'
2222

2323
gem 'google-api-client'
24+
gem 'sprockets-derailleur' # Multi-cpu assets precompile
2425

2526
gem 'crowdin-cli'
2627

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,8 @@ GEM
469469
multi_json (~> 1.0)
470470
rack (~> 1.0)
471471
tilt (~> 1.1, != 1.3.0)
472+
sprockets-derailleur (0.0.9)
473+
sprockets (~> 2)
472474
sprockets-rails (2.3.3)
473475
actionpack (>= 3.0)
474476
activesupport (>= 3.0)
@@ -630,6 +632,7 @@ DEPENDENCIES
630632
sinatra
631633
spring
632634
spring-commands-testunit
635+
sprockets-derailleur
633636
sqlite3
634637
stringex (~> 2.5.2)
635638
therubyracer (~> 0.12.2)

STYLEGUIDE.md

Lines changed: 116 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Style Guide {
1+
# Style Guide
22

33
## Prelude
44
We try to maintain a consistent style for two reasons:
@@ -217,6 +217,121 @@ Default: http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
217217
templates include a script tag which assigns app_options to
218218
a Javascript variable so that it as accessible from JS.
219219

220+
### React
221+
Our default style if not mentioned here should be that mentioned in the AirBnb guide https://github.com/airbnb/javascript/tree/master/react (perhaps with the exception of closing tags on their own line).
222+
* <a name="js-react-inline-styles"></a>
223+
Prefer single object for all styles vs. inlined style objects
224+
```jsx
225+
// Bad
226+
var component = (
227+
<div style={{color: 'red', display: 'block'}}>
228+
<div style={{color: 'blue', fontSize: 10}}>I'm a child</div>
229+
</div>
230+
);
231+
232+
// Good
233+
var styles = {
234+
root: {
235+
color: 'red',
236+
display: 'block
237+
},
238+
child: {
239+
color: 'blue',
240+
fontSize: 10
241+
}
242+
};
243+
...
244+
var component = (
245+
<div style={styles.root}>
246+
<div style={styles.child}>I'm a child</div>
247+
</div>
248+
);
249+
```
250+
* <a name="js-react-pixel-numbers"></a>
251+
Prefer numbers vs strings for pixel values
252+
```jsx
253+
// Bad
254+
var styles = {
255+
root: {
256+
width: '100px',
257+
height: '100px'
258+
}
259+
}'
260+
261+
// Good
262+
var styles = {
263+
root: {
264+
width: 100,
265+
height: 100
266+
}
267+
};
268+
```
269+
* <a name="js-react-long-components"></a>
270+
Components with many attributes should have one per line, with 4 spaces of indentation. Child components should have 2 spaces of indentation.
271+
```jsx
272+
// Bad
273+
var component = (
274+
<MyComponent param1={1} param2={2} param3={3} param4={4} param5={5}>
275+
<ChildComponent/>
276+
</MyComponent>
277+
);
278+
279+
// Good
280+
var component = (
281+
<MyComponent
282+
param1={1}
283+
param2={2}
284+
param3={3}
285+
param4={4}
286+
param5={5}>
287+
<ChildComponent/>
288+
</MyComponent>
289+
);
290+
```
291+
* <a name="jsx-child-elements-on-own-line"></a>
292+
Since JSX [removes newlines before rendering to HTML](http://andrewhfarmer.com/how-whitespace-works-in-jsx/)
293+
you can and should put child elements on their own line, instead of putting
294+
them on the same line to avoid extra spaces.
295+
296+
```
297+
// good
298+
<Component
299+
prop1="prop1"
300+
prop2="prop2">
301+
textContent
302+
</Component>
303+
304+
305+
// bad
306+
<Component
307+
prop1="prop1"
308+
prop2="prop2">textContent</Component>
309+
310+
// good - fine to put content on same line if the tag opens & closes on that line
311+
<Component>textContent</Component>
312+
```
313+
314+
* <a name="js-react-aligned-tags"></a>
315+
align open and close tags
316+
```jsx
317+
// Bad
318+
var component = (<MyComponent
319+
foo="bar"
320+
onClose={this.handleClose}>
321+
<ChildComponent/>
322+
</MyComponent>);
323+
324+
// Good
325+
var component = (
326+
<MyComponent
327+
foo="bar"
328+
onClose={this.handleClose}>
329+
<ChildComponent/>
330+
</MyComponent>
331+
);
332+
```
333+
334+
220335
### In /apps
221336
222337
Use lodash and jQuery libraries in `/apps`.
@@ -225,31 +340,6 @@ Use lodash and jQuery libraries in `/apps`.
225340
226341
Use Google Closure Tools in `/blockly-core`, especially for color conversion and keyboard identifiers. Prefer raw HTML over Closure Tools UI constructs for new code.
227342
228-
## JSX
229-
230-
* <a name="jsx-child-elements-on-own-line"></a>
231-
Since JSX [removes newlines before rendering to HTML](http://andrewhfarmer.com/how-whitespace-works-in-jsx/)
232-
you can and should put child elements on their own line, instead of putting
233-
them on the same line to avoid extra spaces.
234-
235-
```
236-
// good
237-
<Component
238-
prop1="prop1"
239-
prop2="prop2">
240-
textContent
241-
</Component>
242-
243-
244-
// bad
245-
<Component
246-
prop1="prop1"
247-
prop2="prop2">textContent</Component>
248-
249-
// good - fine to put content on same line if the tag opens & closes on that line
250-
<Component>textContent</Component>
251-
```
252-
253343
## CSS
254344
255345
Default: https://github.com/thoughtbot/guides/tree/master/style/sass
@@ -278,4 +368,3 @@ Default: http://google-styleguide.googlecode.com/svn/trunk/htmlcssguide.xml
278368
- Prefer double quotes for attributes.
279369
- Use dashes instead of underscores, camel casing, etc for separating words in IDs and classes.
280370
281-
# }

apps/Gruntfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ module.exports = function (grunt) {
350350

351351
config.exec = {
352352
browserify: 'echo "' + browserifyExec + '" && ' + browserifyExec,
353+
buildColorJs: './script/build-color-js.js',
353354
mochaTest: 'node test/util/runTests.js --color' + (fastMochaTest ? ' --fast' : '')
354355
};
355356

@@ -512,6 +513,7 @@ module.exports = function (grunt) {
512513
'checkDropletSize',
513514
'pseudoloc',
514515
'newer:messages',
516+
'exec:buildColorJs',
515517
'newer:copy:src',
516518
'newer:copy:lib',
517519
'locales',
@@ -545,6 +547,7 @@ module.exports = function (grunt) {
545547

546548
grunt.registerTask('mochaTest', [
547549
'newer:messages',
550+
'exec:buildColorJs',
548551
'newer:copy:static',
549552
'newer:concat',
550553
'exec:mochaTest'

apps/lib/blockly/sentinel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2016-03-15 20:43:26 +0000
1+
2016-03-17 01:38:25 +0000

apps/script/build-color-js.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env node
2+
// Script to generate color.js from color.scss
3+
var fs = require('fs');
4+
var path = require('path');
5+
var readline = require('readline');
6+
7+
var colorScssPath = path.resolve('../shared/css/color.scss');
8+
var colorJsPath = path.resolve('./src/color.js');
9+
10+
// Regular expression to capture a color definition from SCSS
11+
var colorRe = /\$(\w+)\s*:\s*([^;]+);/;
12+
var cachedColors = {};
13+
14+
// In color.scss some color definitions reference previous
15+
// color definitions. Since we're reading them in order,
16+
// we can recursively resolve these referential defintions
17+
// until we land on an actual color.
18+
function resolveColor(value) {
19+
var originalValue = value;
20+
while (/^\$/.test(value)) {
21+
value = cachedColors[value.substring(1)];
22+
}
23+
return value;
24+
}
25+
26+
// Generate color.js while reading color.scss line-by-line
27+
var out = fs.createWriteStream(colorJsPath);
28+
out.write([
29+
'// color.js',
30+
'// GENERATED FILE: DO NOT MODIFY DIRECTLY',
31+
'// This generated file exports all colors defined in color.scss',
32+
'// for use in JavaScript. The generator script is build-color-js.js',
33+
'module.exports = {\n'
34+
].join('\n'));
35+
36+
var rl = readline.createInterface({
37+
input: fs.createReadStream(colorScssPath),
38+
terminal: false
39+
});
40+
41+
var currentLine = 0;
42+
rl.on('line', function (line) {
43+
currentLine++;
44+
var match = colorRe.exec(line);
45+
if (match === null) {
46+
return;
47+
}
48+
49+
var colorName = match[1];
50+
var colorValue = resolveColor(match[2]);
51+
if (typeof colorValue === 'undefined') {
52+
throw new Error([
53+
'Unable to resolve color ' + colorName,
54+
colorScssPath + ':' + currentLine,
55+
line,
56+
' ^'
57+
].join('\n'));
58+
}
59+
cachedColors[colorName] = colorValue;
60+
61+
out.write(' ' + colorName + ': "' + colorValue + '",\n');
62+
});
63+
rl.on('close', function () {
64+
out.write('};\n');
65+
});
66+

0 commit comments

Comments
 (0)