File tree Expand file tree Collapse file tree 3 files changed +30
-16
lines changed
Expand file tree Collapse file tree 3 files changed +30
-16
lines changed Original file line number Diff line number Diff line change 22lib = File . expand_path ( '../lib' , __FILE__ )
33$LOAD_PATH. unshift ( lib ) unless $LOAD_PATH. include? ( lib )
44require 'cortex/snippets/version'
5+ require 'cortex-client'
6+ require 'connection_pool'
57
68Gem ::Specification . new do |spec |
79 spec . name = 'cortex-snippets-client-ruby'
@@ -18,7 +20,7 @@ Gem::Specification.new do |spec|
1820 spec . executables = spec . files . grep ( %r{^exe/} ) { |f | File . basename ( f ) }
1921 spec . require_paths = [ 'lib' ]
2022
21- spec . add_dependency 'cortex-client' , '~> 0.4.3 '
23+ spec . add_dependency 'cortex-client' , '~> 0.4.5 '
2224 spec . add_dependency 'connection_pool' , '~> 2.2.0'
2325
2426 spec . add_development_dependency 'bundler' , '~> 1.10'
Original file line number Diff line number Diff line change @@ -10,10 +10,10 @@ def cortex_client
1010 end
1111 end
1212
13- def current_webpage
13+ def current_webpage ( request )
1414 if defined? ( Rails )
15- Rails . cache . fetch ( "webpages/#{ request_url } " , expires_in : 30 . minutes ) do
16- cortex_client . webpages . get_feed ( request_url )
15+ Rails . cache . fetch ( "webpages/#{ request_url ( request ) } " , expires_in : 30 . minutes ) do
16+ cortex_client . webpages . get_feed ( request_url ( request ) )
1717 end
1818 else
1919 raise 'Your Web framework is not supported. Supported frameworks: Rails'
@@ -22,8 +22,8 @@ def current_webpage
2222
2323 private
2424
25- def request_url
26- # TODO: Should be turbo-easy to grab request URL from Rack , but this is fine for now
25+ def request_url ( request )
26+ # TODO: Should be grabbing request URL in a framework-agnostic manner , but this is fine for now
2727 request . original_url
2828 end
2929 end
Original file line number Diff line number Diff line change 11module Cortex
22 module Snippets
33 module ViewHelpers
4- def snippet ( id )
5- content_tag ( :snippet , Client ::current_webpage [ :snippets ] . find { |snippet | snippet . name == id } , id : id )
4+ def snippet ( options = { } , &block )
5+ snippet = webpage [ :snippets ] . find { |snippet | snippet . name == options [ :id ] }
6+
7+ if snippet . empty?
8+ content_tag ( :snippet , capture ( &block ) , id : options [ :id ] )
9+ else
10+ content_tag ( :snippet , snippet , id : options [ :id ] )
11+ end
612 end
713
814 def seo_title
9- Client :: current_webpage [ :seo_title ]
15+ webpage [ :seo_title ]
1016 end
1117
1218 def seo_description
13- Client :: current_webpage [ :seo_description ]
19+ webpage [ :seo_description ]
1420 end
1521
1622 def noindex
17- Client :: current_webpage [ :noindex ]
23+ webpage [ :noindex ]
1824 end
1925
2026 def nofollow
21- Client :: current_webpage [ :nofollow ]
27+ webpage [ :nofollow ]
2228 end
2329
2430 def noodp
25- Client :: current_webpage [ :noodp ]
31+ webpage [ :noodp ]
2632 end
2733
2834 def nosnippet
29- Client :: current_webpage [ :nosnippet ]
35+ webpage [ :nosnippet ]
3036 end
3137
3238 def noarchive
33- Client :: current_webpage [ :noarchive ]
39+ webpage [ :noarchive ]
3440 end
3541
3642 def noimageindex
37- Client ::current_webpage [ :noimageindex ]
43+ webpage [ :noimageindex ]
44+ end
45+
46+ private
47+
48+ def webpage
49+ Client ::current_webpage ( request )
3850 end
3951 end
4052 end
You can’t perform that action at this time.
0 commit comments