scrivito_seo_page_extender 0.92.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 236f034ea0be1c4c4b9341d539f560bb58a5a406
4
- data.tar.gz: fb95eb9d63250a9acff9d527cd4be00aed22a925
3
+ metadata.gz: 123bcb2020a31ab95ef68e0d1e2821533c42a317
4
+ data.tar.gz: 06eeccd4f549acbd72ba9d67ba01115e5eab6abe
5
5
  SHA512:
6
- metadata.gz: 0450b9800863e5cde61928482aa0e94109bd6dd235ad2dea9175254fe57c2a9c42288ee7a46edb86b99a8be40927455e5cdd0659d8827db755b9283689a692ab
7
- data.tar.gz: e93af5a073eee555d5ad2d76b563dbf3774f5d178501d19e351b4aa1ef44cd17be62a5e9196801fe0282fc64d8e36576bd9523447d0199c217a5108fbf03ada9
6
+ metadata.gz: 8afab6f73df6dce644d489f112fdba71079b8891bdd1dcf081f13f028f30579e82f7921dda34317a844e5f9c41cf8f9e1f5b064c96b109d48321ed2d7f44d88a
7
+ data.tar.gz: 832f12345e99094e31b874577ec9ba3877daa80eaafe1a9ade91e86fb5834aa048de9d95e240f001dec48f130c1268f1a0d4d5149fddb9a4f9875fdf629ed777
data/README.md CHANGED
@@ -145,6 +145,30 @@ class MyObj < Obj
145
145
  end
146
146
  ```
147
147
 
148
+ ## Configuration
149
+
150
+ Add an initializer to activate automatic attribute mapping for titles and descriptions:
151
+
152
+ ```ruby
153
+ ScrivitoSeoPageExtender.configure do |config|
154
+ config.attribute_mapping = true
155
+ end
156
+ ```
157
+
158
+ You can overwrite the default attribute mapping depending on your app in the obj.rb with:
159
+
160
+ ```ruby
161
+ def self.seo_attribute_mapping(obj)
162
+ {
163
+ og_title: obj.my_app_title,
164
+ og_description: obj.my_app_description
165
+ ...
166
+ }
167
+ end
168
+ ```
169
+
170
+ The key is an attribute from meta, open graph or twitter cards modules, the value is app specific. More detailed values like `obj.my_title || obj.title || 'Fallback title'` are possible.
171
+
148
172
  ## Customization
149
173
 
150
174
  If you use the default details views provided in this gem, we recommend to activate [Scrivito Advanced Editors](https://github.com/Scrivito/scrivito_advanced_editors) to utilize the tabs used by this gem.
@@ -18,7 +18,20 @@ module SeoPageExtenderHelper
18
18
  end
19
19
  end
20
20
 
21
+ def seo_attribute_fallback(obj, attribute)
22
+ if seo_attribute_fallback?(obj, attribute)
23
+ seo_attribute_mapping(obj)[attribute]
24
+ else
25
+ obj.send(attribute.to_sym)
26
+ end
27
+ end
28
+
21
29
  private
30
+ def seo_attribute_fallback?(obj, attribute)
31
+ # config is true && attribute is not set && mapping exists
32
+ ScrivitoSeoPageExtender.configuration.attribute_mapping && !obj.send(attribute.to_sym).present? && (seo_attribute_mapping(obj)[attribute]).present?
33
+ end
34
+
22
35
  def get_words_from_page(obj, attribute)
23
36
  strip_tags(scrivito_tag(:span, obj, attribute).to_s).split(" ")
24
37
  end
@@ -50,4 +63,14 @@ module SeoPageExtenderHelper
50
63
  "a,able,about,across,after,all,almost,also,am,among,an,and,any,are,as,at,be,because,been,but,by,can,cannot,could,dear,did,do,does,either,else,ever,every,for,from,get,got,had,has,have,he,her,hers,him,his,how,however,i,if,in,into,is,it,its,just,least,let,like,likely,may,me,might,most,must,my,neither,no,nor,not,of,off,often,on,only,or,other,our,own,rather,said,say,says,she,should,since,so,some,than,that,the,their,them,then,there,these,they,this,tis,to,too,twas,us,wants,was,we,were,what,when,where,which,while,who,whom,why,will,with,would,yet,you,your".split(",")
51
64
  end
52
65
  end
66
+
67
+ def seo_attribute_mapping(obj)
68
+ return Obj.seo_attribute_mapping(obj) if Obj.respond_to?('seo_attribute_mapping')
69
+ {
70
+ og_title: obj.send(:title).presence,
71
+ og_description: obj.send(:meta_description).presence,
72
+ tc_title: obj.send(:title).presence,
73
+ tc_description: obj.send(:meta_description).presence
74
+ }
75
+ end
53
76
  end
@@ -1,9 +1,9 @@
1
- <% if @obj.respond_to?(attribute) && !@obj.send(attribute).blank? %>
1
+ <% if @obj.respond_to?(attribute) && seo_attribute_fallback(@obj, attribute.to_sym).present? %>
2
2
  <% if name[/image\d?$/] %>
3
3
  <meta content="<%= scrivito_path(@obj[attribute]) %>" name="<%= name %>"/>
4
4
  <% elsif name == 'audience' || name == 'robots' || name == 'keywords' %>
5
5
  <meta content="<%= @obj.send(attribute).join(',') %>" name="<%= name %>"/>
6
6
  <% else %>
7
- <meta content="<%= @obj.send(attribute) %>" name="<%= name %>"/>
7
+ <meta content="<%= seo_attribute_fallback(@obj, attribute.to_sym) %>" name="<%= name %>"/>
8
8
  <% end %>
9
9
  <% end %>
@@ -1,4 +1,20 @@
1
1
  require "scrivito_seo_page_extender/engine"
2
+ require "scrivito_seo_page_extender/configuration"
2
3
 
3
4
  module ScrivitoSeoPageExtender
5
+ class << self
6
+ attr_writer :configuration
7
+ end
8
+
9
+ def self.configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def self.reset
14
+ @configuration = Configuration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
4
20
  end
@@ -0,0 +1,8 @@
1
+ module ScrivitoSeoPageExtender
2
+ class Configuration
3
+ attr_accessor :attribute_mapping
4
+ def initialize
5
+ @attribute_mapping = false
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module ScrivitoSeoPageExtender
2
- VERSION = "0.92.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrivito_seo_page_extender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.92.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scrivito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-07 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scrivito_sdk
@@ -64,6 +64,7 @@ files:
64
64
  - app/views/seo_page_extender/open_graph/_profile.html.erb
65
65
  - app/views/seo_page_extender/open_graph/_video.html.erb
66
66
  - lib/scrivito_seo_page_extender.rb
67
+ - lib/scrivito_seo_page_extender/configuration.rb
67
68
  - lib/scrivito_seo_page_extender/engine.rb
68
69
  - lib/scrivito_seo_page_extender/version.rb
69
70
  - lib/tasks/scrivito_seo_page_extender_tasks.rake