forked from saturnflyer/radiant-sheets-extension
-
Notifications
You must be signed in to change notification settings - Fork 7
/
sheets_extension.rb
59 lines (49 loc) · 1.79 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
# 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 ||= []
begin
@@javascript_filters << CoffeeFilter
rescue ExecJS::RuntimeUnavailable
Rails.logger.warn "There is no support for CoffeeScript"
end
def activate
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
end
end