-
Notifications
You must be signed in to change notification settings - Fork 9
/
sheets_extension.rb
76 lines (64 loc) · 2.23 KB
/
sheets_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 'compass'
require 'radiant-sheets-extension/version'
class SheetsExtension < Radiant::Extension
version RadiantSheetsExtension::VERSION
description "Manage CSS and Javascript content in Radiant CMS as Sheets, a subset of Pages"
url "http://github.com/radiant/radiant"
cattr_accessor :stylesheet_filters
cattr_accessor :javascript_filters
@@stylesheet_filters ||= []
@@stylesheet_filters += [SassFilter, ScssFilter]
@@javascript_filters ||= []
@@javascript_filters << CoffeeFilter
def activate
SassFilter
ScssFilter
CoffeeFilter
MenuRenderer.exclude 'JavascriptPage', 'StylesheetPage'
tab 'Design' do
add_item "Stylesheets", "/admin/styles"
add_item "Javascripts", "/admin/scripts"
end
ApplicationHelper.module_eval do
def filter_options_for_select_with_sheet_restrictions(selected=nil)
sheet_filters = SheetsExtension.stylesheet_filters + SheetsExtension.javascript_filters
filters = TextFilter.descendants - sheet_filters
options_for_select([[t('select.none'), '']] + filters.map { |s| s.filter_name }.sort, selected)
end
alias_method_chain :filter_options_for_select, :sheet_restrictions
end
Page.class_eval do
def sheet?
self.is_a?(Sheet::Instance)
end
include JavascriptTags
include StylesheetTags
end
Admin::NodeHelper.module_eval do
def render_node_with_sheets(page, locals = {})
unless page.sheet?
render_node_without_sheets(page, locals)
end
end
alias_method_chain :render_node, :sheets
end
SiteController.class_eval do
def self.sheet_cache_timeout
@sheet_cache_timeout ||= 30.days
end
def self.sheet_cache_timeout=(val)
@sheet_cache_timeout = val
end
def set_cache_control_with_sheets
if @page.sheet?
expires_in self.class.sheet_cache_timeout, :public => true, :private => false
else
set_cache_control_without_sheets
end
end
alias_method_chain :set_cache_control, :sheets
end
end
end