Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 6129 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), 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 | |
104 | helper :theme |
105 | |
106 | # skip_before_filter :get_the_blog_object |
107 | # skip_after_filter :flush_the_blog_object |
108 | |
109 | @@subclasses = { } |
110 | |
111 | class << self |
112 | def inherited(child) |
113 | @@subclasses[self] ||= [] |
114 | @@subclasses[self] |= [child] |
115 | super |
116 | end |
117 | |
118 | def subclasses |
119 | @@subclasses[self] ||= [] |
120 | @@subclasses[self] + extra = |
121 | @@subclasses[self].inject([]) {|list, subclass| list | subclass.subclasses } |
122 | end |
123 | |
124 | def available_sidebars |
125 | @@available_sidebars ||= Sidebars::Plugin.subclasses.select do |sidebar| |
126 | sidebar.subclasses.empty? |
127 | end |
128 | end |
129 | |
130 | |
131 | # The name that needs to be used when refering to the plugin's |
132 | # controller in render statements |
133 | def component_name |
134 | if (self.to_s=~/::([a-zA-Z]+)Controller/) |
135 | "plugins/sidebars/#{$1}".underscore |
136 | else |
137 | raise "I don't know who I am: #{self.to_s}" |
138 | end |
139 | end |
140 | |
141 | # The name that's stored in the DB. This is the final chunk of the |
142 | # controller name, like 'xml' or 'flickr'. |
143 | def short_name |
144 | component_name.split(%r{/}).last |
145 | end |
146 | |
147 | @@display_name_of = { } |
148 | @@description_of = { } |
149 | |
150 | # The name that shows up in the UI |
151 | def display_name(new_dn = nil) |
152 | # This is the default, but it's best to override it |
153 | self.display_name = new_dn if new_dn |
154 | @@display_name_of[self] || short_name.humanize |
155 | end |
156 | |
157 | def display_name=(name) |
158 | @@display_name_of[self] = name |
159 | end |
160 | |
161 | def description(new_desc = nil) |
162 | self.description = new_desc if new_desc |
163 | @@description_of[self] || short_name.humanize |
164 | end |
165 | |
166 | def description=(desc) |
167 | @@description_of[self] = desc |
168 | end |
169 | |
170 | @@fields = { } |
171 | @@default_config = { } |
172 | def setting(key, default=nil, options={ }) |
173 | fields << Field.build(key, options) |
174 | default_config[key.to_s] = default |
175 | self.send(:define_method, key) do |
176 | @sb_config[key.to_s] |
177 | end |
178 | self.helper_method(key) |
179 | end |
180 | |
181 | def default_config |
182 | @@default_config[self] ||= HashWithIndifferentAccess.new |
183 | end |
184 | |
185 | def default_config=(newval) |
186 | @@default_config[self] = newval |
187 | end |
188 | |
189 | def fields |
190 | @@fields[self] ||= [] |
191 | end |
192 | |
193 | def fields=(newval) |
194 | @@fields[self] = newval |
195 | end |
196 | |
197 | def default_helper_module! |
198 | end |
199 | end |
200 | |
201 | def index |
202 | @sidebar=params['sidebar'] |
203 | @sb_config = @sidebar.config || self.class.default_config |
204 | content |
205 | render :action=>'content' unless performed? |
206 | end |
207 | |
208 | def configure_wrapper |
209 | @sidebar=params['sidebar'] |
210 | @sidebar.config ||= (self.class.default_config) |
211 | configure |
212 | render :action=>'configure' unless performed? |
213 | end |
214 | |
215 | # This controller is used on to actually display sidebar items. |
216 | def content |
217 | end |
218 | |
219 | # This controller is used to configure the sidebar from /admin/sidebar |
220 | def configure |
221 | render :partial => 'sidebar/row', :collection => self.class.fields |
222 | end |
223 | |
224 | private |
225 | def sb_config(key) |
226 | config = @sidebar.class.default_config |
227 | config.merge!(@sidebar.config || {}) |
228 | config[key.to_s] |
229 | end |
230 | |
231 | # Horrid hack to make check_cache happy |
232 | def controller |
233 | self |
234 | end |
235 | |
236 | def log_processing |
237 | logger.info "\n\nProcessing #{controller_class_name}\##{action_name} (for #{request_origin})" |
238 | end |
239 | |
240 | end |
241 | end |