scrivito_rich_snippet_widget 0.1.1 → 0.1.3
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.
- checksums.yaml +4 -4
- data/README.md +28 -17
- data/app/assets/javascripts/scrivito_rich_snippet_widget.js +1 -11
- data/app/models/rich_snippet/creative_work.rb +10 -3
- data/app/views/rich_snippet/creative_work/_details.html.erb +48 -32
- data/app/views/rich_snippet/offer/_details.html.erb +2 -2
- data/app/views/rich_snippet/thing/_details.html.erb +1 -1
- data/lib/scrivito_rich_snippet_widget/version.rb +1 -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: dba9f674fd4415f7e8ac8b397a1d4b06ced4d342
|
4
|
+
data.tar.gz: 37f6c7c82e7155d0ef3fa6a47f60c28c6d97e742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cded57475b87265260c77e627a61c4712fc23fb6ba4fbf8978ee4817c0c2041e80de0b02fb3a717ee0556d4318460df83a6dd983f65de72b3435164c3aa4e90d
|
7
|
+
data.tar.gz: c993a9fab68c337f07342ac234a63c5606c2fccc847b9dff7bdb3a1d19d7a3ba925a6a9e112ba9d182326c492f9ef05916ace2b533ebb594b154091bfd4877d5
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ScrivitoRichSnippetWidget
|
2
|
-
Add structured data to you page. Definitions
|
2
|
+
Add structured data to you page. Definitions can be found at https://schema.org
|
3
3
|
|
4
4
|
## Installation
|
5
5
|
Add this line to your application's Gemfile:
|
@@ -13,28 +13,31 @@ And then execute:
|
|
13
13
|
$ bundle
|
14
14
|
```
|
15
15
|
|
16
|
-
To make the content browser filter available add this to your content browser filter js:
|
17
|
-
|
18
16
|
Add this line to your JavaScript manifest **before** you load your content browser filter:
|
19
17
|
|
20
18
|
```js
|
21
19
|
//= require scrivito_rich_snippet_widget
|
22
20
|
```
|
23
21
|
|
22
|
+
Add this to your filters:
|
23
|
+
|
24
24
|
```js
|
25
25
|
scrivito.content_browser.filters(filter) {
|
26
26
|
if(filter.rich_snippet_filter) {
|
27
|
-
|
27
|
+
_obj_class: {
|
28
|
+
field: '_obj_class'
|
29
|
+
options: { rich_snippet_filter(filter.rich_snippet_filter) }
|
30
|
+
}
|
28
31
|
} else if (your filters) {
|
29
|
-
// ... add your filters here
|
32
|
+
// ... add your special filters here
|
30
33
|
} else {
|
31
34
|
'_obj_class': {
|
32
35
|
options: {
|
33
|
-
// ... add your
|
36
|
+
// ... add your standard filters here
|
34
37
|
rich_snippets: {
|
35
38
|
title: 'Rich Snippets',
|
36
39
|
options: {
|
37
|
-
rich_snippet_filter()
|
40
|
+
rich_snippet_filter('all')
|
38
41
|
}
|
39
42
|
}
|
40
43
|
}
|
@@ -45,21 +48,27 @@ scrivito.content_browser.filters(filter) {
|
|
45
48
|
|
46
49
|
## Add your own types
|
47
50
|
|
48
|
-
Create a modle at `/model/rich_snippet/new_type.rb` and add
|
51
|
+
Create a modle at `/model/rich_snippet/new_type.rb` and add the attributes for this type:
|
49
52
|
|
50
53
|
```ruby
|
51
|
-
module
|
54
|
+
module RichSnippet
|
52
55
|
class NewType < RichSnippet::Thing
|
53
56
|
attribute my_attribute, :string
|
54
57
|
attribute person, :refernce
|
55
58
|
attribute children, :referencelist
|
56
59
|
# ... more attributes
|
57
60
|
|
58
|
-
def to_json
|
61
|
+
def to_json(render_childs=false)
|
59
62
|
{
|
63
|
+
"@context": "http://schema.org",
|
64
|
+
"@type": "NewType",
|
65
|
+
name: name,
|
66
|
+
description: description,
|
67
|
+
image: image ? image.binary_url : '',
|
68
|
+
url: url
|
60
69
|
myAttribute: my_attribute,
|
61
|
-
person: person ? person.to_json : nil, # render the json for another rich snippet
|
62
|
-
children: array_json(children), # render an array of other rich snippets
|
70
|
+
person: person ? person.to_json : nil, # render the json for another rich snippet by calling its to_json method
|
71
|
+
children: array_json(children), # render an array of other rich snippets with this helper method
|
63
72
|
# ... definition for more attributes
|
64
73
|
}
|
65
74
|
end
|
@@ -74,15 +83,17 @@ module RichSnippets
|
|
74
83
|
end
|
75
84
|
```
|
76
85
|
|
77
|
-
The
|
86
|
+
The `render_childs` attribute in the `to_json` method can be used to prevent circles in the snippet definitions.
|
87
|
+
|
88
|
+
Then create the details view. You need two files:
|
78
89
|
|
79
90
|
```ruby
|
80
|
-
#
|
91
|
+
# rich_snippet/new_type/details.html.erb
|
81
92
|
<%= render 'rich_snippet/new_type/details', obj: @obj %>
|
82
93
|
```
|
83
94
|
|
84
95
|
```ruby
|
85
|
-
#
|
96
|
+
# rich_snippet/new_type/_details.html.erb
|
86
97
|
<%= render 'rich_snippet/thing/details', obj: obj, url_is_mandatory: false %>
|
87
98
|
|
88
99
|
<%= scrivito_details_for "Event attributes" do %>
|
@@ -109,7 +120,7 @@ In your contentbrowser filters, add the new types by using:
|
|
109
120
|
```js
|
110
121
|
scrivito.content_browser.filters(filter) {
|
111
122
|
if(filter.rich_snippet_filter) {
|
112
|
-
rich_snippet_filter(filter.rich_snippet_filter, ['NewType'
|
123
|
+
rich_snippet_filter(filter.rich_snippet_filter, ['NewType'])
|
113
124
|
} else if (your filters) {
|
114
125
|
// ... add your filters here
|
115
126
|
} else {
|
@@ -119,7 +130,7 @@ scrivito.content_browser.filters(filter) {
|
|
119
130
|
rich_snippets: {
|
120
131
|
title: 'Rich Snippets',
|
121
132
|
options: {
|
122
|
-
rich_snippet_filter(undefined, ['NewType'
|
133
|
+
rich_snippet_filter(undefined, ['NewType'])
|
123
134
|
}
|
124
135
|
}
|
125
136
|
}
|
@@ -12,17 +12,7 @@ Array.prototype.unique = function() {
|
|
12
12
|
function rich_snippet_filter(filter, app_types) {
|
13
13
|
var types = ['Event', 'Offer', 'PostalAddress', 'Person', 'Organization', 'Product', 'Recipe', 'CreativeWork', 'JobPosting'].concat(app_types || []).unique();
|
14
14
|
|
15
|
-
|
16
|
-
return rich_snippet_all_options(types);
|
17
|
-
}
|
18
|
-
else {
|
19
|
-
return {
|
20
|
-
'_obj_class': {
|
21
|
-
'field': '_obj_class',
|
22
|
-
'options': rich_snippet_all_options(filter == 'all' ? types : filter.concat(app_types || []).unique())
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
15
|
+
return rich_snippet_all_options(filter == 'all' ? types : filter);
|
26
16
|
}
|
27
17
|
|
28
18
|
function rich_snippet_all_options(types) {
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RichSnippet
|
2
2
|
class CreativeWork < Thing
|
3
|
-
attribute :work_type, :enum, values: ['Book','Game','Movie','Photograph','Painting','Serie','WebPage','MusicComposition']
|
3
|
+
attribute :work_type, :enum, values: ['Book','Game','Movie','Photograph','Painting','Serie','WebPage','MusicComposition','SoftwareSourceCode']
|
4
4
|
attribute :about, :string
|
5
5
|
attribute :author, :reference
|
6
6
|
attribute :contributor, :reference
|
@@ -19,6 +19,9 @@ module RichSnippet
|
|
19
19
|
attribute :publisher, :reference
|
20
20
|
attribute :thumbnail_url, :string
|
21
21
|
attribute :typical_age_range, :string
|
22
|
+
attribute :code_repository, :string
|
23
|
+
attribute :programming_language, :string
|
24
|
+
attribute :runtime_platform, :string
|
22
25
|
|
23
26
|
#Book
|
24
27
|
attribute :illustrator, :reference
|
@@ -41,7 +44,7 @@ module RichSnippet
|
|
41
44
|
def to_json(render_childs = false)
|
42
45
|
json = {
|
43
46
|
"@context": "http://schema.org",
|
44
|
-
"@type": "CreativeWork",
|
47
|
+
"@type": work_type.presence || "CreativeWork",
|
45
48
|
name: name,
|
46
49
|
description: description,
|
47
50
|
image: image ? image.binary_url : nil,
|
@@ -63,7 +66,7 @@ module RichSnippet
|
|
63
66
|
position: position,
|
64
67
|
publisher: publisher ? publisher.to_json : nil,
|
65
68
|
thumbnailUrl: thumbnail_url,
|
66
|
-
typicalAgeRange: typical_age_range
|
69
|
+
typicalAgeRange: typical_age_range
|
67
70
|
}
|
68
71
|
|
69
72
|
if work_type == 'Book'
|
@@ -80,6 +83,10 @@ module RichSnippet
|
|
80
83
|
json[:composer] = composer ? composer.to_json : nil
|
81
84
|
json[:lyricist] = lyricist ? lyricist.to_json : nil
|
82
85
|
json[:lyrics] = lyrics
|
86
|
+
elsif work_type == 'SoftwareSourceCode'
|
87
|
+
json[:codeRepository]= code_repository
|
88
|
+
json[:programmingLanguage]= programming_language
|
89
|
+
json[:runtimePlatform]= runtime_platform
|
83
90
|
end
|
84
91
|
|
85
92
|
return json.delete_if { |k, v| !v.present? }
|
@@ -1,116 +1,116 @@
|
|
1
1
|
<%= render 'rich_snippet/thing/details', obj: obj, url_is_mandatory: false %>
|
2
2
|
|
3
|
-
<%= scrivito_details_for "
|
3
|
+
<%= scrivito_details_for "Creative work attributes" do %>
|
4
4
|
<%= scrivito_details_for 'Type' do %>
|
5
5
|
<%= scrivito_tag :div, obj, :work_type, data: {scrivito_editors_reload: true} %>
|
6
6
|
<% end %>
|
7
7
|
|
8
|
-
<%= scrivito_details_for '
|
8
|
+
<%= scrivito_details_for 'About' do %>
|
9
9
|
<%= scrivito_tag :div, obj, :about %>
|
10
10
|
<% end %>
|
11
11
|
|
12
|
-
<%= scrivito_details_for '
|
12
|
+
<%= scrivito_details_for 'Author' do %>
|
13
13
|
<%= scrivito_tag :div, obj, :author, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organizazion']}} %>
|
14
14
|
<% end %>
|
15
15
|
|
16
|
-
<%= scrivito_details_for '
|
16
|
+
<%= scrivito_details_for 'Contributor' do %>
|
17
17
|
<%= scrivito_tag :div, obj, :contributor, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organization']}} %>
|
18
18
|
<% end %>
|
19
19
|
|
20
|
-
<%= scrivito_details_for '
|
20
|
+
<%= scrivito_details_for 'Copyright holder' do %>
|
21
21
|
<%= scrivito_tag :div, obj, :copyright_holder, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organization']}} %>
|
22
22
|
<% end %>
|
23
23
|
|
24
|
-
<%= scrivito_details_for '
|
24
|
+
<%= scrivito_details_for 'Copyright year' do %>
|
25
25
|
<%= scrivito_tag :div, obj, :copyright_year %>
|
26
26
|
<% end %>
|
27
27
|
|
28
|
-
<%= scrivito_details_for '
|
28
|
+
<%= scrivito_details_for 'Date created' do %>
|
29
29
|
<%= scrivito_tag :div, obj, :date_created %>
|
30
30
|
<% end %>
|
31
31
|
|
32
|
-
<%= scrivito_details_for '
|
32
|
+
<%= scrivito_details_for 'Date published' do %>
|
33
33
|
<%= scrivito_tag :div, obj, :date_published %>
|
34
34
|
<% end %>
|
35
35
|
|
36
|
-
<%= scrivito_details_for '
|
36
|
+
<%= scrivito_details_for 'Genre' do %>
|
37
37
|
<%= scrivito_tag :div, obj, :genre %>
|
38
38
|
<% end %>
|
39
39
|
|
40
|
-
<%= scrivito_details_for '
|
40
|
+
<%= scrivito_details_for 'In language' do %>
|
41
41
|
<%= scrivito_tag :div, obj, :in_language %>
|
42
42
|
<% end %>
|
43
43
|
|
44
|
-
<%= scrivito_details_for '
|
44
|
+
<%= scrivito_details_for 'Is accessible for free' do %>
|
45
45
|
<%= scrivito_tag :div, obj, :is_accessible_for_free %>
|
46
46
|
<% end %>
|
47
47
|
|
48
|
-
<%= scrivito_details_for '
|
48
|
+
<%= scrivito_details_for 'Is based on' do %>
|
49
49
|
<%= scrivito_tag :div, obj, :is_based_on, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['CreativeWork']}} %>
|
50
50
|
<% end %>
|
51
51
|
|
52
|
-
<%= scrivito_details_for '
|
52
|
+
<%= scrivito_details_for 'Is family friendly' do %>
|
53
53
|
<%= scrivito_tag :div, obj, :is_family_friendly %>
|
54
54
|
<% end %>
|
55
55
|
|
56
|
-
<%= scrivito_details_for '
|
56
|
+
<%= scrivito_details_for 'License' do %>
|
57
57
|
<%= scrivito_tag :div, obj, :license %>
|
58
58
|
<% end %>
|
59
59
|
|
60
|
-
<%= scrivito_details_for '
|
60
|
+
<%= scrivito_details_for 'Offers' do %>
|
61
61
|
<%= scrivito_tag :div, obj, :offers, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Offer']}} %>
|
62
62
|
<% end %>
|
63
63
|
|
64
|
-
<%= scrivito_details_for '
|
64
|
+
<%= scrivito_details_for 'Position' do %>
|
65
65
|
<%= scrivito_tag :div, obj, :position %>
|
66
66
|
<% end %>
|
67
67
|
|
68
|
-
<%= scrivito_details_for '
|
68
|
+
<%= scrivito_details_for 'Publisher' do %>
|
69
69
|
<%= scrivito_tag :div, obj, :publisher, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organization']}} %>
|
70
70
|
<% end %>
|
71
71
|
|
72
|
-
<%= scrivito_details_for '
|
72
|
+
<%= scrivito_details_for 'Thumbnail url' do %>
|
73
73
|
<%= scrivito_tag :div, obj, :thumbnail_url %>
|
74
74
|
<% end %>
|
75
75
|
|
76
|
-
<%= scrivito_details_for '
|
76
|
+
<%= scrivito_details_for 'Typical age range' do %>
|
77
77
|
<%= scrivito_tag :div, obj, :typical_age_range %>
|
78
78
|
<% end %>
|
79
79
|
|
80
80
|
<% if obj.work_type == 'Book' %>
|
81
|
-
<%= scrivito_details_for "
|
82
|
-
<%= scrivito_details_for '
|
81
|
+
<%= scrivito_details_for "Book attributes" do %>
|
82
|
+
<%= scrivito_details_for 'Illustrator' do %>
|
83
83
|
<%= scrivito_tag :div, obj, :illustrator, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organization']}} %>
|
84
84
|
<% end %>
|
85
85
|
|
86
|
-
<%= scrivito_details_for '
|
86
|
+
<%= scrivito_details_for 'Isbn' do %>
|
87
87
|
<%= scrivito_tag :div, obj, :isbn %>
|
88
88
|
<% end %>
|
89
89
|
|
90
|
-
<%= scrivito_details_for '
|
90
|
+
<%= scrivito_details_for 'Number of pages' do %>
|
91
91
|
<%= scrivito_tag :div, obj, :number_of_page %>
|
92
92
|
<% end %>
|
93
93
|
<% end %>
|
94
94
|
<% end %>
|
95
95
|
|
96
96
|
<% if obj.work_type == 'Movie' %>
|
97
|
-
<%= scrivito_details_for "
|
98
|
-
<%= scrivito_details_for '
|
97
|
+
<%= scrivito_details_for "Movie attributes" do %>
|
98
|
+
<%= scrivito_details_for 'Actors' do %>
|
99
99
|
<%= scrivito_tag :div, obj, :actors, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person']}} %>
|
100
100
|
<% end %>
|
101
101
|
|
102
|
-
<%= scrivito_details_for '
|
102
|
+
<%= scrivito_details_for 'Director' do %>
|
103
103
|
<%= scrivito_tag :div, obj, :director, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person']}} %>
|
104
104
|
<% end %>
|
105
105
|
|
106
|
-
<%= scrivito_details_for '
|
106
|
+
<%= scrivito_details_for 'Duration' do %>
|
107
107
|
<%= scrivito_tag :div, obj, :duration %>
|
108
108
|
<% end %>
|
109
109
|
<% end %>
|
110
110
|
<% end %>
|
111
111
|
|
112
112
|
<% if obj.work_type == 'WebPage' %>
|
113
|
-
<%= scrivito_details_for "
|
113
|
+
<%= scrivito_details_for "Web page attributes" do %>
|
114
114
|
<%= scrivito_details_for 'breadcrumb' do %>
|
115
115
|
<%= scrivito_tag :div, obj, :breadcrumb %>
|
116
116
|
<% end %>
|
@@ -118,19 +118,35 @@
|
|
118
118
|
<% end %>
|
119
119
|
|
120
120
|
<% if obj.work_type == 'MusicComposition' %>
|
121
|
-
<%= scrivito_details_for "
|
122
|
-
<%= scrivito_details_for '
|
121
|
+
<%= scrivito_details_for "Musci composition attributes" do %>
|
122
|
+
<%= scrivito_details_for 'Composer' do %>
|
123
123
|
<%= scrivito_tag :div, obj, :composer, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organization']}} %>
|
124
124
|
<% end %>
|
125
125
|
|
126
|
-
<%= scrivito_details_for '
|
126
|
+
<%= scrivito_details_for 'Lyricist' do %>
|
127
127
|
<%= scrivito_tag :div, obj, :lyricist, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person']}} %>
|
128
128
|
<% end %>
|
129
129
|
|
130
|
-
<%= scrivito_details_for '
|
130
|
+
<%= scrivito_details_for 'Lyrics' do %>
|
131
131
|
<%= scrivito_tag :div, obj, :lyrics %>
|
132
132
|
<% end %>
|
133
133
|
<% end %>
|
134
134
|
<% end %>
|
135
135
|
|
136
|
+
<% if obj.work_type == 'SoftwareSourceCode' %>
|
137
|
+
<%= scrivito_details_for "Software source code attributes" do %>
|
138
|
+
<%= scrivito_details_for 'Programming language' do %>
|
139
|
+
<%= scrivito_tag :div, obj, :programming_language %>
|
140
|
+
<% end %>
|
141
|
+
|
142
|
+
<%= scrivito_details_for 'Code repository' do %>
|
143
|
+
<%= scrivito_tag :div, obj, :code_repository %>
|
144
|
+
<% end %>
|
145
|
+
|
146
|
+
<%= scrivito_details_for 'Runtime platform' do %>
|
147
|
+
<%= scrivito_tag :div, obj, :runtime_platform %>
|
148
|
+
<% end %>
|
149
|
+
<% end %>
|
150
|
+
<% end %>
|
151
|
+
|
136
152
|
<% end %>
|
@@ -26,10 +26,10 @@
|
|
26
26
|
<% end %>
|
27
27
|
|
28
28
|
<%= scrivito_details_for 'Inventory level' do %>
|
29
|
-
<%= scrivito_tag :div, obj, :inventory_level
|
29
|
+
<%= scrivito_tag :div, obj, :inventory_level %>
|
30
30
|
<% end %>
|
31
31
|
|
32
32
|
<%= scrivito_details_for 'Seller' do %>
|
33
|
-
<%= scrivito_tag :div, obj, :seller, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Organization']}} %>
|
33
|
+
<%= scrivito_tag :div, obj, :seller, data: {scrivito_editors_filter_context: {rich_snippet_filter: ['Person', 'Organization']}} %>
|
34
34
|
<% end %>
|
35
35
|
<% end %>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<% end %>
|
9
9
|
|
10
10
|
<%= scrivito_details_for 'Image' do %>
|
11
|
-
<%= scrivito_tag :div, obj, :image, data: {scrivito_editors_filter_context: {
|
11
|
+
<%= scrivito_tag :div, obj, :image, data: {scrivito_editors_filter_context: {_image: true}} %>
|
12
12
|
<% end %>
|
13
13
|
|
14
14
|
<%= scrivito_details_for "Url #{url_is_mandatory ? '*' : ''}" do %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivito_rich_snippet_widget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Geidel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: scrivito
|