Giter VIP home page Giter VIP logo

riotjs-rails's Introduction

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

riotjs-rails's People

Contributors

adambutler avatar marcioj avatar

Watchers

Steve avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.