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

Update 60-second setup.md #30

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
9df73c6
Fixed 404 links, transitions, partials
Jan 23, 2014
97939bf
Merge pull request #16 from quangv/master
Rich-Harris Feb 9, 2014
b9bab3b
move render task into tasks/ folder
Rich-Harris Feb 9, 2014
9c37e1e
add edit link to all pages
Rich-Harris Feb 9, 2014
5a15a9e
add @lluchs slip decorator (nuked after wiki migration)
Rich-Harris Feb 9, 2014
711720f
add back @antonbloom fixes (nuked by wiki migration)
Rich-Harris Feb 9, 2014
f34503b
Add back @azu typo fix (nuked by wiki migration)
Rich-Harris Feb 9, 2014
82485b1
Merge branch 'master' of https://github.com/RactiveJS/docs.ractivejs.org
Rich-Harris Feb 9, 2014
c38a19f
fix links
Rich-Harris Feb 9, 2014
33aea0b
remove reference to wiki
Rich-Harris Feb 9, 2014
e32340a
Merge branch 'master' of https://github.com/RactiveJS/docs.ractivejs.org
Rich-Harris Feb 9, 2014
31983bb
typos
Rich-Harris Feb 9, 2014
3f9b1cb
Merge branch 'master' of https://github.com/RactiveJS/docs.ractivejs.org
Rich-Harris Feb 9, 2014
df811c9
broken link
Rich-Harris Feb 9, 2014
e1f2e97
broken link (#9)
Rich-Harris Feb 9, 2014
6e71107
broken links (#9)
Rich-Harris Feb 9, 2014
6a66476
broken link (#9)
Rich-Harris Feb 9, 2014
678368d
broken link (#9)
Rich-Harris Feb 9, 2014
1de2038
broken links (#9)
Rich-Harris Feb 9, 2014
4415da3
broken link (#9)
Rich-Harris Feb 9, 2014
8c5475e
broken link (#9)
Rich-Harris Feb 9, 2014
f2e72a6
broken link (#9)
Rich-Harris Feb 9, 2014
37e032e
broken link (#9)
Rich-Harris Feb 9, 2014
799ed76
broken link (#9)
Rich-Harris Feb 9, 2014
dd4d51b
broken link (#9)
Rich-Harris Feb 9, 2014
44f0bbf
Merge branch 'master' of https://github.com/RactiveJS/docs.ractivejs.org
Rich-Harris Feb 9, 2014
e59d1f6
update gitignore
Rich-Harris Feb 9, 2014
ea76258
broken link (#9)
Rich-Harris Feb 9, 2014
bd2065f
typo
Rich-Harris Feb 9, 2014
c918552
typo
Rich-Harris Feb 9, 2014
453f54e
broken link (#9)
Rich-Harris Feb 9, 2014
ccf0fbb
typo
Rich-Harris Feb 9, 2014
e64e7a7
typo
Rich-Harris Feb 9, 2014
58cc512
broken link
Rich-Harris Feb 9, 2014
ccf6bf6
update events info
Rich-Harris Feb 9, 2014
8fcfdab
Remove object keys with dots in them (what was I thinking?)
Rich-Harris Feb 11, 2014
d7eaabc
Merge branch 'master' of https://github.com/RactiveJS/docs.ractivejs.org
Rich-Harris Feb 11, 2014
e3499dd
Additions and tweaks to expressions docs
mikemaccana Feb 12, 2014
4a83a40
Merge pull request #25 from mikemaccana/patch-1
Rich-Harris Feb 12, 2014
234d1e5
Add @cfenzo's minmaxwidth plugin
Rich-Harris Feb 12, 2014
20cddd0
Add decorators to glossary
codler Feb 12, 2014
3f426fb
Merge pull request #26 from codler/patch-1
Rich-Harris Feb 12, 2014
aff9a75
Order by alphabetical
codler Feb 12, 2014
fbd90b5
Merge pull request #27 from codler/patch-2
Rich-Harris Feb 12, 2014
71437ed
first attempt at a Travis CI auto-deploy script
Rich-Harris Feb 13, 2014
63dd89c
fixed .travis.yml
Rich-Harris Feb 13, 2014
d605d33
chmod deploy script before running
Rich-Harris Feb 13, 2014
8125683
argh
Rich-Harris Feb 13, 2014
411dec9
here travis, try this
Rich-Harris Feb 13, 2014
147b6b3
remember to build BEFORE deploying...
Rich-Harris Feb 13, 2014
86a0865
lint yml. (sorry to anyone getting spammed as I try to figure this ou…
Rich-Harris Feb 13, 2014
e83e802
more debugging
Rich-Harris Feb 13, 2014
c445225
try using cp instead of grunt copy
Rich-Harris Feb 13, 2014
7537ce1
added deploy sequence back in
Rich-Harris Feb 13, 2014
6437b3f
dont deploy from a PR!
Rich-Harris Feb 13, 2014
3e49948
innocuous change to test Travis CI deployment to gh-pages
Feb 13, 2014
1bb93aa
copy recursively. doh
Rich-Harris Feb 13, 2014
df038f8
Merge branch 'master' of https://github.com/RactiveJS/docs.ractivejs.org
Rich-Harris Feb 13, 2014
cbd999e
use grunt-sass instead of grunt-contrib-sass, so we can stay in node …
Rich-Harris Feb 13, 2014
b89e93c
could this be the one?
Rich-Harris Feb 13, 2014
8807df7
ugh
Rich-Harris Feb 13, 2014
99293fd
nope
Rich-Harris Feb 13, 2014
13523bf
another innocuous change from non-collaborator, to test PR workflow
emma-f Feb 13, 2014
489461b
Merge pull request #28 from emma-f/patch-1
Feb 13, 2014
1d61810
update secure token
Rich-Harris Feb 18, 2014
3ca679d
Update 60-second setup.md
Rich-Harris Mar 20, 2014
118488e
typo
Rich-Harris Mar 20, 2014
6cdc0ed
Update 60-second setup.md
Mar 26, 2014
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules
tmp
build
.sass-cache
.sass-cache
deploy.sh
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "0.10"
before_script:
- npm install -g grunt-cli; chmod u+x deploy-to-gh-pages.sh; grunt build
script: ./deploy-to-gh-pages.sh
env:
global:
- GH_REF: github.com/RactiveJS/docs.ractivejs.org.git
- secure: AXOggwbE9d5bcLlAXQrpjc7EQz0qgpkYI8JICzNFwh9I7pqDy1BAg1nC8nc0c1Pyd/HTZH+4hkSO3vjuffTEdV7Nb/gEqo2Wu8lnB/NfAx6bNvMPK0rp54qc9kLr93m0i0ttDDnT3XoLdY7c9T3AFWHTF4c8y9ihvAqx+f4LaB8=
151 changes: 7 additions & 144 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function ( grunt ) {

docs: {
files: 'docs/**/*',
tasks: [ 'dir2json', 'render' ]
tasks: [ 'spelunk', 'render' ]
}
},

Expand All @@ -37,7 +37,7 @@ module.exports = function ( grunt ) {
files: [ 'build/', 'tmp/' ]
},

dir2json: {
spelunk: {
posts: {
root: 'docs',
dest: 'tmp/docs.json'
Expand All @@ -57,95 +57,12 @@ module.exports = function ( grunt ) {
});

grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-contrib-sass' );
grunt.loadNpmTasks( 'grunt-sass' );
grunt.loadNpmTasks( 'grunt-contrib-clean' );
grunt.loadNpmTasks( 'grunt-contrib-copy' );
grunt.loadNpmTasks( 'grunt-dir2json' );


grunt.registerTask( 'render', function () {

var Ractive, docs, version, versionedDocs, pageName, slug, page, pages, slugs;

Ractive = require( 'ractive' );

docs = grunt.file.readJSON( 'tmp/docs.json' );

// render index page
render( 'index', {}, null, 'index' );

for ( version in docs ) {
versionedDocs = docs[ version ];
pages = [];
slugs = {};

for ( pageName in versionedDocs ) {
if ( pageName.charAt( 0 ) !== '_' ) {
page = processPage( versionedDocs[ pageName ], version, pageName, versionedDocs._home );
pages.push( page );

if ( slugs[ page.slug ] ) {
throw new Error( 'You cannot have multiple pages with the same slug (' + page.slug + ')' );
}
slugs[ page.slug ] = true;
}
}

pages.reverse();

// render individual posts
pages.forEach( renderPage.bind( null, version ) );

// render index
render( 'version-index', { home: versionedDocs._home }, version, 'index' );

// render page list
render( 'pages', { pages: pages }, version, 'pages' );
}

function renderPage ( version, page ) {
render( 'page', { page: page }, version, page.slug );
}

function writeFile ( version, fileName, content ) {
var path = [ 'build' ];
if ( version ) {
path.push( version );
}
path.push( fileName + '.html' );
grunt.file.write( path.join( '/' ), content );
}

function render ( templateName, data, version, fileName ) {
var cache, template, rendered, logMessage;

logMessage = [ "Rendering " ];
if ( version ) {
logMessage.push( version + "/" );
}
logMessage = logMessage.concat( fileName + ".html", " as [ ", templateName, " ]" );
console.log( logMessage.join( '' ) );


cache = render.cache || ( render.cache = {} );
template = cache[ templateName ] ||
( cache[ templateName ] = grunt.file.read( 'templates/' + templateName + '.html' ) );
rendered = new Ractive({
template: template,
data: data,
delimiters: [ '[[', ']]' ],
tripleDelimiters: [ '[[[', ']]]' ],
preserveWhitespace: true
}).toHTML();

writeFile( version, fileName, rendered );
if ( version === grunt.config( 'latest' ) ) {
writeFile( 'latest', fileName, rendered );
}
}

});
grunt.loadNpmTasks( 'grunt-spelunk' );

grunt.loadTasks( 'tasks' );

grunt.registerTask( 'default', [
'build',
Expand All @@ -154,64 +71,10 @@ module.exports = function ( grunt ) {

grunt.registerTask( 'build', [
'clean',
'dir2json',
'spelunk',
'render',
'sass',
'copy'
]);

};

function processPage ( page, version, name, homePath ) {
var markdown;

return {
version: version,
name: name,
slug: slugify( name ),
html: postprocess( require( 'marked' )( preprocessMarkdown( page, homePath ) ) )
};
}

function preprocessMarkdown ( markdown, homePath ) {

// breadcrumbs
markdown = markdown.replace( /^(.+)$/m, function ( match, breadcrumbs ) {
return '<div class="breadcrumbs">' + breadcrumbs.replace( / > /g, ' &raquo; ' ) + '</div>';
});

// specially treat [[Home]] link
markdown = markdown.replace( /\[\[Home\]\]/g, '[Home](' + homePath + ')' );

// turn [[My link]] into [My link](my-link)
markdown = markdown.replace( /\[\[([^\]]+)\]\]/g, function ( match, link ) {
return '[' + link + '](' + slugify( link ) + ')';
});

// process github-style code blocks
markdown = markdown.replace( /```([a-z]+)?\n([\s\S]+?)\n```/g, function ( match, language, content ) {
content = content
.replace( /\t/g, ' ' )
.replace( /</g, '&lt;' )
.replace( />/g, '&gt;' );

return '<pre' + ( language ? ' class="prettyprint lang-' + language + '"' : '' ) + '>' + content + '</pre>';
});

return markdown;
}

function postprocess ( html ) {
return html.replace( / - /g, ' &ndash; ' );
}

function slugify ( str ) {
if ( !str ) {
return '';
}
return str.toLowerCase()
.replace( /[^a-z]/g, '-' )
.replace( /-{2,}/g, '-' )
.replace( /^-/, '' )
.replace( /-$/, '' );
}
};
19 changes: 19 additions & 0 deletions deploy-to-gh-pages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# deploy script based on https://medium.com/philosophy-logic/53a8270e87db
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
echo "Deploy script running..."
( cd build
# grunt copy task doesn't seem to work here...
# cp -r ../root/* ./

git init
git config user.name "Travis-CI"
git config user.email "[email protected]"
git add .
git commit -m "Deployed to Github Pages"

echo "Pushing to gh-pages"
git push --force "https://${GH_TOKEN}@${GH_REF}" master:gh-pages > /dev/null 2>&1
)
fi
6 changes: 3 additions & 3 deletions docs/0.3.9/60-second setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Create a folder with a blank `index.html` page:
</html>
```

Download the [latest released version of Ractive.js](https://raw.github.com/RactiveJS/Ractive/master/Ractive.js) and put it in the same folder as `index.html`. Include it with a script tag just before the closing `</body>` tag:
Download the [latest released version](http://cdn.ractivejs.org/latest/Ractive.js) or the [latest released minified version of Ractive.js](http://cdn.ractivejs.org/latest/Ractive.min.js) and put it in the same folder as `index.html`. Include it with a script tag just before the closing `</body>` tag:

```html
<body>
Expand Down Expand Up @@ -79,10 +79,10 @@ Everything is in place to create a Ractive. Add another script tag at the bottom

Open the page in a browser. You should see a 'Hello, world!' message. If you open the console and type `ractive.set('recipient', 'Jim')` the text will update.

That's it - you're in business.
That's it - you're in business!

### Next steps

* You could pass in a template string as the `template` option, rather than the ID of a script tag containing the template. In that case, if your template is more than a couple of lines you'll probably want to keep it in a separate file and load it (e.g. with `$.ajax`, if you're using jQuery)
* As your app grows in complexity, you'll want to keep your application code (i.e. the bit that calls `new Ractive()`) in a separate file. You can also [use Ractive with RequireJS](using-ractive-with-requirejs).
* Work your way through the [tutorials](http://learn.ractivejs.org) to learn how to use Ractive. You can also consult the [[API reference]].
* Work your way through the [tutorials](http://learn.ractivejs.org) to learn how to use Ractive. You can also consult the [[API reference]].
12 changes: 6 additions & 6 deletions docs/0.3.9/API reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ Create a new Ractive instance. See [[Initialisation options]] for a breakdown of
## Instance properties

* [[ractive.nodes]]
* [ractive.transitions](ractive.transitions %28instance%29)
* [ractive.partials](ractive.partials %28instance%29)
* [[ractive.transitions (instance)]]
* [[Ractive.partials (instance)]]


## Instance events
Expand All @@ -42,8 +42,8 @@ See [[Events]].
## Plugins and shared properties

* [[Ractive.adaptors]]
* [[Ractive.eventDefinitions]]
* [[Ractive.events]]
* [[Ractive.easing]]
* [Ractive.partials](Ractive.partials %28global%29)
* [Ractive.transitions](Ractive.transitions %28global%29)
...more to come...
* [[Ractive.partials (global)]]
* [[Ractive.transitions (global)]]
...more to come...
2 changes: 1 addition & 1 deletion docs/0.3.9/Array modification.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ractive = new Ractive({
list.push( 'd' ); // adds a new list item - <li>d</li>
```

You can disable this behaviour by passing in `modifyArrays: false` as an [initialisation option](Initialisation options).
You can disable this behaviour by passing in `modifyArrays: false` as an [initialisation option](initialisation-options).


## How it works
Expand Down
2 changes: 1 addition & 1 deletion docs/0.3.9/Events.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Proxy event handlers receive an `event` argument. This isn't the same as the `ev

Because of the way proxy events work, they more or less eliminate the need for event delegation.

Any standard DOM event that an element supports can be used (e.g. `on-mouseover='highlight'`, `on-touchstart='dragstart'`, `on-blur='submit'`, `on-error='loadFallbackImage'`, and so on), as can non-standard events defined in [[Ractive.eventDefinitions]] such as `on-tap`.
Any standard DOM event that an element supports can be used (e.g. `on-mouseover='highlight'`, `on-touchstart='dragstart'`, `on-blur='submit'`, `on-error='loadFallbackImage'`, and so on), as can non-standard events defined in [[ractive-events]] such as `on-tap`.

*TODO - chained proxy events, additional arguments in custom event definitions*

Expand Down
31 changes: 22 additions & 9 deletions docs/0.3.9/Expressions.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[[Home]] > [[Glossary]] > [[Expressions]]

Expressions allow you to use logic within a template. At their simplest, that may just mean a basic arithmetic operation, such as converting to percentages, or making your [index references](Mustaches#index-references) start at 1 rather than 0:
Expressions allow you to use logic within a template. At their simplest, that may just mean a basic arithmetic operation, such as converting to percentages, but there are a variety of more complex uses, such as the examples below.

These examples are plucked from the air - whether they would be useful or not in real life depends on what you're trying to do. The point is that you can include more of your view logic at the declarative layer - the template - where it's easier to *reason about*.

## Examples

### Making your [index references](mustaches#index-references) start at 1 rather than 0:

```html
<div class='bar-chart'>
Expand All @@ -10,19 +16,29 @@ Expressions allow you to use logic within a template. At their simplest, that ma
</div>
```

Or it could mean formatting a currency so that `1.79` renders as `£1.79p`:
### Formatting a currency

In this case, so that `1.79` renders as `£1.79p`

```html
<p>Price: <strong>{{ format( price ) }}</strong></p>
```

Or it could mean adding a class based on some condition:
### Adding a class to an element based on a condition

```html
<a class='button {{ active ? "on" : "off" }}'>switch</a>
```

Or it could mean filtering a list to exclude certain records:
### A template section that depends on a condition

```
{{# status === 'running' }}
<p>Running</p>
{{/ end of filter }}
```

### Filtering a list to exclude certain records

```html
<ul>
Expand All @@ -32,9 +48,6 @@ Or it could mean filtering a list to exclude certain records:
</ul>
```

These are all examples casually plucked from the air - whether they would be useful or not in real life depends on what you're trying to do. The point is that you can include more of your view logic at the declarative layer - the template - where it's easier to *reason about*.


## Valid expressions

These are, of course, JavaScript expressions. Almost any valid JavaScript expression can be used, with a few exceptions:
Expand All @@ -44,7 +57,7 @@ These are, of course, JavaScript expressions. Almost any valid JavaScript expres
* No function literals (i.e. anything that involves the `function` keyword)
* No regular expression literals (this may change in future!)

Aside from a subset of global objects (e.g. `Math`, `Array`, `parseInt`, `encodeURIComponent` - full list below), any references must be to properties (however deeply nested) of the Ractive instance's data, rather than arbitrary variables. Reference resolution follows the [normal process](References).
Aside from a subset of global objects (e.g. `Math`, `Array`, `parseInt`, `encodeURIComponent` - full list below), any references must be to properties (however deeply nested) of the Ractive instance's data, rather than arbitrary variables. Reference resolution follows the [normal process](references).


## Does this use `eval`?
Expand Down Expand Up @@ -111,4 +124,4 @@ In regular mustache, we have something called the *implicit iterator* - `{{.}}`
* `null`
* `parseFloat`
* `parseInt`
* `undefined`
* `undefined`
21 changes: 11 additions & 10 deletions docs/0.3.9/Glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ Ractive aims to be as self-explanatory as possible - you shouldn't have to trawl

That said, if you're curious about some of the inner workings of Ractive, and want to better understand some of the concepts it uses, these pages may help.

* [[Mustaches]]
* [[References]]
* [[Keypaths]]
* [[Parallel DOM]]
* [[Adaptors]]
* [[Array modification]]
* [[Components]]
* [[Decorators]]
* [[Dependants]]
* [[Expressions]]
* [[Keypaths]]
* [[Magic mode]]
* [[Mustaches]]
* [[Observers]]
* [[Parallel DOM]]
* [[Partials]]
* [[References]]
* [[Templates]]
* [[Transitions]]
* [[Two‐way binding]]
* [[Templates]]
* [[Partials]]
* [[Adaptors]]
* [[Array modification]]
* [[Magic mode]]
* [[Components]]
Loading