para-seo_tools 0.4.2 → 0.4.3

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: 724bd64d9cc63d30dd64a7c34f5ac844e2a4aa58
4
- data.tar.gz: 2cddf86252810fc4f146f2e458e126d9a33b45f1
3
+ metadata.gz: 6e220801b91af4f208d0699b1ad222e6da70a14a
4
+ data.tar.gz: 038f5d4d193c3dc4cf4b28d4952075e814e2c83c
5
5
  SHA512:
6
- metadata.gz: af089b88e4d1fd13ed69e23a853adca81ee3829c976dde442876adcf2de804ccaa1a41c7ab34c6adda4ec2225fe275d84e27ccffb4d5b48f7b9b266cfae8d667
7
- data.tar.gz: 956ba99b6bcd1ca62cd691efbdad934e0f71ccba101467c701c653b24c3f296b190803fc0a02c8d5f6fb7e968081e60ab57b5693ef1decc9a0be9087d7b252f1
6
+ metadata.gz: e5eae100d8ef70eb4cf1527b523a2390f0b0c797ba4c6a311dbcb20d12a592ea2f636148cc2913a6025aeca2633da888e43f926a0576a1ef461232850e96e38a
7
+ data.tar.gz: 2b4f5c397b6638653c7ddc7526aed32ff9b01b723540093fbcddc49d0abcad40024d65359f07aa5764af95afc72de32a17d24663f3b64e63dcbc7aa2f36ab726
data/README.md CHANGED
@@ -196,6 +196,27 @@ Para::SeoTools::Skeleton.draw(scope: :locale) do
196
196
  By using `I18n.with_locale`, we force the current locale in the block, and
197
197
  SeoTools automatically assigns the locale to the page resource.
198
198
 
199
+ #### Scoping page fetching in request
200
+
201
+ When you add arbitrary scope your pages, you may want Seo Tools to use these
202
+ scopes when retrieving the page to fetch meta tags, at request time.
203
+
204
+ > **Note**: The following scopes are included in default page retrieval scoping
205
+ and need not to be overriden : `:locale`, `:subdomain` and `:domain`.
206
+
207
+ Override the `#seo_tools_scope_for(request)` method in the controllers that need
208
+ to apply these scope rules. This will be the ApplicationController in most
209
+ cases. The method should return a hash.
210
+
211
+ ```
212
+ def seo_tools_scope_for(request)
213
+ super.tap do |hash|
214
+ # use `hash[:my_scope_name] = ...` here to fill or update the default scope
215
+ end
216
+ end
217
+ ```
218
+
219
+
199
220
  #### Lazy skeleton building.
200
221
 
201
222
  On large applications, building the skeleton with all its pages at application
@@ -39,12 +39,8 @@ module Para
39
39
  end
40
40
 
41
41
  def fetch_meta_tags_page
42
- page_conditions = Para::SeoTools::Page.where(path: request.path)
43
- page_conditions = page_conditions.with_subdomain(request.subdomain) if Para::SeoTools.handle_subdomain
44
- page_conditions = page_conditions.with_domain(request.domain) if Para::SeoTools.handle_domain
45
-
46
- if (page = page_conditions.first)
47
- set_meta_tags_from_page(page)
42
+ if current_seo_tools_page
43
+ set_meta_tags_from_page(current_seo_tools_page)
48
44
  end
49
45
  end
50
46
 
@@ -8,12 +8,13 @@ module Para
8
8
  initializer 'para.seo_tools.include_controller_mixin' do
9
9
  ActiveSupport.on_load(:action_controller) do
10
10
  include Para::SeoTools::Controller
11
+ include Para::SeoTools::Helpers::PageHelper
11
12
  end
12
13
  end
13
14
 
14
15
  initializer "para.seo_tools.include_view_helpers" do
15
16
  ActiveSupport.on_load(:action_view) do
16
- include Para::SeoTools::ViewHelpers
17
+ include Para::SeoTools::Helpers::ViewHelper
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,72 @@
1
+ module Para
2
+ module SeoTools
3
+ module Helpers
4
+ module PageHelper
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ # Allow module methods to be called from the view when the PageHelper
9
+ # module is included in a controller
10
+ if respond_to?(:helper_method)
11
+ helper_method :current_seo_tools_page,
12
+ :seo_tools_page_for,
13
+ :seo_tools_pages_for,
14
+ :seo_tools_scoped_sibling_for,
15
+ :seo_tools_scoped_siblings_for
16
+ end
17
+ end
18
+
19
+ def current_seo_tools_page
20
+ RequestStore.store['para.seo_tools.current_seo_tools_page'] ||=
21
+ seo_tools_page_for({ path: request.path }.merge(seo_tools_scope_for(request)))
22
+ end
23
+
24
+ # Retrieve the first page that matches the given scope conditions
25
+ #
26
+ def seo_tools_page_for(scope_hash = {})
27
+ seo_tools_pages_for(scope_hash).first
28
+ end
29
+
30
+ # Find all the pages with the given scope conditions, merged with the
31
+ # current page ones.
32
+ #
33
+ def seo_tools_pages_for(scope_hash = {})
34
+ Para::SeoTools::Page.scope_with(scope_hash)
35
+ end
36
+
37
+ def seo_tools_scoped_sibling_for(*args)
38
+ seo_tools_scoped_siblings_for(*args).first
39
+ end
40
+
41
+ def seo_tools_scoped_siblings_for(path, scope_hash = {})
42
+ source_page = if Hash === path
43
+ scope_hash = path
44
+ current_seo_tools_page
45
+ else
46
+ Para::SeoTools::Page.find_by_path(path)
47
+ end
48
+
49
+ return Para::SeoTools::Page.none unless source_page
50
+
51
+ scope_hash = scope_hash.merge(seo_tools_scope_for(request))
52
+ source_page.siblings.scope_with(scope_hash)
53
+ end
54
+
55
+ protected
56
+
57
+ # Return a simple scopes hash, letting the Page.scope_with method handle
58
+ # column and JSON field backed attributes
59
+ #
60
+ # This method is meant to be overriden in app controllers to scope
61
+ #
62
+ def seo_tools_scope_for(request)
63
+ {}.tap do |hash|
64
+ hash[:subdomain] = request.subdomain if Para::SeoTools.handle_subdomain
65
+ hash[:domain] = request.domain if Para::SeoTools.handle_domain
66
+ hash[:locale] = I18n.locale if I18n.available_locales.length > 1
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,11 @@
1
+ module Para
2
+ module SeoTools
3
+ module Helpers
4
+ module ViewHelper
5
+ def meta_tags(options = {})
6
+ MetaTags::Renderer.new(self, options).render
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Para
2
+ module SeoTools
3
+ module Helpers
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :PageHelper
7
+ autoload :ViewHelper
8
+ end
9
+ end
10
+ end
@@ -4,12 +4,6 @@ module Para
4
4
  def perform
5
5
  Para::SeoTools::Sitemap.ping_search_engines
6
6
  end
7
-
8
- private
9
-
10
- def progress_total
11
- nil
12
- end
13
7
  end
14
8
  end
15
9
  end
@@ -6,12 +6,6 @@ module Para
6
6
  Para::SeoTools::Skeleton.build(load_skeleton: true)
7
7
  Para::SeoTools::Sitemap.generate!
8
8
  end
9
-
10
- private
11
-
12
- def progress_total
13
- nil
14
- end
15
9
  end
16
10
  end
17
11
  end
@@ -1,5 +1,5 @@
1
1
  module Para
2
2
  module SeoTools
3
- VERSION = "0.4.2"
3
+ VERSION = "0.4.3"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ module Para
17
17
 
18
18
  autoload :MetaTaggable
19
19
  autoload :MetaTaggableMacro
20
- autoload :ViewHelpers
20
+ autoload :Helpers
21
21
 
22
22
  mattr_writer :host
23
23
  @@host = nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para-seo_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-06 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -126,6 +126,9 @@ files:
126
126
  - lib/para/seo_tools.rb
127
127
  - lib/para/seo_tools/controller.rb
128
128
  - lib/para/seo_tools/engine.rb
129
+ - lib/para/seo_tools/helpers.rb
130
+ - lib/para/seo_tools/helpers/page_helper.rb
131
+ - lib/para/seo_tools/helpers/view_helper.rb
129
132
  - lib/para/seo_tools/meta_tags.rb
130
133
  - lib/para/seo_tools/meta_tags/renderer.rb
131
134
  - lib/para/seo_tools/meta_tags/store.rb
@@ -149,7 +152,6 @@ files:
149
152
  - lib/para/seo_tools/skeleton/page_builder.rb
150
153
  - lib/para/seo_tools/skeleton/site.rb
151
154
  - lib/para/seo_tools/version.rb
152
- - lib/para/seo_tools/view_helpers.rb
153
155
  - lib/tasks/migration.rake
154
156
  - lib/tasks/para_seo_tools_tasks.rake
155
157
  - para-seo_tools.gemspec
@@ -1,9 +0,0 @@
1
- module Para
2
- module SeoTools
3
- module ViewHelpers
4
- def meta_tags(options = {})
5
- MetaTags::Renderer.new(self, options).render
6
- end
7
- end
8
- end
9
- end