spearwolf-microdata_fu 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +6 -2
- data/lib/microdata_fu.rb +25 -2
- data/lib/microdata_fu_helper.rb +12 -2
- metadata +2 -3
data/README.rdoc
CHANGED
@@ -31,8 +31,12 @@ Then insert into your html layout the microdata_fu tag (<em>e.g.</em> <tt>app/vi
|
|
31
31
|
microdata :bar, { :abc => 'ABC', :xyz => 123 }
|
32
32
|
microdata :user, User.find(params[:id])
|
33
33
|
end
|
34
|
-
end
|
34
|
+
end
|
35
35
|
|
36
|
+
=== Set microdata storage type
|
37
|
+
|
38
|
+
microdata :foo, 'foo', :flash => true # flash storage is default
|
39
|
+
microdata :bar, 'plah!', :session => true # use session storage
|
36
40
|
|
37
41
|
=== Read-out microdata from javascript
|
38
42
|
|
@@ -44,7 +48,7 @@ or use the optional callback function:
|
|
44
48
|
|
45
49
|
mircodata_fu.read('bar', function(bar) {
|
46
50
|
/* ...do whatever you want with bar here...
|
47
|
-
if bar is undefined
|
51
|
+
if bar is undefined this callback won't be executed */
|
48
52
|
});
|
49
53
|
|
50
54
|
|
data/lib/microdata_fu.rb
CHANGED
@@ -1,7 +1,30 @@
|
|
1
1
|
# MicrodataFu
|
2
2
|
module MicrodataFu
|
3
3
|
|
4
|
-
def microdata key, value
|
5
|
-
|
4
|
+
def microdata key, value, options = {}
|
5
|
+
value = value.respond_to?(:to_json) ? value.to_json : value.to_s.to_json
|
6
|
+
#if use_flash?(options)
|
7
|
+
#(flash[:microdata] ||= {})[key.to_s] = value
|
8
|
+
#elsif use_session?(options)
|
9
|
+
if use_session?(options)
|
10
|
+
(session[:microdata] ||= {})[key.to_s] = value
|
11
|
+
else
|
12
|
+
(flash[:microdata] ||= {})[key.to_s] = value
|
13
|
+
end
|
14
|
+
# TODO put value into custom store
|
6
15
|
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def use_flash? options
|
20
|
+
options[:flash] == true
|
21
|
+
end
|
22
|
+
|
23
|
+
def use_session? options
|
24
|
+
options[:session] == true
|
25
|
+
end
|
26
|
+
|
27
|
+
#def store
|
28
|
+
# TODO define custom store
|
29
|
+
#end
|
7
30
|
end
|
data/lib/microdata_fu_helper.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
module MicrodataFuHelper
|
2
2
|
|
3
3
|
def microdata_fu
|
4
|
-
md =
|
5
|
-
javascript_tag "var 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
6
|
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def microdata_values
|
11
|
+
returning({}) do |h|
|
12
|
+
h.merge!(session[:microdata]) unless session[:microdata].nil?
|
13
|
+
h.merge!(flash[:microdata]) unless flash[:microdata].nil?
|
14
|
+
# TODO merge values from custom store
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spearwolf-microdata_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wolfger Schramm
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -31,7 +31,6 @@ has_rdoc: true
|
|
31
31
|
homepage: http://github.com/spearwolf/microdata_fu
|
32
32
|
post_install_message:
|
33
33
|
rdoc_options:
|
34
|
-
- --inline-source
|
35
34
|
- --charset=UTF-8
|
36
35
|
require_paths:
|
37
36
|
- lib
|