GitXplorerGitXplorer
a

riotjs-rails

public
26 stars
15 forks
1 issues

Commits

List of commits on branch master.
Unverified
4a4fbedd5a3e6049da868d08c207bd643179c5ff

Merge pull request #3 from marcioj/compile-tags

mmarcioj committed 10 years ago
Unverified
a37e950e2d3039426d4ae2e4dfb376612207dc5c

Updated README

mmarcioj committed 10 years ago
Unverified
cc1bb99161845ea95769049b86ba812a1f3219f6

Extract compiler to your own class and use escape_javascript

mmarcioj committed 10 years ago
Unverified
0e2b39bff4699b13d5234b72e7d2f39970ff60d9

Compile riot tags in asset pipeline

mmarcioj committed 10 years ago
Unverified
d1ecd4297063d8baecfbce93413945908393fe43

Merge pull request #2 from marcioj/update-javascript

aadambutler committed 10 years ago
Unverified
08fd765a7d757e1d381ea8cfc7d375301110e910

Added line break

mmarcioj committed 10 years ago

README

The README file for this repository.

riotjs-rails Gem Version

About

Rails 3.1+ asset-pipeline gem to provide riot.js

Prerequisite

You should install nodejs for riot.js compilation work

Setup

Have in your Gemfile:

gem 'riotjs-rails'

And, have in your application.js manifest:

//= require riot

Usage

You can create a tag by including a file in app/assets/javascripts, this file must end with .tag.

The name of the file will be used as the tag name, so let's say we want to create a timer.tag.

All we need to do is create a file called app/assets/javascripts/timer.tag:

<timer>

  <p>Seconds Elapsed: { time }</p>

  this.time = opts.start || 0

  this.tick = function() {
    this.update({ time: ++this.time })
  }

  var timer = setInterval(this.tick.bind(this), 1000)

  this.on("unmount", function() {
    clearInterval(timer)
  })

</timer>

After, we mount the tag using riot.mount('timer') where we want to use it.

For instance in your application.js:

//= require jquery
//= require jquery_ujs
//= require riot
//= require_tree .

$(function() {
  riot.mount('timer');
});

And then include the tag adding <timer></timer> in your html.

You should see Seconds Elapsed: 0 changing the number after each second.

Contributing

Contributions are welcome, please follow GitHub Flow