Project

racovi

0.0
No commit activity in last 3 years
No release in over 3 years
Use Hevents (https://github.com/yarmand/hevents) to create JS init function for Rails controllers and views. Provide helper to setup handlers in your Rails code
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 1.0.0
>= 1.8.3
>= 3.12
>= 2.8.0

Runtime

>= 3.1.0
 Project Readme

racovi

Build Status

racovi is a gem to register initialization code for your javascript which is executed only for the current controller and view.

I created that to easily deploy what is explain in this blog post.

racovi is based on the javascript event stack Hevents.

** Important Note ** : This is a early version of the gem and still need some manual installations in your Rails application. But javascript code works

Usage

Prepare your Rails layout

Put the helper function init_view_js wherever you want in your layouts, it will add a $(document).ready(…) section calling initializer code for the current controller and the current view.

for example

/** application.html.haml **/
…
= init_view_js
…

Prepare your application.js

add these line to your app/assets/javascript/application.js

//= require hevents
//= require racovi

Register an initializer code

use register_init(names,fun) in your controller or view js files

/** assets/javascript/persons.js **/
…
Racovi.register_init('persons', function(){
  console.log('hello from Person controller')
});
…

_

/** assets/javascript/persons.js.coffee **/
…
Racovi.register_init 'persons', () ->
  console.log('hello from Person controller')
…

register initializer for multiple views

/** assets/javascript/persons.js.coffee **/
...
Racovi.register_init ['persons_new','persons_edit'], () ->
  console.log('editing a Person')
…

cumulative initializer for complex views

If you have complex view GUI distributed on multiple sources files, independent from each others, you can register multiple time the same initializer name, all registered functions will be called.

/** assets/javascript/sidebar.js.coffee **/
…
Racovi.register_init 'persons', () ->
	('#persons_menu').show()
…
/** assets/javascript/persons.js.coffee **/
...
Racovi.register_init 'persons', () ->
  console.log('hello from Person controller')
...

TODO

  • automatically add hevents and racovi in application.js
  • automatically add init_view_js to layouts
  • make optioneal usage of $document.ready(…)
  • add generic helpers to init whatever event

Contributing to racovi

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2012 yann ARMAND under MIT See LICENSE.txt for further details.