An open API service indexing awesome lists of open source software.

https://github.com/spearwolf/microdata_fu

Passing microdata from rails to javascript
https://github.com/spearwolf/microdata_fu

Last synced: 10 months ago
JSON representation

Passing microdata from rails to javascript

Awesome Lists containing this project

README

          

= microdata_fu (rails plugin)

A simple rails plugin which enables you to..

- store non-visible data (microdata) into your html
- read-out the data from javascript

== How to Install

First, add microdata_fu to your list of gems in config/environment.rb:

config.gem 'spearwolf-microdata_fu', :lib => 'microdata_fu', :source => 'http://gems.github.com'

Then insert into your html layout the microdata_fu tag (e.g. app/views/layouts/application.html.erb):


..
<%= microdata_fu %>
..

== Usage Example

=== Define microdata in your controller

class MyController << ApplicationController
def index
microdata :foo, 'foo'
microdata :bar, { :abc => 'ABC', :xyz => 123 }
microdata :user, User.find(params[:id])
end
end

=== Set microdata storage type

microdata :foo, 'bar' # by default values are stored in controller instance
microdata :plah, 'foo', :flash => true # use rails flash storage
microdata :bar, 'plah!', :session => true # use session storage

=== Read-out microdata from javascript

In javascript you can read-out the microdata through the microdata_fu api:

var foo = microdata_fu.read('foo');

or use the optional callback function:

mircodata_fu.read('bar', function(bar) {
/* ...do whatever you want with bar here...
if bar is undefined this callback won't be executed */
});

== Author

Copyright (c) 2008-2010 Wolfger Schramm , released under the MIT license