Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

everything #2

Merged
merged 1 commit into from
Mar 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
46 changes: 46 additions & 0 deletions .jshintrc
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
}
1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sanctuary.js.org
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
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.
47 changes: 47 additions & 0 deletions Makefile
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)
6 changes: 6 additions & 0 deletions README.md
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
94 changes: 94 additions & 0 deletions behaviour.js
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);

}());
11 changes: 11 additions & 0 deletions circle.yml
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
31 changes: 31 additions & 0 deletions custom/introduction.md
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.
11 changes: 11 additions & 0 deletions custom/type-checking-ramda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```javascript
R.inc('XXX');
// => '1XXX'
```

===============================================================================

```javascript
> R.inc('XXX')
'1XXX'
```
11 changes: 11 additions & 0 deletions custom/type-checking-sanctuary.md
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"
```
Loading