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:
- 5632 Bytes
1 | class Sidebar < ActiveRecord::Base |
2 | serialize :config |
3 | belongs_to :blog |
4 | |
5 | class Field |
6 | attr_accessor :key |
7 | attr_accessor :options |
8 | attr_accessor :default |
9 | include ApplicationHelper |
10 | include ActionView::Helpers::TagHelper |
11 | include ActionView::Helpers::FormTagHelper |
12 | include ActionView::Helpers::FormOptionsHelper |
13 | |
14 | def initialize(key, default, options = { }) |
15 | @key, @default, @options = key.to_s, default, options |
16 | end |
17 | |
18 | def label |
19 | options[:label] || key.humanize.gsub(/url/i, 'URL') |
20 | end |
21 | |
22 | def label_html(sidebar) |
23 | content_tag('label', label) |
24 | end |
25 | |
26 | def input_html(sidebar) |
27 | text_field_tag(input_name(sidebar), sidebar.config[key], options) |
28 | end |
29 | |
30 | def line_html(sidebar) |
31 | label_html(sidebar) + "<br />" + input_html(sidebar) + "<br />" |
32 | end |
33 | |
34 | def input_name(sidebar) |
35 | "configure[#{sidebar.id}][#{key}]" |
36 | end |
37 | |
38 | def canonicalize(value) |
39 | value |
40 | end |
41 | |
42 | class SelectField < self |
43 | def input_html(sidebar) |
44 | select_tag(input_name(sidebar), |
45 | options_for_select(options[:choices], sidebar.config[key]), |
46 | options) |
47 | end |
48 | end |
49 | |
50 | class TextAreaField < self |
51 | def input_html(sidebar) |
52 | html_options = { "rows" => "10", "cols" => "30", "style" => "width:255px"}.update(options.stringify_keys) |
53 | text_area_tag(input_name(sidebar), h(sidebar.config[key]), html_options) |
54 | end |
55 | end |
56 | |
57 | class RadioField < self |
58 | def input_html(sidebar) |
59 | options[:choices].collect do |choice| |
60 | value = value_for(choice) |
61 | radio_button_tag(input_name(sidebar), value, |
62 | value == sidebar.config[key], options) + |
63 | content_tag('label', label_for(choice)) |
64 | end.join("<br />") |
65 | end |
66 | |
67 | def label_for(choice) |
68 | choice.is_a?(Array) ? choice.last : choice.to_s.humanize |
69 | end |
70 | |
71 | def value_for(choice) |
72 | choice.is_a?(Array) ? choice.first : choice |
73 | end |
74 | end |
75 | |
76 | class CheckBoxField < self |
77 | def input_html(sidebar) |
78 | check_box_tag(input_name(sidebar), 1, sidebar.config[key], options)+ |
79 | hidden_field_tag(input_name(sidebar),0) |
80 | end |
81 | |
82 | def line_html(sidebar) |
83 | input_html(sidebar) + ' ' + label_html(sidebar) + '<br >' |
84 | end |
85 | |
86 | def canonicalize(value) |
87 | case value |
88 | when "0" |
89 | false |
90 | else |
91 | true |
92 | end |
93 | end |
94 | end |
95 | |
96 | def self.build(key, default, options) |
97 | field = class_for(options).new(key, default, options) |
98 | end |
99 | |
100 | def self.class_for(options) |
101 | case options[:input_type] |
102 | when :text_area |
103 | TextAreaField |
104 | when :textarea |
105 | TextAreaField |
106 | when :radio |
107 | RadioField |
108 | when :checkbox |
109 | CheckBoxField |
110 | when :select |
111 | SelectField |
112 | else |
113 | if options[:choices] |
114 | SelectField |
115 | else |
116 | self |
117 | end |
118 | end |
119 | end |
120 | end |
121 | |
122 | class << self |
123 | attr_accessor :view_root |
124 | |
125 | def find_all_visible |
126 | find :all, :conditions => 'active_position is not null', :order => 'active_position' |
127 | end |
128 | |
129 | def find_all_staged |
130 | find :all, :conditions => 'staged_position is not null', :order => 'staged_position' |
131 | end |
132 | |
133 | def purge |
134 | delete_all('active_position is null and staged_position is null') |
135 | end |
136 | |
137 | def setting(key, default=nil, options = { }) |
138 | return if instance_methods.include?(key.to_s) |
139 | fields << Field.build(key.to_s, default, options) |
140 | fieldmap.update(key.to_s => fields.last) |
141 | self.send(:define_method, key) do |
142 | self.config[key.to_s] |
143 | end |
144 | self.send(:define_method, "#{key}=") do |newval| |
145 | self.config[key.to_s] = newval |
146 | end |
147 | end |
148 | |
149 | def fieldmap |
150 | @fieldmap ||= {} |
151 | end |
152 | |
153 | def fields |
154 | @fields ||= [] |
155 | end |
156 | |
157 | def fields=(newval) |
158 | @fields = newval |
159 | end |
160 | |
161 | def description(desc = nil) |
162 | if desc |
163 | @description = desc |
164 | else |
165 | @description |
166 | end |
167 | end |
168 | |
169 | def lifetime(timeout = nil) |
170 | if timeout |
171 | @lifetime = timeout |
172 | else |
173 | @lifetime |
174 | end |
175 | end |
176 | |
177 | def short_name |
178 | self.to_s.underscore.split(%r{_}).first |
179 | end |
180 | |
181 | def display_name(new_dn = nil) |
182 | @display_name = new_dn if new_dn |
183 | @display_name || short_name.humanize |
184 | end |
185 | |
186 | def available_sidebars |
187 | Sidebar.subclasses.sort_by { |klass| klass.to_s } |
188 | end |
189 | end |
190 | |
191 | def initialize(*args, &block) |
192 | super(*args, &block) |
193 | self.class.fields.each do |field| |
194 | unless config.has_key?(field.key) |
195 | config[field.key] = field.default |
196 | end |
197 | end |
198 | end |
199 | |
200 | |
201 | def publish |
202 | self.active_position=self.staged_position |
203 | end |
204 | |
205 | def config |
206 | self[:config] ||= { } |
207 | end |
208 | |
209 | def sidebar_controller |
210 | @sidebar_controller ||= SidebarController.available_sidebars.find { |s| s.short_name == self.controller } |
211 | end |
212 | |
213 | def html_id |
214 | short_name + '-' + id.to_s |
215 | end |
216 | |
217 | def parse_request(contents, params) |
218 | end |
219 | |
220 | def fields |
221 | self.class.fields |
222 | end |
223 | |
224 | def fieldmap(field = nil) |
225 | if field |
226 | self.class.fieldmap[field.to_s] |
227 | else |
228 | self.class.fieldmap |
229 | end |
230 | end |
231 | |
232 | def description |
233 | self.class.description |
234 | end |
235 | |
236 | def short_name |
237 | self.class.short_name |
238 | end |
239 | |
240 | def display_name |
241 | self.class.display_name |
242 | end |
243 | |
244 | def content_partial |
245 | "/sidebars/#{short_name}/content" |
246 | end |
247 | |
248 | def to_locals_hash |
249 | fields.inject({ :sidebar => self }) do |hash, field| |
250 | hash.merge(field.key => config[field.key]) |
251 | end |
252 | end |
253 | |
254 | def lifetime |
255 | self.class.lifetime |
256 | end |
257 | |
258 | def view_root |
259 | self.class.view_root |
260 | end |
261 | end |
262 |