-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from plaid/dc-everything
everything
- Loading branch information
Showing
18 changed files
with
15,385 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"bitwise": false, | ||
"camelcase": false, | ||
"curly": false, | ||
"eqeqeq": true, | ||
"forin": false, | ||
"freeze": false, | ||
"immed": true, | ||
"indent": 2, | ||
"latedef": false, | ||
"newcap": false, | ||
"noarg": true, | ||
"noempty": true, | ||
"nonew": true, | ||
"plusplus": true, | ||
"undef": true, | ||
"unused": "vars", | ||
"strict": false, | ||
"asi": false, | ||
"boss": false, | ||
"debug": false, | ||
"eqnull": true, | ||
"esnext": true, | ||
"evil": false, | ||
"expr": false, | ||
"funcscope": false, | ||
"globalstrict": false, | ||
"iterator": false, | ||
"lastsemic": false, | ||
"laxbreak": false, | ||
"laxcomma": false, | ||
"loopfunc": false, | ||
"moz": false, | ||
"multistr": false, | ||
"notypeof": false, | ||
"proto": false, | ||
"scripturl": false, | ||
"shadow": false, | ||
"sub": false, | ||
"supernew": false, | ||
"validthis": false, | ||
"nonstandard": true, | ||
"browser": false, | ||
"es3": false, | ||
"node": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sanctuary.js.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Contributing | ||
|
||
1. Update local gh-pages branch: | ||
|
||
$ git checkout gh-pages | ||
$ git pull upstream gh-pages | ||
|
||
2. Create feature branch: | ||
|
||
$ git checkout -b feature-x | ||
|
||
3. Make one or more atomic commits, and ensure that each commit has a | ||
descriptive commit message. Commit messages should be line wrapped | ||
at 72 characters. | ||
|
||
4. Run `make` to build the site. This requires a recent version of Node. | ||
|
||
5. Review the changes in a browser. | ||
|
||
6. Run `make test lint`, and address any errors. Preferably, fix commits | ||
in place using `git rebase` or `git commit --amend` to make the changes | ||
easier to review. | ||
|
||
7. Push: | ||
|
||
$ git push origin feature-x | ||
|
||
8. Open a pull request. Include screenshots if applicable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
JSHINT = node_modules/.bin/jshint | ||
NPM = npm | ||
|
||
CUSTOM = $(shell find custom -name '*.md' | sort) | ||
VENDOR = ramda sanctuary sanctuary-def | ||
VENDOR_CHECKS = $(patsubst %,check-%-version,$(VENDOR)) | ||
FILES = index.html $(patsubst %,vendor/%.js,$(VENDOR)) | ||
|
||
|
||
.PHONY: all | ||
all: $(FILES) | ||
|
||
index.html: scripts/generate node_modules/sanctuary/README.md $(CUSTOM) | ||
'$<' node_modules/sanctuary | ||
|
||
vendor/ramda.js: node_modules/ramda/dist/ramda.js | ||
cp '$<' '$@' | ||
|
||
vendor/%.js: node_modules/%/index.js | ||
cp '$<' '$@' | ||
|
||
|
||
.PHONY: $(VENDOR_CHECKS) | ||
$(VENDOR_CHECKS): check-%-version: | ||
node -e 'require("assert").strictEqual(require("$*/package.json").version, require("./package.json").dependencies["$*"])' | ||
|
||
|
||
.PHONY: clean | ||
clean: $(FILES) | ||
rm -f -- $^ | ||
|
||
|
||
.PHONY: lint | ||
lint: scripts/generate behaviour.js | ||
$(JSHINT) -- $^ | ||
make clean | ||
make | ||
git diff --exit-code | ||
|
||
|
||
.PHONY: setup | ||
setup: | ||
$(NPM) update | ||
|
||
|
||
.PHONY: test | ||
test: $(VENDOR_CHECKS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# sanctuary-site | ||
|
||
Build script and files for the [Sanctuary][1] website. | ||
|
||
|
||
[1]: https://github.com/plaid/sanctuary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* jshint browser: true */ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
var R = window.R; | ||
var S = window.S = window.sanctuary; | ||
|
||
// evaluate :: String -> Either String Any | ||
var evaluate = | ||
S.encaseEither(R.prop('message'), | ||
S.pipe([R.replace(/^const ([^ ]*) = (.*)/, | ||
'(window.$1 = $2), undefined'), | ||
R.concat('return '), | ||
R.construct(Function), | ||
R.call])); | ||
|
||
// hasClass :: String -> Element -> Boolean | ||
var hasClass = function(className) { | ||
return function(el) { | ||
return el.nodeType === 1 && | ||
S.words(el.className).indexOf(className) >= 0; | ||
}; | ||
}; | ||
|
||
// evaluateForm :: Element -> Undefined | ||
var evaluateForm = function(el) { | ||
var input = el.getElementsByTagName('input')[0]; | ||
var output = el.getElementsByClassName('output')[0]; | ||
|
||
S.either(function(s) { | ||
output.setAttribute('data-error', 'true'); | ||
output.textContent = '! ' + s; | ||
}, | ||
function(x) { | ||
output.setAttribute('data-error', 'false'); | ||
output.textContent = R.toString(x); | ||
}, | ||
evaluate(input.value)); | ||
}; | ||
|
||
// evaluateForms :: Element -> Undefined | ||
var evaluateForms = function(el) { | ||
R.forEach(evaluateForm, el.getElementsByTagName('form')); | ||
}; | ||
|
||
evaluateForms(document.body); | ||
|
||
// The first time the user moves her mouse over the first example, select | ||
// the "words" to suggest that the text is editable. Note that "mouseover" | ||
// is unsuitable as the cursor may already be over the first example. | ||
var firstExample = document.body.getElementsByClassName('examples')[0]; | ||
document.body.addEventListener('mousemove', function selectWords(event) { | ||
var el = event.target; | ||
while (el !== document.body) { | ||
if (el === firstExample) { | ||
var input = firstExample.getElementsByTagName('input')[0]; | ||
input.focus(); | ||
input.setSelectionRange(input.value.indexOf('[') + 1, | ||
input.value.indexOf(']'), | ||
'forward'); | ||
document.body.removeEventListener('mousemove', selectWords, false); | ||
} | ||
el = el.parentNode; | ||
} | ||
}, false); | ||
|
||
document.body.addEventListener('click', function(event) { | ||
// Dragging a selection triggers a "click" event. Selecting the | ||
// output text (for copying) should not focus the input element. | ||
if (window.getSelection().isCollapsed) { | ||
var el = event.target; | ||
while (el.tagName !== 'INPUT' && el !== document.body) { | ||
if (hasClass('examples')(el)) { | ||
var input = el.getElementsByTagName('input')[0]; | ||
input.focus(); | ||
// Move the caret to the end of the text. | ||
input.value = input.value; | ||
break; | ||
} | ||
el = el.parentNode; | ||
} | ||
} | ||
}, false); | ||
|
||
document.body.addEventListener('submit', function(event) { | ||
if (event.target.tagName === 'FORM') { | ||
event.preventDefault(); | ||
evaluateForms(event.target.parentNode); | ||
} | ||
}, false); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
dependencies: | ||
override: | ||
- make setup | ||
|
||
machine: | ||
node: | ||
version: 4.2.2 | ||
|
||
test: | ||
override: | ||
- make test lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
In JavaScript it's trivial to introduce a possible run-time type error: | ||
|
||
words[0].toUpperCase() | ||
|
||
If `words` is `[]` we'll get a familiar error at run-time: | ||
|
||
TypeError: Cannot read property 'toUpperCase' of undefined | ||
|
||
Sanctuary gives us a fighting chance of avoiding such errors. We might | ||
write: | ||
|
||
R.map(R.toUpper, S.head(words)) | ||
|
||
=============================================================================== | ||
|
||
In JavaScript it's trivial to introduce a possible run-time type error. | ||
|
||
Try changing `words` to `[]` in the REPL below. Hit _return_ to re-evaluate. | ||
|
||
```javascript | ||
> words = ['foo', 'bar', 'baz'] | ||
undefined | ||
|
||
> words[0].toUpperCase() | ||
"FOO" | ||
|
||
> R.map(S.toUpper, S.head(words)) | ||
Nothing("FOO") | ||
``` | ||
|
||
`R` is Ramda; `S` is Sanctuary. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```javascript | ||
R.inc('XXX'); | ||
// => '1XXX' | ||
``` | ||
|
||
=============================================================================== | ||
|
||
```javascript | ||
> R.inc('XXX') | ||
'1XXX' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
```javascript | ||
S.inc('XXX'); | ||
// ! TypeError: ‘inc’ expected a value of type FiniteNumber as its first argument; received "XXX" | ||
``` | ||
|
||
=============================================================================== | ||
|
||
```javascript | ||
> S.inc('XXX') | ||
! ‘inc’ expected a value of type FiniteNumber as its first argument; received "XXX" | ||
``` |
Oops, something went wrong.