microdata_fu 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +58 -0
- data/lib/microdata_fu.rb +28 -0
- data/lib/microdata_fu_helper.rb +7 -0
- data/rails/init.rb +4 -0
- metadata +66 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008-2009 Wolfger Schramm <wolfger@spearwolf.de>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= microdata_fu (rails plugin)
|
2
|
+
|
3
|
+
A simple rails plugin which enables you to..
|
4
|
+
|
5
|
+
- store <em>non-visible data</em> (microdata) into your html
|
6
|
+
- read-out the data from javascript
|
7
|
+
|
8
|
+
|
9
|
+
== How to Install
|
10
|
+
|
11
|
+
First, add microdata_fu to your list of gems in <tt>config/environment.rb</tt>:
|
12
|
+
|
13
|
+
config.gem 'spearwolf-microdata_fu', :lib => 'microdata_fu', :source => 'http://gems.github.com'
|
14
|
+
|
15
|
+
Then insert into your html layout the microdata_fu tag (<em>e.g.</em> <tt>app/views/layouts/application.html.erb</tt>):
|
16
|
+
|
17
|
+
<head>
|
18
|
+
..
|
19
|
+
<%= microdata_fu %>
|
20
|
+
..
|
21
|
+
</head>
|
22
|
+
|
23
|
+
|
24
|
+
== Usage Example
|
25
|
+
|
26
|
+
=== Define microdata in your controller
|
27
|
+
|
28
|
+
class MyController << ApplicationController
|
29
|
+
def index
|
30
|
+
microdata :foo, 'foo'
|
31
|
+
microdata :bar, { :abc => 'ABC', :xyz => 123 }
|
32
|
+
microdata :user, User.find(params[:id])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
=== Set microdata storage type
|
37
|
+
|
38
|
+
microdata :foo, 'bar' # by default values are stored in controller instance
|
39
|
+
microdata :plah, 'foo', :flash => true # use rails flash storage
|
40
|
+
microdata :bar, 'plah!', :session => true # use session storage
|
41
|
+
|
42
|
+
=== Read-out microdata from javascript
|
43
|
+
|
44
|
+
In javascript you can read-out the microdata through the microdata_fu api:
|
45
|
+
|
46
|
+
var foo = microdata_fu.read('foo');
|
47
|
+
|
48
|
+
or use the optional callback function:
|
49
|
+
|
50
|
+
mircodata_fu.read('bar', function(bar) {
|
51
|
+
/* ...do whatever you want with bar here...
|
52
|
+
if bar is undefined this callback won't be executed */
|
53
|
+
});
|
54
|
+
|
55
|
+
|
56
|
+
== Author
|
57
|
+
|
58
|
+
Copyright (c) 2008-2010 Wolfger Schramm <wolfger@spearwolf.de>, released under the MIT license
|
data/lib/microdata_fu.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# MicrodataFu
|
2
|
+
module MicrodataFu
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.instance_eval "helper_method :microdata_values"
|
6
|
+
end
|
7
|
+
|
8
|
+
def microdata key, value, options = {}
|
9
|
+
value = value.respond_to?(:to_json) ? value.to_json : value.to_s.to_json
|
10
|
+
if options[:flash] == true
|
11
|
+
(flash[:microdata] ||= {})[key.to_s] = value
|
12
|
+
elsif options[:session] == true
|
13
|
+
(session[:microdata] ||= {})[key.to_s] = value
|
14
|
+
else
|
15
|
+
(@microdata_values ||= {})[key.to_s] = value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def microdata_values
|
22
|
+
returning({}) do |h|
|
23
|
+
h.merge!(session[:microdata]) unless session[:microdata].nil?
|
24
|
+
h.merge!(flash[:microdata]) unless flash[:microdata].nil?
|
25
|
+
h.merge!(@microdata_values) if @microdata_values
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
module MicrodataFuHelper
|
2
|
+
|
3
|
+
def microdata_fu
|
4
|
+
md = microdata_values.map {|k,v| "'#{escape_javascript(k)}':#{v}" }.join(",")
|
5
|
+
javascript_tag "var microdata_fu = /* http://github.com/spearwolf/microdata_fu/tree/master */(function(){var _md_fu={#{md}};var md={get:function(k){return _md_fu[k];}};return{read:function(k,fn){var v=md.get(k);if(fn!=undefined&&v!=undefined){v=fn(v);}return v;}}})();"
|
6
|
+
end
|
7
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: microdata_fu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 5
|
9
|
+
version: 0.2.5
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Wolfger Schramm
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-23 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Read-out (rails generated) microdata from javascript
|
22
|
+
email: wolfger@spearwolf.de
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- README.rdoc
|
29
|
+
files:
|
30
|
+
- MIT-LICENSE
|
31
|
+
- README.rdoc
|
32
|
+
- lib/microdata_fu.rb
|
33
|
+
- lib/microdata_fu_helper.rb
|
34
|
+
- rails/init.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/spearwolf/microdata_fu
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options:
|
41
|
+
- --charset=UTF-8
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
segments:
|
49
|
+
- 0
|
50
|
+
version: "0"
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
requirements: []
|
59
|
+
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.3.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: Passing microdata from rails to javascript
|
65
|
+
test_files: []
|
66
|
+
|