item 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.html +218 -0
  6. data/README.md +186 -0
  7. data/Rakefile +11 -0
  8. data/item.gemspec +25 -0
  9. data/lib/item.rb +8 -0
  10. data/lib/item/version.rb +3 -0
  11. data/lib/item/view_helpers.rb +46 -0
  12. data/test/.travis.yml +7 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/Rakefile +6 -0
  15. data/test/dummy/app/assets/images/.keep +0 -0
  16. data/test/dummy/app/assets/javascripts/application.js +13 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  18. data/test/dummy/app/controllers/application_controller.rb +5 -0
  19. data/test/dummy/app/controllers/concerns/.keep +0 -0
  20. data/test/dummy/app/helpers/application_helper.rb +2 -0
  21. data/test/dummy/app/mailers/.keep +0 -0
  22. data/test/dummy/app/models/.keep +0 -0
  23. data/test/dummy/app/models/concerns/.keep +0 -0
  24. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  25. data/test/dummy/bin/bundle +3 -0
  26. data/test/dummy/bin/rails +4 -0
  27. data/test/dummy/bin/rake +4 -0
  28. data/test/dummy/config.ru +4 -0
  29. data/test/dummy/config/application.rb +23 -0
  30. data/test/dummy/config/boot.rb +5 -0
  31. data/test/dummy/config/database.yml +25 -0
  32. data/test/dummy/config/environment.rb +5 -0
  33. data/test/dummy/config/environments/development.rb +37 -0
  34. data/test/dummy/config/environments/production.rb +82 -0
  35. data/test/dummy/config/environments/test.rb +39 -0
  36. data/test/dummy/config/initializers/assets.rb +8 -0
  37. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  38. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  39. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  40. data/test/dummy/config/initializers/inflections.rb +16 -0
  41. data/test/dummy/config/initializers/mime_types.rb +4 -0
  42. data/test/dummy/config/initializers/session_store.rb +3 -0
  43. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  44. data/test/dummy/config/locales/en.yml +23 -0
  45. data/test/dummy/config/routes.rb +56 -0
  46. data/test/dummy/config/secrets.yml +22 -0
  47. data/test/dummy/db/test.sqlite3 +0 -0
  48. data/test/dummy/lib/assets/.keep +0 -0
  49. data/test/dummy/log/.keep +0 -0
  50. data/test/dummy/log/test.log +10 -0
  51. data/test/dummy/public/404.html +67 -0
  52. data/test/dummy/public/422.html +67 -0
  53. data/test/dummy/public/500.html +66 -0
  54. data/test/dummy/public/favicon.ico +0 -0
  55. data/test/test_helper.rb +15 -0
  56. data/test/view_helpers_test.rb +66 -0
  57. metadata +201 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d319183537bdd771b4e31638aab0dd4773b21816
4
+ data.tar.gz: 7f9f8942e45fbb913111f852dd6b784a9eeae2fa
5
+ SHA512:
6
+ metadata.gz: 52eac981f4ff837a29b74d3cece7a1b0aa2d973ac99ea82751b2e5e05591891573dd20482bdf560873c9c700e638c777475528e1c4693681b2e04624799b34fb
7
+ data.tar.gz: 7abdc20e71d00312d24cdc564a028e6d89e14e3ead1784094e4e3cfc4c4bb20beeea217534ea198d08e4b916ba1fa52943fe08ae3ec9a88a957aebb233642b7e
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in item.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Lasse Bunk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,218 @@
1
+ <!DOCTYPE html><html><head><meta charset="utf-8"><style>html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
2
+
3
+ body{
4
+ color:#444;
5
+ font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman',
6
+ "Hiragino Sans GB", "STXihei", "微软雅黑", serif;
7
+ font-size:12px;
8
+ line-height:1.5em;
9
+ background:#fefefe;
10
+ width: 45em;
11
+ margin: 10px auto;
12
+ padding: 1em;
13
+ outline: 1300px solid #FAFAFA;
14
+ }
15
+
16
+ a{ color: #0645ad; text-decoration:none;}
17
+ a:visited{ color: #0b0080; }
18
+ a:hover{ color: #06e; }
19
+ a:active{ color:#faa700; }
20
+ a:focus{ outline: thin dotted; }
21
+ a:hover, a:active{ outline: 0; }
22
+
23
+ span.backtick {
24
+ border:1px solid #EAEAEA;
25
+ border-radius:3px;
26
+ background:#F8F8F8;
27
+ padding:0 3px 0 3px;
28
+ }
29
+
30
+ ::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
31
+ ::selection{background:rgba(255,255,0,0.3);color:#000}
32
+
33
+ a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
34
+ a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
35
+
36
+ p{
37
+ margin:1em 0;
38
+ }
39
+
40
+ img{
41
+ max-width:100%;
42
+ }
43
+
44
+ h1,h2,h3,h4,h5,h6{
45
+ font-weight:normal;
46
+ color:#111;
47
+ line-height:1em;
48
+ }
49
+ h4,h5,h6{ font-weight: bold; }
50
+ h1{ font-size:2.5em; }
51
+ h2{ font-size:2em; border-bottom:1px solid silver; padding-bottom: 5px; }
52
+ h3{ font-size:1.5em; }
53
+ h4{ font-size:1.2em; }
54
+ h5{ font-size:1em; }
55
+ h6{ font-size:0.9em; }
56
+
57
+ blockquote{
58
+ color:#666666;
59
+ margin:0;
60
+ padding-left: 3em;
61
+ border-left: 0.5em #EEE solid;
62
+ }
63
+ hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
64
+
65
+
66
+ pre , code, kbd, samp {
67
+ color: #000;
68
+ font-family: monospace;
69
+ font-size: 0.88em;
70
+ border-radius:3px;
71
+ background-color: #F8F8F8;
72
+ border: 1px solid #CCC;
73
+ }
74
+ pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; padding: 5px 12px;}
75
+ pre code { border: 0px !important; padding: 0;}
76
+ code { padding: 0 3px 0 3px; }
77
+
78
+ b, strong { font-weight: bold; }
79
+
80
+ dfn { font-style: italic; }
81
+
82
+ ins { background: #ff9; color: #000; text-decoration: none; }
83
+
84
+ mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
85
+
86
+ sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
87
+ sup { top: -0.5em; }
88
+ sub { bottom: -0.25em; }
89
+
90
+ ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
91
+ li p:last-child { margin:0 }
92
+ dd { margin: 0 0 0 2em; }
93
+
94
+ img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
95
+
96
+ table { border-collapse: collapse; border-spacing: 0; }
97
+ td { vertical-align: top; }
98
+
99
+ @media only screen and (min-width: 480px) {
100
+ body{font-size:14px;}
101
+ }
102
+
103
+ @media only screen and (min-width: 768px) {
104
+ body{font-size:16px;}
105
+ }
106
+
107
+ @media print {
108
+ * { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
109
+ body{font-size:12pt; max-width:100%; outline:none;}
110
+ a, a:visited { text-decoration: underline; }
111
+ hr { height: 1px; border:0; border-bottom:1px solid black; }
112
+ a[href]:after { content: " (" attr(href) ")"; }
113
+ abbr[title]:after { content: " (" attr(title) ")"; }
114
+ .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
115
+ pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
116
+ tr, img { page-break-inside: avoid; }
117
+ img { max-width: 100% !important; }
118
+ @page :left { margin: 15mm 20mm 15mm 10mm; }
119
+ @page :right { margin: 15mm 10mm 15mm 20mm; }
120
+ p, h2, h3 { orphans: 3; widows: 3; }
121
+ h2, h3 { page-break-after: avoid; }
122
+ }
123
+ </style><title>README</title></head><body><p><a href="http://travis-ci.org/lassebunk/item"><img alt="Build Status" src="https://secure.travis-ci.org/lassebunk/item.png" /></a></p>
124
+ <h1 id="item">Item</h1>
125
+ <p>Item is a Ruby on Rails plugin for implementing semantic markup (microdata) without messing up the view code.</p>
126
+ <p>See <a href="http://schema.org/docs/schemas.html">Schema.org</a> for valid microdata.</p>
127
+ <h2 id="installation">Installation</h2>
128
+ <p>Add this line to your application's <em>Gemfile</em>:</p>
129
+ <pre><code class="ruby">gem 'item'
130
+ </code></pre>
131
+
132
+ <p>Then run:</p>
133
+ <pre><code class="bash">$ bundle
134
+ </code></pre>
135
+
136
+ <h2 id="usage">Usage</h2>
137
+ <h3 id="scopes">Scopes</h3>
138
+ <p>To define an <code>itemscope</code>:</p>
139
+ <pre><code class="erb">&lt;% scope :product do %&gt;
140
+ ...
141
+ &lt;% end %&gt;
142
+ </code></pre>
143
+
144
+ <p>This will generate the following HTML:</p>
145
+ <pre><code class="html">&lt;div itemscope itemtype=&quot;http://schema.org/Product&quot;&gt;
146
+ ...
147
+ &lt;/div&gt;
148
+ </code></pre>
149
+
150
+ <h3 id="properties">Properties</h3>
151
+ <p>To define an <code>itemprop</code> span:</p>
152
+ <pre><code class="erb">&lt;%= prop :name, &quot;My Product Name&quot; %&gt;
153
+ </code></pre>
154
+
155
+ <p>This will generate the following HTML:</p>
156
+ <pre><code class="html">&lt;span itemprop=&quot;name&quot;&gt;My Product Name&lt;/span&gt;
157
+ </code></pre>
158
+
159
+ <h4 id="hidden-meta-properties">Hidden meta properties</h4>
160
+ <p>To define hidden <code>itemprop</code>s via <code>&lt;meta&gt;</code> tags, pass a hash to the <code>prop</code> helper:</p>
161
+ <pre><code class="erb">&lt;%= prop date_published: Date.today %&gt;
162
+ </code></pre>
163
+
164
+ <p>This will generate the following HTML:</p>
165
+ <pre><code class="html">&lt;meta itemprop=&quot;datePublished&quot; content=&quot;2014-07-26&quot; /&gt;
166
+ </code></pre>
167
+
168
+ <h4 id="link-values">Link values</h4>
169
+ <p>To define a link to an enumeration member, e.g. <a href="">ItemAvailability</a></p>
170
+ <h2 id="example">Example</h2>
171
+ <p>The following is the Product <a href="http://schema.org/Product">example</a> on <a href="http://schema.org">Schema.org</a> rewritten with Item. In your view:</p>
172
+ <pre><code class="erb">&lt;% scope :product do %&gt;
173
+ &lt;%= itemprop :name, &quot;Kenmore White 17\&quot; Microwave&quot; %&gt;
174
+ &lt;%= image_tag &quot;kenmore-microwave-17in.jpg&quot; %&gt;
175
+
176
+ &lt;% prop :aggregate_rating do %&gt;
177
+ Rated &lt;%= prop :rating_value, 3.5 %&gt;/5
178
+ based on &lt;%= prop :review_count, 11 %&gt; custom reviews
179
+ &lt;% end %&gt;
180
+
181
+ &lt;% prop :offers, type: :offer do %&gt;
182
+ &lt;%= prop :price, &quot;$55.00&quot; %&gt;
183
+ &lt;%= prop :availability, :in_stock %&gt;
184
+ In Stock
185
+ &lt;% end %&gt;
186
+
187
+ Product description:
188
+ &lt;%= prop :description, &quot;0.7 cubic feet countertop microwave.
189
+ Has six preset cooking categories and convenience features like
190
+ Add-A-Minute and Child Lock.&quot; %&gt;
191
+
192
+ Customer reviews:
193
+ &lt;% prop :review do %&gt;
194
+ &lt;%= prop :name, &quot;Not a happy camper&quot; %&gt; -
195
+ by &lt;%= prop :author, &quot;Ellie&quot; %&gt;,
196
+ &lt;%= prop date_published: &quot;2011-04-01&quot; %&gt;
197
+ April 1, 2011
198
+ &lt;% prop :review_rating, type: :rating do %&gt;
199
+ &lt;%= prop worst_rating: 1 %&gt;
200
+ &lt;%= prop :rating_value, 1 %&gt; /
201
+ &lt;%= prop :best_rating, 5 %&gt; stars
202
+ &lt;%= prop :description, &quot;The lamp burned out and now I have to replace it.&quot; %&gt;
203
+ &lt;% end %&gt;
204
+ &lt;% end %&gt;
205
+ &lt;% end %&gt;
206
+ </code></pre>
207
+
208
+ <h2 id="contributing">Contributing</h2>
209
+ <p>Changes and improvements are to Item are very welcome and greatly appreciated.</p>
210
+ <ol>
211
+ <li>Fork the project</li>
212
+ <li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
213
+ <li>Add your changes, including tests so we don't break it unintentionally.</li>
214
+ <li>Run <code>rake</code> to make sure the tests pass</li>
215
+ <li>Commit your changes (<code>git commit -am 'Add feature'</code>)</li>
216
+ <li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
217
+ <li>Create a new pull request</li>
218
+ </ol></body></html>
@@ -0,0 +1,186 @@
1
+ [![Build Status](https://secure.travis-ci.org/lassebunk/item.png)](http://travis-ci.org/lassebunk/item)
2
+
3
+ # Item
4
+
5
+ Item is a Ruby on Rails plugin for adding semantic markup (microdata) to your views without cluttering the code.
6
+
7
+ **What is Microdata?** [Microdata](http://schema.org) helps search engines show additional information about your content, for example product reviews.
8
+ This can help attract visitors to your site:
9
+
10
+ ![Microdata in SERPs](http://i.imgur.com/bCi0GHF.png)
11
+
12
+ **The problem with Microdata:** Normally, implementing these Microdata can make your views quite messy because you have a lot of "extra" content other than your regular view content.
13
+
14
+
15
+ **Item:** Item solves the problem by adding two helpers, `scope` and `prop`, that you can use in your views.
16
+ This makes it easy to add microdata scopes and properties without cluttering the view. Item is made to maximize ease of writing (and joy, of course – it *is* Ruby), while minimizing the code needed to add microdata to your views.
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's *Gemfile*:
21
+
22
+ ```ruby
23
+ gem 'item'
24
+ ```
25
+
26
+ Then run:
27
+
28
+ ```bash
29
+ $ bundle
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### Scopes
35
+
36
+ To define an `itemscope`:
37
+
38
+ ```erb
39
+ <% scope :product do %>
40
+ ...
41
+ <% end %>
42
+ ```
43
+
44
+ You don't need `<%=` before scopes, because we see it as just a definition, and not something that is inserted into the view, even though this is done behind the scenes.
45
+
46
+ The above will generate the following HTML:
47
+
48
+ ```html
49
+ <div itemscope itemtype="http://schema.org/Product">
50
+ ...
51
+ </div>
52
+ ```
53
+
54
+ ### Properties
55
+
56
+ To define an `itemprop` span:
57
+
58
+ ```erb
59
+ <%= prop :name, "My Product Name" %>
60
+ ```
61
+
62
+ This will generate the following HTML:
63
+
64
+ ```html
65
+ <span itemprop="name">My Product Name</span>
66
+ ```
67
+
68
+ #### Scoped properties
69
+
70
+ To define a property that is also a scope:
71
+
72
+ ```erb
73
+ <% prop :review do %>
74
+ <%= prop :name, "Pete Anderson" %>
75
+ <% end %>
76
+ ```
77
+
78
+ You don't need `<%=` before scoped properties, because we see this as a definition of a scope. The HTML is inserted automatically.
79
+
80
+ The above will generate the following HTML:
81
+
82
+ ```html
83
+ <div itemprop="review" itemscope itemtype="http://schema.org/Review">
84
+ <span itemprop="name">Pete Anderson</span>
85
+ </div>
86
+ ```
87
+
88
+ ##### Defining types on scoped properties
89
+
90
+ Sometimes you need to define a type on scoped properties when this cannot be inferred from the property name. To set a type:
91
+
92
+ ```erb
93
+ <% prop :review_rating, type: :review do %>
94
+ ...
95
+ <% end %>
96
+ ```
97
+
98
+ This will generate the following HTML:
99
+
100
+ ```html
101
+ <div itemprop="reviewRating" itemscope itemtype="http://schema.org/Review">
102
+ ...
103
+ </div>
104
+ ```
105
+
106
+
107
+ #### Meta properties
108
+
109
+ To define hidden `itemprop`s via `<meta>` tags, pass a hash to the `prop` helper:
110
+
111
+ ```erb
112
+ <%= prop date_published: Date.today %>
113
+ ```
114
+
115
+ This will generate the following HTML:
116
+
117
+ ```html
118
+ <meta itemprop="datePublished" content="2014-07-26" />
119
+ ```
120
+
121
+ #### Link properties
122
+
123
+ To define a link to an enumeration member, e.g. [ItemAvailability](http://schema.org/ItemAvailability):
124
+
125
+ ```erb
126
+ <%= prop :availability, :in_stock %>
127
+ ```
128
+
129
+ This will generate the following HTML:
130
+
131
+ ```html
132
+ <link itemprop="availability" href="http://schema.org/InStock" />
133
+ ```
134
+
135
+ ## Example
136
+
137
+ The following is based on the [Product example](http://schema.org/Product) on [Schema.org](http://schema.org), rewritten with the Item gem. In your view:
138
+
139
+ ```erb
140
+ <% scope :product do %>
141
+ <%= itemprop :name, "Kenmore White 17\" Microwave" %>
142
+ <%= image_tag "kenmore-microwave-17in.jpg" %>
143
+
144
+ <% prop :aggregate_rating do %>
145
+ Rated <%= prop :rating_value, 3.5 %>/5
146
+ based on <%= prop :review_count, 11 %> custom reviews
147
+ <% end %>
148
+
149
+ <% prop :offers, type: :offer do %>
150
+ <%= prop :price, "$55.00" %>
151
+ <%= prop :availability, :in_stock %>
152
+ In Stock
153
+ <% end %>
154
+
155
+ Product description:
156
+ <%= prop :description, "0.7 cubic feet countertop microwave.
157
+ Has six preset cooking categories and convenience features like
158
+ Add-A-Minute and Child Lock." %>
159
+
160
+ Customer reviews:
161
+ <% prop :review do %>
162
+ <%= prop :name, "Not a happy camper" %> -
163
+ by <%= prop :author, "Ellie" %>,
164
+ <%= prop date_published: "2011-04-01" %>
165
+ April 1, 2011
166
+ <% prop :review_rating, type: :rating do %>
167
+ <%= prop worst_rating: 1 %>
168
+ <%= prop :rating_value, 1 %> /
169
+ <%= prop :best_rating, 5 %> stars
170
+ <%= prop :description, "The lamp burned out and now I have to replace it." %>
171
+ <% end %>
172
+ <% end %>
173
+ <% end %>
174
+ ```
175
+
176
+ ## Contributing
177
+
178
+ Changes and improvements are to Item are very welcome and greatly appreciated.
179
+
180
+ 1. Fork the project
181
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
182
+ 3. Add your changes, including tests so we don't break it unintentionally.
183
+ 4. Run `rake` to make sure the tests pass
184
+ 5. Commit your changes (`git commit -am 'Add feature'`)
185
+ 6. Push to the branch (`git push origin my-new-feature`)
186
+ 7. Create a new pull request