Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 71
- Log:
Start of upgrade to Typo 4.0.0, the latest stable release since
2.6.0. Note test/mocks/themes/azure changes from a file to a
directory, so the file has been removed in this revision and
the directory will be added in the next revision.
- Author:
- adh
- Date:
- Mon Aug 07 22:18:11 +0100 2006
- Size:
- 6181 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].blank?, options) |
67 | end |
68 | |
69 | def line_html(sidebar) |
70 | input_html(sidebar) + ' ' + label_html(sidebar) + '<br >' |
71 | end |
72 | end |
73 | |
74 | def self.build(key, options) |
75 | field = class_for(options).new(key, options) |
76 | end |
77 | |
78 | def self.class_for(options) |
79 | case options[:input_type] |
80 | when :text_area |
81 | TextAreaField |
82 | when :textarea |
83 | TextAreaField |
84 | when :radio |
85 | RadioField |
86 | when :checkbox |
87 | CheckBoxField |
88 | when :select |
89 | SelectField |
90 | else |
91 | if options[:choices] |
92 | SelectField |
93 | else |
94 | self |
95 | end |
96 | end |
97 | end |
98 | end |
99 | |
100 | |
101 | class Sidebars::Plugin < ApplicationController |
102 | include ApplicationHelper |
103 | helper :theme |
104 | |
105 | @@subclasses = { } |
106 | |
107 | class << self |
108 | def inherited(child) |
109 | @@subclasses[self] ||= [] |
110 | @@subclasses[self] |= [child] |
111 | super |
112 | end |
113 | |
114 | def subclasses |
115 | @@subclasses[self] ||= [] |
116 | @@subclasses[self] + extra = |
117 | @@subclasses[self].inject([]) {|list, subclass| list | subclass.subclasses } |
118 | end |
119 | |
120 | def available_sidebars |
121 | @@available_sidebars ||= Sidebars::Plugin.subclasses.select do |sidebar| |
122 | sidebar.subclasses.empty? |
123 | end |
124 | end |
125 | |
126 | # The name that needs to be used when refering to the plugin's |
127 | # controller in render statements |
128 | def component_name |
129 | if (self.to_s=~/::([a-zA-Z]+)Controller/) |
130 | "plugins/sidebars/#{$1}".underscore |
131 | else |
132 | raise "I don't know who I am: #{self.to_s}" |
133 | end |
134 | end |
135 | |
136 | # The name that's stored in the DB. This is the final chunk of the |
137 | # controller name, like 'xml' or 'flickr'. |
138 | def short_name |
139 | component_name.split(%r{/}).last |
140 | end |
141 | |
142 | @@display_name_of = { } |
143 | @@description_of = { } |
144 | |
145 | # The name that shows up in the UI |
146 | def display_name(new_dn = nil) |
147 | # This is the default, but it's best to override it |
148 | self.display_name = new_dn if new_dn |
149 | @@display_name_of[self] || short_name.humanize |
150 | end |
151 | |
152 | def display_name=(name) |
153 | @@display_name_of[self] = name |
154 | end |
155 | |
156 | def description(new_desc = nil) |
157 | self.description = new_desc if new_desc |
158 | @@description_of[self] || short_name.humanize |
159 | end |
160 | |
161 | def description=(desc) |
162 | @@description_of[self] = desc |
163 | end |
164 | |
165 | @@fields = { } |
166 | @@default_config = { } |
167 | def setting(key, default=nil, options={ }) |
168 | fields << Field.build(key, options) |
169 | default_config[key.to_s] = default |
170 | self.send(:define_method, key) do |
171 | @sb_config[key.to_s] |
172 | end |
173 | self.helper_method(key) |
174 | end |
175 | |
176 | def default_config |
177 | @@default_config[self] ||= HashWithIndifferentAccess.new |
178 | end |
179 | |
180 | def default_config=(newval) |
181 | @@default_config[self] = newval |
182 | end |
183 | |
184 | def fields |
185 | @@fields[self] ||= [] |
186 | end |
187 | |
188 | def fields=(newval) |
189 | @@fields[self] = newval |
190 | end |
191 | |
192 | def default_helper_module! |
193 | end |
194 | end |
195 | |
196 | def index |
197 | @sidebar=params['sidebar'] |
198 | set_config |
199 | @sb_config = @sidebar.config |
200 | content |
201 | render :action=>'content' unless performed? |
202 | end |
203 | |
204 | def configure_wrapper |
205 | @sidebar=params['sidebar'] |
206 | set_config |
207 | configure |
208 | render :action=>'configure' unless performed? |
209 | end |
210 | |
211 | # This controller is used on to actually display sidebar items. |
212 | def content |
213 | end |
214 | |
215 | # This controller is used to configure the sidebar from /admin/sidebar |
216 | def configure |
217 | render :partial => 'sidebar/row', :collection => self.class.fields |
218 | end |
219 | |
220 | private |
221 | def set_config |
222 | @sidebar.config ||= {} |
223 | @sidebar.config = self.class.default_config.dup.merge(@sidebar.config) |
224 | @sidebar.config ||= (self.class.default_config) |
225 | end |
226 | |
227 | def sb_config(key) |
228 | config = @sidebar.class.default_config |
229 | config.merge!(@sidebar.config || {}) |
230 | config[key.to_s] |
231 | end |
232 | |
233 | # Horrid hack to make check_cache happy |
234 | def controller |
235 | self |
236 | end |
237 | |
238 | def log_processing |
239 | logger.info "\n\nProcessing #{controller_class_name}\##{action_name} (for #{request_origin})" |
240 | end |
241 | |
242 | end |
243 | end |