Giter Club home page Giter Club logo

javascript_fu's Introduction

JavaScript Fu Rails Plugin

This plugin adds helpers, rake tasks, and rspec matchers for JavaScript development.

Installation

git clone git://github.com/osteele/javascript_fu.git vendor/plugins/javascript_fu

Extended Rake Tasks

The existing notes and statistics tasks are extended to compass the public/javascript directory:

rake statistics
rake notes

New View Helper

The new onload generator method generates code that executes the content of the block upon the completion of page load.

page.onload do
  page.call alert', 'page loaded!'
end

generates

Event.observe("window", "load", function() { alert("page loaded!"); });

or

$(document).ready(function() { alert("page loaded!"); });

New RSpec Matcher

Use these in your specs to verify that a view is calling a JavaScript function:

response.should call_js('fn')
response.should call_js('fn(true)')
response.should call_js('gApp.setup')

If there is a body, the arguments to the call are parsed (as JSON) and passed to it:

# response includes <script>...fn('string', 2)...</script>
response.should call_js(fn') do |args|
  args.should == ['string', 2]
end

If the “JCON” gem is installed, you can use this to test arguments values against ECMAScript 4.0 types:

'<script>fn("id", {x:1, y:2}, true)</script>'.should call_js('fn') do |args|
  args[0].should conform_to_js('string')
  args[1].should conform_to_js('{x:int, y:int}')
  args[2].should conform_to_js('boolean')
  # or:
  args.should conform_to_js('[string, {x:int, y:int}, boolean]')
end

License

Copyright 2008 by Oliver Steele. All rights reserved. Released under the MIT License.

javascript_fu's People

Contributors

osteele 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.