Skip to content

Restructuring #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Version History
====
* All Version bumps are required to update this file as well!!
----

* 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.
4 changes: 2 additions & 2 deletions cortex-snippets-client-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cortex/snippets/version'
require 'cortex/snippets/client/version'

Gem::Specification.new do |spec|
spec.name = 'cortex-snippets-client-ruby'
spec.version = Cortex::Snippets::VERSION
spec.version = Cortex::Snippets::Client::VERSION
spec.authors = ['CB Content Enablement']
spec.email = ['ContentEnablementProductTeam@careerbuilder.com']
spec.license = 'Apache-2.0'
Expand Down
2 changes: 2 additions & 0 deletions lib/cortex-snippets-client-ruby.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'cortex/snippets/client'
require 'cortex/snippets/client/version'
4 changes: 0 additions & 4 deletions lib/cortex/snippets-client.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/cortex/snippets/client.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'cortex/snippets/client/helper'
require 'cortex/snippets/client/railtie' if defined?(Rails)
require 'cortex-client'
require 'connection_pool'
require 'addressable/template'
Expand All @@ -16,16 +18,14 @@ def cortex_client

def current_webpage(request)
if defined?(Rails)
Rails.cache.fetch("webpages/#{request_url(request)}", expires_in: 30.minutes) do
Rails.cache.fetch("webpages/#{request_url(request)}", expires_in: 30.minutes, race_condition_ttl: 10) do
cortex_client.webpages.get_feed(request_url(request)).contents
end
else
raise 'Your Web framework is not supported. Supported frameworks: Rails'
end
end

private

def request_url(request)
# TODO: Should be grabbing request URL in a framework-agnostic manner, but this is fine for now
uri = Addressable::URI.parse(request.original_url)
Expand Down
60 changes: 60 additions & 0 deletions lib/cortex/snippets/client/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module Cortex
module Snippets
module Client
module Helper
def snippet(options = {}, &block)
snippets = webpage[:snippets] || []
snippet = snippets.find { |snippet| snippet[:document][:name] == options[:id] }

if snippet.nil? || snippet[:document][:body].nil? || snippet[:document][:body].empty?
content_tag(:snippet, capture(&block), options)
else
content_tag(:snippet, snippet[:document][:body].html_safe, options)
end
end

def seo_title
webpage[:seo_title]
end

def seo_description
webpage[:seo_description]
end

def seo_keywords
webpage[:seo_keywords]
end

def noindex
webpage[:noindex]
end

def nofollow
webpage[:nofollow]
end

def noodp
webpage[:noodp]
end

def nosnippet
webpage[:nosnippet]
end

def noarchive
webpage[:noarchive]
end

def noimageindex
webpage[:noimageindex]
end

private

def webpage
Cortex::Snippets::Client::current_webpage(request)
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/cortex/snippets/client/railtie.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Cortex
module Snippets
module Client
class Railtie < Rails::Railtie
initializer 'cortex-snippets-client.view_controller_helpers' do |app|
ActiveSupport.on_load :action_view do
include Helper
end

ActiveSupport.on_load :action_controller do
include Helper
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions lib/cortex/snippets/client/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Cortex
module Snippets
module Client
VERSION = '0.5.0'
end
end
end
9 changes: 0 additions & 9 deletions lib/cortex/snippets/railtie.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/cortex/snippets/version.rb

This file was deleted.

53 changes: 0 additions & 53 deletions lib/cortex/snippets/view_helpers.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/cortex/snippets_client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Cortex::Snippets do
describe Cortex::Snippets::Client do
it 'has a version number' do
expect(Cortex::Snippets::VERSION).not_to be nil
expect(Cortex::Snippets::Client::VERSION).not_to be nil
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'cortex/snippets-client'
require 'cortex-snippets-client-ruby'