Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 5965 Bytes
1 | module Sidebars |
2 | class Field |
3 | attr_accessor :key |
4 | attr_accessor :options |
5 | include ApplicationHelper |
6 | include ActionView::Helpers::TagHelper |
7 | include ActionView::Helpers::FormTagHelper |
8 | include ActionView::Helpers::FormOptionsHelper |
9 | |
10 | def initialize(key = nil, options = { }) |
11 | @key, @options = key.to_s, options |
12 | end |
13 | |
14 | def label_html(sidebar) |
15 | content_tag('label', options[:label] || key.humanize.gsub(/url/i, 'URL')) |
16 | end |
17 | |
18 | def input_html(sidebar) |
19 | text_field_tag(input_name(sidebar), sidebar.config[key], options) |
20 | end |
21 | |
22 | def line_html(sidebar) |
23 | label_html(sidebar) + "<br />" + input_html(sidebar) + "<br />" |
24 | end |
25 | |
26 | def input_name(sidebar) |
27 | "configure[#{sidebar.id}][#{key}]" |
28 | end |
29 | |
30 | class SelectField < self |
31 | def input_html(sidebar) |
32 | select_tag(input_name(sidebar), |
33 | options_for_select(options[:choices], sidebar.config[key]), |
34 | options) |
35 | end |
36 | end |
37 | |
38 | class TextAreaField < self |
39 | def input_html(sidebar) |
40 | html_options = { "rows" => "10", "cols" => "30", "style" => "width:255px"}.update(options.stringify_keys) |
41 | text_area_tag(input_name(sidebar), h(sidebar.config[key]), html_options) |
42 | end |
43 | end |
44 | |
45 | class RadioField < self |
46 | def input_html(sidebar) |
47 | options[:choices].collect do |choice| |
48 | value = value_for(choice) |
49 | radio_button_tag(input_name(sidebar), value, |
50 | value == sidebar.config[key], options) + |
51 | content_tag('label', label_for(choice)) |
52 | end.join("<br />") |
53 | end |
54 | |
55 | def label_for(choice) |
56 | choice.is_a?(Array) ? choice.last : choice.to_s.humanize |
57 | end |
58 | |
59 | def value_for(choice) |
60 | choice.is_a?(Array) ? choice.first : choice |
61 | end |
62 | end |
63 | |
64 | class CheckBoxField < self |
65 | def input_html(sidebar) |
66 | check_box_tag(input_name(sidebar), 1, sidebar.config[key], options)+ |
67 | hidden_field_tag(input_name(sidebar),0) |
68 | end |
69 | |
70 | def line_html(sidebar) |
71 | input_html(sidebar) + ' ' + label_html(sidebar) + '<br >' |
72 | end |
73 | end |
74 | |
75 | def self.build(key, options) |
76 | field = class_for(options).new(key, options) |
77 | end |
78 | |
79 | def self.class_for(options) |
80 | case options[:input_type] |
81 | when :text_area |
82 | TextAreaField |
83 | when :textarea |
84 | TextAreaField |
85 | when :radio |
86 | RadioField |
87 | when :checkbox |
88 | CheckBoxField |
89 | when :select |
90 | SelectField |
91 | else |
92 | if options[:choices] |
93 | SelectField |
94 | else |
95 | self |
96 | end |
97 | end |
98 | end |
99 | end |
100 | |
101 | |
102 | class Sidebars::Plugin < ApplicationController |
103 | include ApplicationHelper |
104 | helper :theme |
105 | |
106 | @@subclasses = { } |
107 | |
108 | class << self |
109 | def inherited(child) |
110 | @@subclasses[self] ||= [] |
111 | @@subclasses[self] |= [child] |
112 | super |
113 | end |
114 | |
115 | def subclasses |
116 | @@subclasses[self] ||= [] |
117 | @@subclasses[self] + extra = |
118 | @@subclasses[self].inject([]) {|list, subclass| list | subclass.subclasses } |
119 | end |
120 | |
121 | def available_sidebars |
122 | Sidebars::Plugin.subclasses.select do |sidebar| |
123 | sidebar.concrete? |
124 | end |
125 | end |
126 | |
127 | |
128 | def concrete? |
129 | self.to_s !~ /^Sidebars::(Co(mponent|nsolidated))?Plugin/ |
130 | end |
131 | |
132 | # The name that's stored in the DB. This is the final chunk of the |
133 | # controller name, like 'xml' or 'flickr'. |
134 | def short_name |
135 | self.to_s.underscore.split(%r{/}).last |
136 | end |
137 | |
138 | @@display_name_of = { } |
139 | @@description_of = { } |
140 | |
141 | # The name that shows up in the UI |
142 | def display_name(new_dn = nil) |
143 | # This is the default, but it's best to override it |
144 | self.display_name = new_dn if new_dn |
145 | @@display_name_of[self] || short_name.humanize |
146 | end |
147 | |
148 | def display_name=(name) |
149 | @@display_name_of[self] = name |
150 | end |
151 | |
152 | def description(new_desc = nil) |
153 | self.description = new_desc if new_desc |
154 | @@description_of[self] || short_name.humanize |
155 | end |
156 | |
157 | def description=(desc) |
158 | @@description_of[self] = desc |
159 | end |
160 | |
161 | @@fields = { } |
162 | @@default_config = { } |
163 | def setting(key, default=nil, options={ }) |
164 | fields << Field.build(key, options) |
165 | default_config[key.to_s] = default |
166 | self.send(:define_method, key) do |
167 | @sb_config[key.to_s] |
168 | end |
169 | self.helper_method(key) |
170 | end |
171 | |
172 | def default_config |
173 | @@default_config[self] ||= HashWithIndifferentAccess.new |
174 | end |
175 | |
176 | def default_config=(newval) |
177 | @@default_config[self] = newval |
178 | end |
179 | |
180 | def fields |
181 | @@fields[self] ||= [] |
182 | end |
183 | |
184 | def fields=(newval) |
185 | @@fields[self] = newval |
186 | end |
187 | |
188 | def default_helper_module! |
189 | end |
190 | end |
191 | |
192 | def index |
193 | @sidebar=params['sidebar'] |
194 | set_config |
195 | @sb_config = @sidebar.config |
196 | content |
197 | render :action=>'content' unless performed? |
198 | end |
199 | |
200 | def configure_wrapper |
201 | @sidebar=params['sidebar'] |
202 | set_config |
203 | configure |
204 | render :action=>'configure' unless performed? |
205 | end |
206 | |
207 | # This controller is used on to actually display sidebar items. |
208 | def content |
209 | end |
210 | |
211 | # This controller is used to configure the sidebar from /admin/sidebar |
212 | def configure |
213 | render :partial => 'sidebar/row', :collection => self.class.fields |
214 | end |
215 | |
216 | private |
217 | def set_config |
218 | @sidebar.config ||= {} |
219 | @sidebar.config = self.class.default_config.dup.merge(@sidebar.config) |
220 | @sidebar.config ||= (self.class.default_config) |
221 | end |
222 | |
223 | def sb_config(key) |
224 | config = @sidebar.class.default_config |
225 | config.merge!(@sidebar.config || {}) |
226 | config[key.to_s] |
227 | end |
228 | |
229 | # Horrid hack to make check_cache happy |
230 | def controller |
231 | self |
232 | end |
233 | |
234 | def log_processing |
235 | logger.info "\n\nProcessing #{controller_class_name}\##{action_name} (for #{request_origin})" |
236 | end |
237 | |
238 | end |
239 | end |