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 2
2
lib = File . expand_path ( '../lib' , __FILE__ )
3
3
$LOAD_PATH. unshift ( lib ) unless $LOAD_PATH. include? ( lib )
4
4
require 'cortex/snippets/version'
5
+ require 'cortex-client'
6
+ require 'connection_pool'
5
7
6
8
Gem ::Specification . new do |spec |
7
9
spec . name = 'cortex-snippets-client-ruby'
@@ -18,7 +20,7 @@ Gem::Specification.new do |spec|
18
20
spec . executables = spec . files . grep ( %r{^exe/} ) { |f | File . basename ( f ) }
19
21
spec . require_paths = [ 'lib' ]
20
22
21
- spec . add_dependency 'cortex-client' , '~> 0.4.3 '
23
+ spec . add_dependency 'cortex-client' , '~> 0.4.5 '
22
24
spec . add_dependency 'connection_pool' , '~> 2.2.0'
23
25
24
26
spec . add_development_dependency 'bundler' , '~> 1.10'
Original file line number Diff line number Diff line change @@ -10,10 +10,10 @@ def cortex_client
10
10
end
11
11
end
12
12
13
- def current_webpage
13
+ def current_webpage ( request )
14
14
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 ) )
17
17
end
18
18
else
19
19
raise 'Your Web framework is not supported. Supported frameworks: Rails'
@@ -22,8 +22,8 @@ def current_webpage
22
22
23
23
private
24
24
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
27
27
request . original_url
28
28
end
29
29
end
Original file line number Diff line number Diff line change 1
1
module Cortex
2
2
module Snippets
3
3
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
6
12
end
7
13
8
14
def seo_title
9
- Client :: current_webpage [ :seo_title ]
15
+ webpage [ :seo_title ]
10
16
end
11
17
12
18
def seo_description
13
- Client :: current_webpage [ :seo_description ]
19
+ webpage [ :seo_description ]
14
20
end
15
21
16
22
def noindex
17
- Client :: current_webpage [ :noindex ]
23
+ webpage [ :noindex ]
18
24
end
19
25
20
26
def nofollow
21
- Client :: current_webpage [ :nofollow ]
27
+ webpage [ :nofollow ]
22
28
end
23
29
24
30
def noodp
25
- Client :: current_webpage [ :noodp ]
31
+ webpage [ :noodp ]
26
32
end
27
33
28
34
def nosnippet
29
- Client :: current_webpage [ :nosnippet ]
35
+ webpage [ :nosnippet ]
30
36
end
31
37
32
38
def noarchive
33
- Client :: current_webpage [ :noarchive ]
39
+ webpage [ :noarchive ]
34
40
end
35
41
36
42
def noimageindex
37
- Client ::current_webpage [ :noimageindex ]
43
+ webpage [ :noimageindex ]
44
+ end
45
+
46
+ private
47
+
48
+ def webpage
49
+ Client ::current_webpage ( request )
38
50
end
39
51
end
40
52
end
You can’t perform that action at this time.
0 commit comments