Skip to content

Commit 2b72ce9

Browse files
Alex TharpAlex Tharp
Alex Tharp
authored and
Alex Tharp
committed
Merge pull request #17 from cortex-cms/restructuring
Restructuring
2 parents 6beefb3 + 869f286 commit 2b72ce9

13 files changed

+100
-79
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Version History
2+
====
3+
* All Version bumps are required to update this file as well!!
4+
----
5+
6+
* 0.5.0 - Auto-inject Client Helper into Views/Controllers. Pass through to Snippet tag entire set of HTML attributes. Implement new namespacing and support Bundler.require.

cortex-snippets-client-ruby.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# coding: utf-8
22
lib = File.expand_path('../lib', __FILE__)
33
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4-
require 'cortex/snippets/version'
4+
require 'cortex/snippets/client/version'
55

66
Gem::Specification.new do |spec|
77
spec.name = 'cortex-snippets-client-ruby'
8-
spec.version = Cortex::Snippets::VERSION
8+
spec.version = Cortex::Snippets::Client::VERSION
99
spec.authors = ['CB Content Enablement']
1010
spec.email = ['[email protected]']
1111
spec.license = 'Apache-2.0'

lib/cortex-snippets-client-ruby.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require 'cortex/snippets/client'
2+
require 'cortex/snippets/client/version'

lib/cortex/snippets-client.rb

-4
This file was deleted.

lib/cortex/snippets/client.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'cortex/snippets/client/helper'
2+
require 'cortex/snippets/client/railtie' if defined?(Rails)
13
require 'cortex-client'
24
require 'connection_pool'
35
require 'addressable/template'
@@ -16,16 +18,14 @@ def cortex_client
1618

1719
def current_webpage(request)
1820
if defined?(Rails)
19-
Rails.cache.fetch("webpages/#{request_url(request)}", expires_in: 30.minutes) do
21+
Rails.cache.fetch("webpages/#{request_url(request)}", expires_in: 30.minutes, race_condition_ttl: 10) do
2022
cortex_client.webpages.get_feed(request_url(request)).contents
2123
end
2224
else
2325
raise 'Your Web framework is not supported. Supported frameworks: Rails'
2426
end
2527
end
2628

27-
private
28-
2929
def request_url(request)
3030
# TODO: Should be grabbing request URL in a framework-agnostic manner, but this is fine for now
3131
uri = Addressable::URI.parse(request.original_url)

lib/cortex/snippets/client/helper.rb

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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_keywords]
26+
end
27+
28+
def noindex
29+
webpage[:noindex]
30+
end
31+
32+
def nofollow
33+
webpage[:nofollow]
34+
end
35+
36+
def noodp
37+
webpage[:noodp]
38+
end
39+
40+
def nosnippet
41+
webpage[:nosnippet]
42+
end
43+
44+
def noarchive
45+
webpage[:noarchive]
46+
end
47+
48+
def noimageindex
49+
webpage[:noimageindex]
50+
end
51+
52+
private
53+
54+
def webpage
55+
Cortex::Snippets::Client::current_webpage(request)
56+
end
57+
end
58+
end
59+
end
60+
end

lib/cortex/snippets/client/railtie.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

lib/cortex/snippets/client/version.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Cortex
2+
module Snippets
3+
module Client
4+
VERSION = '0.5.0'
5+
end
6+
end
7+
end

lib/cortex/snippets/railtie.rb

-9
This file was deleted.

lib/cortex/snippets/version.rb

-5
This file was deleted.

lib/cortex/snippets/view_helpers.rb

-53
This file was deleted.

spec/cortex/snippets_client_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

3-
describe Cortex::Snippets do
3+
describe Cortex::Snippets::Client do
44
it 'has a version number' do
5-
expect(Cortex::Snippets::VERSION).not_to be nil
5+
expect(Cortex::Snippets::Client::VERSION).not_to be nil
66
end
77
end

spec/spec_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2-
require 'cortex/snippets-client'
2+
require 'cortex-snippets-client-ruby'

0 commit comments

Comments
 (0)