cortex-snippets-client 0.8.1 → 1.0.0
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/CHANGELOG.md +1 -0
- data/cortex-snippets-client-ruby.gemspec +0 -1
- data/lib/cortex/snippets/client/version.rb +1 -1
- data/lib/cortex/snippets/client/webpage.rb +69 -0
- data/lib/cortex/snippets/client.rb +30 -26
- metadata +4 -19
- data/lib/cortex/snippets/client/helper.rb +0 -78
- data/lib/cortex/snippets/client/railtie.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a0a5085dbcbd4d1d792cff72f4e0b60dd38eee3
|
4
|
+
data.tar.gz: 550740427579f08cbc93f0e33f52c3cc44985bec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 086cb48328524926153665e802951de93679a79e798f133c62271e7576551dd72b989993e022812eb54745a0b534a9540b3d00ba251e5adb68ce7a3640c84416
|
7
|
+
data.tar.gz: bbd67ff27361d4157645fad1ba4e7659de1f86ec740f5a37f4a32a6e211fb93c092b2b35856f3e2c1bbb51ca6719d69e7d9095e2fb4fd3c225cbc1ce1ba526ed
|
data/CHANGELOG.md
CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
21
|
spec.add_dependency 'cortex-client', '~> 0.10'
|
22
|
-
spec.add_dependency 'connection_pool', '~> 2.2'
|
23
22
|
spec.add_dependency 'addressable', '~> 2.5'
|
24
23
|
|
25
24
|
spec.add_development_dependency 'rake', '~> 12.0'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Cortex
|
2
|
+
module Snippets
|
3
|
+
module Client
|
4
|
+
class Webpage
|
5
|
+
def initialize(cortex_client, url)
|
6
|
+
@webpage = cortex_client.webpages.get_feed(url).contents
|
7
|
+
end
|
8
|
+
|
9
|
+
def seo_title
|
10
|
+
@webpage[:seo_title]
|
11
|
+
end
|
12
|
+
|
13
|
+
def seo_description
|
14
|
+
@webpage[:seo_description]
|
15
|
+
end
|
16
|
+
|
17
|
+
def seo_keywords
|
18
|
+
@webpage[:seo_keyword_list]
|
19
|
+
end
|
20
|
+
|
21
|
+
def seo_robots
|
22
|
+
robot_information = []
|
23
|
+
index_options = [:noindex, :nofollow, :noodp, :nosnippet, :noarchive, :noimageindex]
|
24
|
+
|
25
|
+
index_options.each do |index_option|
|
26
|
+
robot_information << index_option if @webpage[index_option]
|
27
|
+
end
|
28
|
+
|
29
|
+
robot_information
|
30
|
+
end
|
31
|
+
|
32
|
+
def noindex
|
33
|
+
@webpage[:noindex]
|
34
|
+
end
|
35
|
+
|
36
|
+
def nofollow
|
37
|
+
@webpage[:nofollow]
|
38
|
+
end
|
39
|
+
|
40
|
+
def noodp
|
41
|
+
@webpage[:noodp]
|
42
|
+
end
|
43
|
+
|
44
|
+
def nosnippet
|
45
|
+
@webpage[:nosnippet]
|
46
|
+
end
|
47
|
+
|
48
|
+
def noarchive
|
49
|
+
@webpage[:noarchive]
|
50
|
+
end
|
51
|
+
|
52
|
+
def noimageindex
|
53
|
+
@webpage[:noimageindex]
|
54
|
+
end
|
55
|
+
|
56
|
+
def dynamic_yield
|
57
|
+
{
|
58
|
+
sku: @webpage[:dynamic_yield_sku],
|
59
|
+
category: @webpage[:dynamic_yield_category]
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def snippets
|
64
|
+
@webpage[:snippets]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,37 +1,41 @@
|
|
1
|
-
require 'cortex/snippets/client/
|
2
|
-
require '
|
3
|
-
require 'cortex-client'
|
4
|
-
require 'connection_pool'
|
5
|
-
require 'addressable/template'
|
1
|
+
require 'cortex/snippets/client/webpage'
|
2
|
+
require 'addressable/uri'
|
6
3
|
|
7
4
|
module Cortex
|
8
5
|
module Snippets
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
class Client
|
7
|
+
def initialize(cortex_client)
|
8
|
+
@cortex_client = cortex_client
|
9
|
+
end
|
10
|
+
|
11
|
+
def snippet(options = {}, &block)
|
12
|
+
snippets = current_webpage(@cortex_client).snippets || []
|
13
|
+
snippet = snippets.find { |snippet| snippet[:document][:name] == options[:id] }
|
14
|
+
|
15
|
+
if snippet.nil? || snippet[:document][:body].nil? || snippet[:document][:body].empty?
|
16
|
+
content_tag(:snippet, capture(&block), options)
|
17
|
+
else
|
18
|
+
content_tag(:snippet, snippet[:document][:body].html_safe, options)
|
17
19
|
end
|
20
|
+
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
else
|
26
|
-
raise 'Your Web framework is not supported. Supported frameworks: Rails'
|
22
|
+
def current_webpage
|
23
|
+
if defined?(Rails)
|
24
|
+
url = sanitized_webpage_url(request.original_url)
|
25
|
+
Rails.cache.fetch("webpages/#{@cortex_client.access_token.client.id}/#{url}", race_condition_ttl: 10) do
|
26
|
+
Cortex::Snippets::Client::Webpage.new(@cortex_client, url)
|
27
27
|
end
|
28
|
+
else
|
29
|
+
raise 'Your Web framework is not supported. Supported frameworks: Rails'
|
28
30
|
end
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
private
|
34
|
+
|
35
|
+
def sanitized_webpage_url(url)
|
36
|
+
uri = Addressable::URI.parse(url)
|
37
|
+
path = uri.path == '/' ? uri.path : uri.path.chomp('/')
|
38
|
+
"#{uri.scheme}://#{uri.authority}#{path}"
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cortex-snippets-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CareerBuilder Employer Site & Content Products
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cortex-client
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.10'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: connection_pool
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.2'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '2.2'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: addressable
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,9 +86,8 @@ files:
|
|
100
86
|
- cortex-snippets-client-ruby.gemspec
|
101
87
|
- lib/cortex-snippets-client.rb
|
102
88
|
- lib/cortex/snippets/client.rb
|
103
|
-
- lib/cortex/snippets/client/helper.rb
|
104
|
-
- lib/cortex/snippets/client/railtie.rb
|
105
89
|
- lib/cortex/snippets/client/version.rb
|
90
|
+
- lib/cortex/snippets/client/webpage.rb
|
106
91
|
homepage: https://github.com/cortex-cms/cortex-snippets-client-ruby
|
107
92
|
licenses:
|
108
93
|
- Apache-2.0
|
@@ -123,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
108
|
version: '0'
|
124
109
|
requirements: []
|
125
110
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
111
|
+
rubygems_version: 2.5.1
|
127
112
|
signing_key:
|
128
113
|
specification_version: 4
|
129
114
|
summary: Provides loading of Cortex snippets for Ruby applications, with some Rails
|
@@ -1,78 +0,0 @@
|
|
1
|
-
module Cortex
|
2
|
-
module Snippets
|
3
|
-
module Client
|
4
|
-
module Helper
|
5
|
-
def snippet(options = {}, &block)
|
6
|
-
snippets = webpage[:snippets] || []
|
7
|
-
snippet = snippets.find { |snippet| snippet[:document][:name] == options[:id] }
|
8
|
-
|
9
|
-
if snippet.nil? || snippet[:document][:body].nil? || snippet[:document][:body].empty?
|
10
|
-
content_tag(:snippet, capture(&block), options)
|
11
|
-
else
|
12
|
-
content_tag(:snippet, snippet[:document][:body].html_safe, options)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def seo_title
|
17
|
-
webpage[:seo_title]
|
18
|
-
end
|
19
|
-
|
20
|
-
def seo_description
|
21
|
-
webpage[:seo_description]
|
22
|
-
end
|
23
|
-
|
24
|
-
def seo_keywords
|
25
|
-
webpage[:seo_keyword_list]
|
26
|
-
end
|
27
|
-
|
28
|
-
def seo_robots
|
29
|
-
robot_information = []
|
30
|
-
index_options = [:noindex, :nofollow, :noodp, :nosnippet, :noarchive, :noimageindex]
|
31
|
-
|
32
|
-
index_options.each do |index_option|
|
33
|
-
robot_information << index_option if webpage[index_option]
|
34
|
-
end
|
35
|
-
|
36
|
-
robot_information
|
37
|
-
end
|
38
|
-
|
39
|
-
def noindex
|
40
|
-
webpage[:noindex]
|
41
|
-
end
|
42
|
-
|
43
|
-
def nofollow
|
44
|
-
webpage[:nofollow]
|
45
|
-
end
|
46
|
-
|
47
|
-
def noodp
|
48
|
-
webpage[:noodp]
|
49
|
-
end
|
50
|
-
|
51
|
-
def nosnippet
|
52
|
-
webpage[:nosnippet]
|
53
|
-
end
|
54
|
-
|
55
|
-
def noarchive
|
56
|
-
webpage[:noarchive]
|
57
|
-
end
|
58
|
-
|
59
|
-
def noimageindex
|
60
|
-
webpage[:noimageindex]
|
61
|
-
end
|
62
|
-
|
63
|
-
def dynamic_yield
|
64
|
-
{
|
65
|
-
sku: webpage[:dynamic_yield_sku],
|
66
|
-
category: webpage[:dynamic_yield_category]
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def webpage
|
73
|
-
Cortex::Snippets::Client::current_webpage(request)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Cortex
|
2
|
-
module Snippets
|
3
|
-
module Client
|
4
|
-
class Railtie < Rails::Railtie
|
5
|
-
initializer 'cortex-snippets-client.view_controller_helpers' do |app|
|
6
|
-
ActiveSupport.on_load :action_view do
|
7
|
-
include Helper
|
8
|
-
end
|
9
|
-
|
10
|
-
ActiveSupport.on_load :action_controller do
|
11
|
-
include Helper
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|