Giter VIP home page Giter VIP logo

jsboot-rails's Introduction

Jsboot::Rails

A small solution for removing all inline javascript from your views.

This gem provides a small jsboot javascript file for use in the asset pipeline.

The basic principal is that rather than bootstrapping json with inline script tags, you use script tags of type application/json and include a json data structure inside the tag. The id for the tag is used to lookup a callback function to find the js to bootstrap for the page uniquely.

By not using inline javascript in your views, the gain is twofold:

  • You no longer clutter your html with script tags
  • More importantly, you can implement Content Security Policy to deny inline script tags, drastically narrowing the chance for XSS attacks against the site.

Installation

Add this line to your application's Gemfile:

gem 'jsboot-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install jsboot-rails

Usage

An example inclusion in your application.js file:

//= require jsboot

window.MyApp = {};
Jsboot(window.MyApp, jQuery);

MyApp.jsboot.on("posts#show", function(data) {
  console.log(data);
});

and in your view

# The data followed by a key, posts-show, used to build an id
# If no key is provided it will default to controller#action
<%= jsboot_data_tag({:foo => "bar"}, "posts#show") %>

The jsboot_data_tag is a helper provided that will convert objects to json. Passed data must respond to #to_json

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

jsboot-rails's People

Contributors

bemurphy avatar codegangsta avatar brentd avatar voodoogq avatar

Stargazers

 avatar

Watchers

Rob Christie avatar Bill Heaton avatar Andrew Olson avatar Charles Forcey avatar Kevin Compton avatar Justin Richard avatar Steve Hull avatar Jim Bishop avatar  avatar Kenny Rueter avatar Josh Orr avatar andrew dally avatar Sean Flannagan avatar Jason Carlin avatar Jared Loman avatar Weverton Timoteo avatar James Cloos avatar Kajabi CI avatar Christian Wensel avatar Ted Specht avatar Ken Grimm avatar Darrell Rivera avatar Devin avatar Jose Mendoza avatar Julian Skinner avatar JJ Kim avatar  avatar Justin Leveck avatar  avatar Matt Muldorf avatar Hunter Stewart avatar  avatar Jerome Johnson avatar Dylan Richards avatar Ben Hays avatar  avatar Sam Croswell avatar Julia Bazhukhina avatar Alex avatar Ryan Kortmann avatar Jordie Saenz avatar Kevin Dang avatar Tim Noeding avatar Nick Dome avatar Kai avatar Michelle Child avatar Christopher Yu avatar Goncharenko avatar Nick Lauwers avatar  avatar Court McFadzean avatar Ashley E avatar Katie Borisov avatar Abdullah Saeed avatar Forrest Holt avatar George avatar Phil Schanely avatar Aaron Newcomer avatar  avatar Doug Feltner avatar

jsboot-rails's Issues

.now should bypass document ready checks

we should be able to call .now (like .on) to have jsboot pull data from the dom and fire if need be, but not inside a document ready. This way we can prevent flicker, etc, in areas with more explicit control.

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.