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:
- 5527 Bytes
1 | require File.dirname(__FILE__) + '/helpers/action_view_mods' |
2 | |
3 | module Haml |
4 | # This module contains various helpful methods to make it easier to do |
5 | # various tasks. Haml::Helpers is automatically included in the context |
6 | # that a Haml template is parsed in, so all these methods are at your |
7 | # disposal from within the template. |
8 | module Helpers |
9 | self.extend self |
10 | |
11 | @@action_view = false |
12 | @@force_no_action_view = false |
13 | |
14 | # Returns whether or not ActionView is installed on the system. |
15 | def self.action_view? |
16 | @@action_view |
17 | end |
18 | |
19 | # Takes any string, finds all the endlines and converts them to |
20 | # HTML entities for endlines so they'll render correctly in |
21 | # whitespace-sensitive tags without screwing up the indentation. |
22 | def flatten(input) |
23 | input.gsub(/\n/, '
').gsub(/\r/, '') |
24 | end |
25 | |
26 | # Takes an Enumerable object and a block |
27 | # and iterates over the object, |
28 | # yielding each element to a Haml block |
29 | # and putting the result into <tt><li></tt> elements. |
30 | # This creates a list of the results of the block. |
31 | # For example: |
32 | # |
33 | # = list_of([['hello'], ['yall']]) do |i| |
34 | # = i[0] |
35 | # |
36 | # Produces: |
37 | # |
38 | # <li>hello</li> |
39 | # <li>yall</li> |
40 | # |
41 | # And |
42 | # |
43 | # = list_of({:title => 'All the stuff', :description => 'A book about all the stuff.'}) do |key, val| |
44 | # %h3= key.humanize |
45 | # %p= val |
46 | # |
47 | # Produces: |
48 | # |
49 | # <li> |
50 | # <h3>Title</h3> |
51 | # <p>All the stuff</p> |
52 | # </li> |
53 | # <li> |
54 | # <h3>Description</h3> |
55 | # <p>A book about all the stuff.</p> |
56 | # </li> |
57 | # |
58 | def list_of(array, &block) # :yields: item |
59 | to_return = array.collect do |i| |
60 | result = capture_haml(i, &block) |
61 | |
62 | if result.count("\n") > 1 |
63 | result.gsub!("\n", "\n ") |
64 | result = "\n #{result.strip}\n" |
65 | else |
66 | result.strip! |
67 | end |
68 | |
69 | "<li>#{result}</li>" |
70 | end |
71 | to_return.join("\n") |
72 | end |
73 | |
74 | # Increments the number of tabs the buffer automatically adds |
75 | # to the lines of the template. |
76 | # For example: |
77 | # |
78 | # %h1 foo |
79 | # - tab_up |
80 | # %p bar |
81 | # - tab_down |
82 | # %strong baz |
83 | # |
84 | # Produces: |
85 | # |
86 | # <h1>foo</h1> |
87 | # <p>bar</p> |
88 | # <strong>baz</strong> |
89 | # |
90 | def tab_up(i = 1) |
91 | buffer.tabulation += i |
92 | end |
93 | |
94 | # Increments the number of tabs the buffer automatically adds |
95 | # to the lines of the template. |
96 | # |
97 | # See tab_up. |
98 | def tab_down(i = 1) |
99 | buffer.tabulation -= i |
100 | end |
101 | |
102 | # Surrounds the given block of Haml code with the given characters, |
103 | # with no whitespace in between. |
104 | # For example: |
105 | # |
106 | # = surround '(', ')' do |
107 | # %a{:href => "food"} chicken |
108 | # |
109 | # Produces: |
110 | # |
111 | # (<a href='food'>chicken</a>) |
112 | # |
113 | # and |
114 | # |
115 | # = surround '*' do |
116 | # %strong angry |
117 | # |
118 | # Produces: |
119 | # |
120 | # *<strong>angry</strong>* |
121 | # |
122 | def surround(front, back = nil, &block) |
123 | back ||= front |
124 | output = capture_haml(&block) |
125 | |
126 | "#{front}#{output.chomp}#{back}\n" |
127 | end |
128 | |
129 | # Prepends the given character to the beginning of the Haml block, |
130 | # with no whitespace between. |
131 | # For example: |
132 | # |
133 | # = precede '*' do |
134 | # %span.small Not really |
135 | # |
136 | # Produces: |
137 | # |
138 | # *<span class='small'>Not really</span> |
139 | # |
140 | def precede(char, &block) |
141 | "#{char}#{capture_haml(&block).chomp}\n" |
142 | end |
143 | |
144 | # Appends the given character to the end of the Haml block, |
145 | # with no whitespace between. |
146 | # For example: |
147 | # |
148 | # click |
149 | # = succeed '.' do |
150 | # %a{:href=>"thing"} here |
151 | # |
152 | # Produces: |
153 | # |
154 | # click |
155 | # <a href='thing'>here</a>. |
156 | # |
157 | def succeed(char, &block) |
158 | "#{capture_haml(&block).chomp}#{char}\n" |
159 | end |
160 | |
161 | # Captures the result of the given block of Haml code, |
162 | # gets rid of the excess indentation, |
163 | # and returns it as a string. |
164 | # For example, after the following, |
165 | # |
166 | # .foo |
167 | # - foo = capture_haml(13) do |a| |
168 | # %p= a |
169 | # |
170 | # the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n". |
171 | # |
172 | def capture_haml(*args, &block) |
173 | capture_haml_with_buffer(buffer.buffer, *args, &block) |
174 | end |
175 | |
176 | private |
177 | |
178 | # Sets whether or not ActionView is installed on the system. |
179 | def self.action_view(value) # :nodoc: |
180 | @@action_view = value |
181 | end |
182 | |
183 | # Gets a reference to the current Haml::Buffer object. |
184 | def buffer |
185 | @haml_stack[-1] |
186 | end |
187 | |
188 | # Gives a proc the same local "_hamlout" and "_erbout" variables |
189 | # that the current template has. |
190 | def bind_proc(&proc) |
191 | _hamlout = buffer |
192 | _erbout = _hamlout.buffer |
193 | proc { |*args| proc.call(*args) } |
194 | end |
195 | |
196 | # Performs the function of capture_haml, assuming <tt>local_buffer</tt> |
197 | # is where the output of block goes. |
198 | def capture_haml_with_buffer(local_buffer, *args, &block) |
199 | position = local_buffer.length |
200 | |
201 | block.call(*args) |
202 | |
203 | captured = local_buffer.slice!(position..-1) |
204 | |
205 | min_tabs = nil |
206 | captured.each do |line| |
207 | tabs = line.index(/[^ ]/) |
208 | min_tabs ||= tabs |
209 | min_tabs = min_tabs > tabs ? tabs : min_tabs |
210 | end |
211 | |
212 | result = captured.map do |line| |
213 | line[min_tabs..-1] |
214 | end |
215 | result.to_s |
216 | end |
217 | |
218 | include ActionViewMods if self.const_defined? "ActionViewMods" |
219 | end |
220 | end |