item 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +37 -0
- data/lib/item/version.rb +1 -1
- data/lib/item/view_helpers.rb +23 -9
- data/test/view_helpers_test.rb +53 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f3aa76ac0d54caa805e09ca62f66a0900ea0e3e
|
4
|
+
data.tar.gz: 518a7394a3de2cdee49a06f91fcb1d17a0edafad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5acabdac052a0d9cf352f55dfdd52c3de58ed4f81761160f0dd06cf57efd639ad77fc8161da4ab17951013559c8a20df99d2516405cf8515b38c75c54fdc2d69
|
7
|
+
data.tar.gz: cf65dca0846db6c9495fcda72632a7208f770c4bd7662ec35a620fd97bbb88ad5ac5696208a9b00b8cdf474e53d2ed291084807245f29ab4214a7bdc95831388
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -112,6 +112,16 @@ This will generate the following HTML:
|
|
112
112
|
</div>
|
113
113
|
```
|
114
114
|
|
115
|
+
##### Disabling rendering on scoped properties
|
116
|
+
|
117
|
+
Sometimes you need to disable rendering on entire `prop` blocks. You can do this by passing `:if` and `:unless` options.
|
118
|
+
This will render the content, but without microdata for both the `prop` block itself and all `prop`s inside it:
|
119
|
+
|
120
|
+
```erb
|
121
|
+
<%= prop :review_rating, type: :rating, if: @product.rating? do %>
|
122
|
+
...
|
123
|
+
<% end %>
|
124
|
+
```
|
115
125
|
|
116
126
|
#### Meta properties
|
117
127
|
|
@@ -135,6 +145,12 @@ To define a link to an enumeration member, e.g. [ItemAvailability](http://schema
|
|
135
145
|
<%= prop :availability, :in_stock %>
|
136
146
|
```
|
137
147
|
|
148
|
+
You can also do this by passing symbols as hash values:
|
149
|
+
|
150
|
+
```erb
|
151
|
+
<%= prop availability: :in_stock %>
|
152
|
+
```
|
153
|
+
|
138
154
|
This will generate the following HTML:
|
139
155
|
|
140
156
|
```html
|
@@ -182,6 +198,27 @@ The following is based on the [Product example](http://schema.org/Product) on [S
|
|
182
198
|
<% end %>
|
183
199
|
```
|
184
200
|
|
201
|
+
## Tools for validating microdata
|
202
|
+
|
203
|
+
There are various tools you can use for validating your microdata.
|
204
|
+
I recommend using these (especially Google's) before releasing to production, so you are sure that the microdata you implemented works as expected.
|
205
|
+
|
206
|
+
#### Google Structured Data Testing Tool
|
207
|
+
|
208
|
+
[Google's Structured Data Testing Tool](http://www.google.com/webmasters/tools/richsnippets) is the tool I recommend using for making sure your microdata will validate.
|
209
|
+
If your microdata validates here, it will validate on Google SERPs.
|
210
|
+
|
211
|
+
You can enter a URL or copy/paste HTML to validate. This means that you can test your development code, too.
|
212
|
+
|
213
|
+
#### Bing Markup Validator
|
214
|
+
|
215
|
+
[Bing's Markup Validator](http://www.bing.com/webmaster/diagnostics/markup/validator) appears to be easier to read, but it is not as strict as Google's tool.
|
216
|
+
|
217
|
+
#### Mida
|
218
|
+
|
219
|
+
[Mida](https://github.com/LawrenceWoodman/mida) is a great tool for validating your code locally as you implement new microdata.
|
220
|
+
It runs locally via the command line and takes a URL to validate, so you can validate code on your local development server.
|
221
|
+
|
185
222
|
## Contributing
|
186
223
|
|
187
224
|
Changes and improvements are to Item are very welcome and greatly appreciated.
|
data/lib/item/version.rb
CHANGED
data/lib/item/view_helpers.rb
CHANGED
@@ -7,33 +7,47 @@ module Item
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def prop(key, value = nil, options = {}, &block)
|
10
|
+
@_item_enabled = true unless defined?(@_item_enabled)
|
11
|
+
|
10
12
|
if key.is_a?(Hash)
|
11
13
|
key.map do |key, value|
|
12
14
|
if value.is_a?(Symbol)
|
13
|
-
link_prop(key, value)
|
15
|
+
link_prop(key, value) if @_item_enabled
|
14
16
|
else
|
15
|
-
meta_prop(key, value)
|
17
|
+
meta_prop(key, value) if @_item_enabled
|
16
18
|
end
|
17
|
-
end.join("\n").html_safe
|
19
|
+
end.compact.join("\n").html_safe
|
18
20
|
elsif value.is_a?(Symbol)
|
19
|
-
link_prop(key, value)
|
21
|
+
link_prop(key, value) if @_item_enabled
|
20
22
|
else
|
21
23
|
options, value = value, nil if value.is_a?(Hash)
|
22
24
|
itemprop = Util.itemprop(key)
|
23
25
|
|
24
|
-
|
26
|
+
@_item_enabled_old = @_item_enabled
|
27
|
+
@_item_enabled = @_item_enabled_old && options.fetch(:if, !options.fetch(:unless, false))
|
28
|
+
|
29
|
+
options.delete(:if)
|
30
|
+
options.delete(:unless)
|
31
|
+
|
32
|
+
content = if block
|
25
33
|
tag = options.delete(:tag) || :div
|
26
34
|
itemtype = Util.itemtype(options.delete(:type) || key)
|
27
|
-
|
28
|
-
content_tag(tag,
|
35
|
+
options = { itemprop: itemprop, itemscope: "itemscope", itemtype: itemtype }.merge(options) if @_item_enabled
|
36
|
+
content_tag(tag, options, &block)
|
29
37
|
else
|
30
38
|
tag = options.delete(:tag) || :span
|
31
|
-
|
32
|
-
content_tag(tag, value,
|
39
|
+
options = { itemprop: itemprop }.merge(options) if @_item_enabled
|
40
|
+
content_tag(tag, value, options)
|
33
41
|
end
|
42
|
+
|
43
|
+
@_item_enabled = @_item_enabled_old
|
44
|
+
|
45
|
+
content
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
49
|
+
private
|
50
|
+
|
37
51
|
def link_prop(key, value)
|
38
52
|
tag(:link, itemprop: Util.itemprop(key), href: Util.href(value))
|
39
53
|
end
|
data/test/view_helpers_test.rb
CHANGED
@@ -78,10 +78,62 @@ class ViewHelpersTest < ActionView::TestCase
|
|
78
78
|
|
79
79
|
test "combined" do
|
80
80
|
content = scope :product do
|
81
|
-
|
81
|
+
prop(:title, "My Title")
|
82
82
|
end
|
83
83
|
|
84
84
|
assert_equal %{<div itemscope="itemscope" itemtype="http://schema.org/Product"><span itemprop="title">My Title</span></div>},
|
85
85
|
content
|
86
86
|
end
|
87
|
+
|
88
|
+
test "prop with trueish if" do
|
89
|
+
content = scope :product do
|
90
|
+
prop :offers, type: :offer, tag: :custom1, class: "offers-container", if: "trueish" do
|
91
|
+
[prop(:price, 123.5, tag: :custom2, class: "price-container"),
|
92
|
+
prop(availability: :in_stock, price_currency: "DKK"),
|
93
|
+
prop(:other_key, :other_value)].join.html_safe
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_equal %{<div itemscope="itemscope" itemtype="http://schema.org/Product"><custom1 class="offers-container" itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer"><custom2 class="price-container" itemprop="price">123.5</custom2><link href="http://schema.org/InStock" itemprop="availability" />\n<meta content="DKK" itemprop="priceCurrency" /><link href="http://schema.org/OtherValue" itemprop="otherKey" /></custom1></div>},
|
98
|
+
content
|
99
|
+
end
|
100
|
+
|
101
|
+
test "prop with falsey if" do
|
102
|
+
content = scope :product do
|
103
|
+
prop :offers, type: :offer, tag: :custom1, class: "offers-container", if: nil do
|
104
|
+
[prop(:price, 123.5, tag: :custom2, class: "price-container"),
|
105
|
+
prop(availability: :in_stock, price_currency: "DKK"),
|
106
|
+
prop(:other_key, :other_value)].join.html_safe
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
assert_equal %{<div itemscope="itemscope" itemtype="http://schema.org/Product"><custom1 class="offers-container"><custom2 class="price-container">123.5</custom2></custom1></div>},
|
111
|
+
content
|
112
|
+
end
|
113
|
+
|
114
|
+
test "prop with falsey unless" do
|
115
|
+
content = scope :product do
|
116
|
+
prop :offers, type: :offer, tag: :custom1, class: "offers-container", unless: nil do
|
117
|
+
[prop(:price, 123.5, tag: :custom2, class: "price-container"),
|
118
|
+
prop(availability: :in_stock, price_currency: "DKK"),
|
119
|
+
prop(:other_key, :other_value)].join.html_safe
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
assert_equal %{<div itemscope="itemscope" itemtype="http://schema.org/Product"><custom1 class="offers-container" itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer"><custom2 class="price-container" itemprop="price">123.5</custom2><link href="http://schema.org/InStock" itemprop="availability" />\n<meta content="DKK" itemprop="priceCurrency" /><link href="http://schema.org/OtherValue" itemprop="otherKey" /></custom1></div>},
|
124
|
+
content
|
125
|
+
end
|
126
|
+
|
127
|
+
test "prop with trueish unless" do
|
128
|
+
content = scope :product do
|
129
|
+
prop :offers, type: :offer, tag: :custom1, class: "offers-container", unless: "trueish" do
|
130
|
+
[prop(:price, 123.5, tag: :custom2, class: "price-container"),
|
131
|
+
prop(availability: :in_stock, price_currency: "DKK"),
|
132
|
+
prop(:other_key, :other_value)].join.html_safe
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
assert_equal %{<div itemscope="itemscope" itemtype="http://schema.org/Product"><custom1 class="offers-container"><custom2 class="price-container">123.5</custom2></custom1></div>},
|
137
|
+
content
|
138
|
+
end
|
87
139
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: item
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasse Bunk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|