forked from SamWhited/radiant-news-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews_extension.rb
76 lines (64 loc) · 2.01 KB
/
news_extension.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Uncomment this if you reference any of your controllers in activate
# require_dependency "application_controller"
require "radiant-news-extension"
class NewsExtension < Radiant::Extension
version RadiantNewsExtension::VERSION
description RadiantNewsExtension::DESCRIPTION
url RadiantNewsExtension::URL
# See your config/routes.rb file in this extension to define custom routes
extension_config do |config|
end
cattr_accessor :news_types, :news_paths
@@news_types ||= ['General']
@@news_paths ||= ['/news/']
def activate
MenuRenderer.exclude 'NewsPage'
tab 'Content' do
add_item "News", "/admin/news", :after => "Pages", :visibility => [:developer, :admin]
end
Page.class_eval do
def news?
self.is_a?(News::Instance)
end
include NewsTags
end
if defined?(ArchiveExtension)
ArchivePage.class_eval do
alias_method :child_path_original, :child_path
def child_path(child)
cleaned_path = clean_path(path)
if (NewsExtension.news_paths.any? { |i| clean_path(i) == cleaned_path } && !child.news?)
# Page.child_path(child)
clean_path(path + '/' + child.slug)
else
child_path_original(child)
end
end
end
end
Admin::NodeHelper.module_eval do
def render_node_with_news(page, locals = {})
unless page.news?
render_node_without_news(page, locals)
end
end
alias_method_chain :render_node, :news
end
SiteController.class_eval do
def self.news_cache_timeout
@news_cache_timeout ||= 7.days
end
def self.news_cache_timeout=(val)
@news_cache_timeout = val
end
def set_cache_control_with_news
if @page.news?
expires_in self.class.news_cache_timeout, :public => true, :private => false
else
set_cache_control_without_news
end
end
alias_method_chain :set_cache_control, :news
end
end
end