radiant 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of radiant might be problematic. Click here for more details.
- data/CHANGELOG +15 -0
- data/CONTRIBUTORS +8 -0
- data/app/controllers/admin/page_controller.rb +1 -11
- data/app/controllers/admin/welcome_controller.rb +5 -6
- data/app/controllers/application.rb +2 -0
- data/app/controllers/site_controller.rb +1 -0
- data/app/helpers/admin/page_helper.rb +36 -0
- data/app/helpers/admin/regions_helper.rb +28 -0
- data/app/helpers/admin/user_helper.rb +6 -0
- data/app/helpers/application_helper.rb +2 -1
- data/app/models/user.rb +7 -8
- data/app/views/admin/extension/index.html.haml +28 -0
- data/app/views/admin/layout/edit.html.haml +44 -0
- data/app/views/admin/layout/index.html.haml +25 -0
- data/app/views/admin/layout/remove.html.haml +16 -0
- data/app/views/admin/page/_meta_row.html.haml +6 -0
- data/app/views/admin/page/_node.html.haml +25 -0
- data/app/views/admin/page/_part.html.haml +17 -0
- data/app/views/admin/page/_tag_reference.html.haml +3 -0
- data/app/views/admin/page/children.html.haml +2 -0
- data/app/views/admin/page/edit.html.haml +114 -0
- data/app/views/admin/page/index.html.haml +28 -0
- data/app/views/admin/page/remove.html.haml +20 -0
- data/app/views/admin/snippet/edit.html.haml +36 -0
- data/app/views/admin/snippet/index.html.haml +20 -0
- data/app/views/admin/snippet/remove.html.haml +19 -0
- data/app/views/admin/user/edit.html.haml +80 -0
- data/app/views/admin/user/index.html.haml +23 -0
- data/app/views/admin/user/preferences.html.haml +28 -0
- data/app/views/admin/user/remove.html.haml +18 -0
- data/app/views/admin/welcome/login.html.haml +44 -0
- data/app/views/layouts/application.html.haml +54 -0
- data/app/views/site/not_found.html.haml +3 -0
- data/db/migrate/019_add_salt_to_users.rb +11 -0
- data/db/schema.rb +2 -1
- data/lib/login_system.rb +1 -0
- data/lib/radiant.rb +1 -1
- data/lib/radiant/admin_ui.rb +65 -0
- data/lib/radiant/admin_ui/region_partials.rb +18 -0
- data/lib/radiant/admin_ui/region_set.rb +35 -0
- data/lib/tasks/extensions.rake +33 -0
- data/public/javascripts/admin/admin.js +8 -2
- data/public/javascripts/admin/sitemap.js +2 -1
- data/public/stylesheets/admin/main.css +4 -0
- data/spec/controllers/admin/abstract_model_controller_spec.rb +2 -0
- data/spec/controllers/admin/page_controller_spec.rb +3 -28
- data/spec/controllers/admin/user_controller_spec.rb +1 -1
- data/spec/controllers/admin/welcome_controller_spec.rb +26 -0
- data/spec/helpers/admin/page_helper_spec.rb +4 -0
- data/spec/helpers/admin/regions_helper_spec.rb +47 -0
- data/spec/helpers/admin/user_helper_spec.rb +7 -0
- data/spec/helpers/application_helper_spec.rb +7 -3
- data/spec/lib/login_system_spec.rb +5 -0
- data/spec/lib/radiant/admin_ui/region_partials_spec.rb +35 -0
- data/spec/lib/radiant/admin_ui/region_set_spec.rb +61 -0
- data/spec/lib/radiant/admin_ui_spec.rb +74 -18
- data/spec/models/user_spec.rb +11 -4
- data/spec/scenarios/users_scenario.rb +2 -2
- data/vendor/plugins/haml/MIT-LICENSE +20 -0
- data/vendor/plugins/haml/README.rdoc +319 -0
- data/vendor/plugins/haml/Rakefile +158 -0
- data/vendor/plugins/haml/TODO +9 -0
- data/vendor/plugins/haml/VERSION +1 -0
- data/vendor/plugins/haml/bin/css2sass +7 -0
- data/vendor/plugins/haml/bin/haml +8 -0
- data/vendor/plugins/haml/bin/html2haml +7 -0
- data/vendor/plugins/haml/bin/sass +8 -0
- data/vendor/plugins/haml/extra/haml-mode.el +328 -0
- data/vendor/plugins/haml/extra/sass-mode.el +88 -0
- data/vendor/plugins/haml/init.rb +2 -0
- data/vendor/plugins/haml/lib/haml.rb +977 -0
- data/vendor/plugins/haml/lib/haml/buffer.rb +229 -0
- data/vendor/plugins/haml/lib/haml/engine.rb +274 -0
- data/vendor/plugins/haml/lib/haml/error.rb +23 -0
- data/vendor/plugins/haml/lib/haml/exec.rb +347 -0
- data/vendor/plugins/haml/lib/haml/filters.rb +249 -0
- data/vendor/plugins/haml/lib/haml/helpers.rb +413 -0
- data/vendor/plugins/haml/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/vendor/plugins/haml/lib/haml/helpers/action_view_mods.rb +122 -0
- data/vendor/plugins/haml/lib/haml/html.rb +188 -0
- data/vendor/plugins/haml/lib/haml/precompiler.rb +757 -0
- data/vendor/plugins/haml/lib/haml/template.rb +43 -0
- data/vendor/plugins/haml/lib/haml/template/patch.rb +58 -0
- data/vendor/plugins/haml/lib/haml/template/plugin.rb +72 -0
- data/vendor/plugins/haml/lib/sass.rb +833 -0
- data/vendor/plugins/haml/lib/sass/constant.rb +245 -0
- data/vendor/plugins/haml/lib/sass/constant/color.rb +101 -0
- data/vendor/plugins/haml/lib/sass/constant/literal.rb +53 -0
- data/vendor/plugins/haml/lib/sass/constant/number.rb +87 -0
- data/vendor/plugins/haml/lib/sass/constant/operation.rb +30 -0
- data/vendor/plugins/haml/lib/sass/constant/string.rb +22 -0
- data/vendor/plugins/haml/lib/sass/css.rb +378 -0
- data/vendor/plugins/haml/lib/sass/engine.rb +459 -0
- data/vendor/plugins/haml/lib/sass/error.rb +35 -0
- data/vendor/plugins/haml/lib/sass/plugin.rb +165 -0
- data/vendor/plugins/haml/lib/sass/plugin/merb.rb +56 -0
- data/vendor/plugins/haml/lib/sass/plugin/rails.rb +24 -0
- data/vendor/plugins/haml/lib/sass/tree/attr_node.rb +53 -0
- data/vendor/plugins/haml/lib/sass/tree/comment_node.rb +20 -0
- data/vendor/plugins/haml/lib/sass/tree/directive_node.rb +46 -0
- data/vendor/plugins/haml/lib/sass/tree/node.rb +42 -0
- data/vendor/plugins/haml/lib/sass/tree/rule_node.rb +89 -0
- data/vendor/plugins/haml/lib/sass/tree/value_node.rb +16 -0
- data/vendor/plugins/haml/test/benchmark.rb +82 -0
- data/vendor/plugins/haml/test/haml/engine_test.rb +587 -0
- data/vendor/plugins/haml/test/haml/helper_test.rb +187 -0
- data/vendor/plugins/haml/test/haml/html2haml_test.rb +60 -0
- data/vendor/plugins/haml/test/haml/markaby/standard.mab +52 -0
- data/vendor/plugins/haml/test/haml/mocks/article.rb +6 -0
- data/vendor/plugins/haml/test/haml/results/content_for_layout.xhtml +16 -0
- data/vendor/plugins/haml/test/haml/results/eval_suppressed.xhtml +11 -0
- data/vendor/plugins/haml/test/haml/results/filters.xhtml +82 -0
- data/vendor/plugins/haml/test/haml/results/helpers.xhtml +94 -0
- data/vendor/plugins/haml/test/haml/results/helpful.xhtml +10 -0
- data/vendor/plugins/haml/test/haml/results/just_stuff.xhtml +64 -0
- data/vendor/plugins/haml/test/haml/results/list.xhtml +12 -0
- data/vendor/plugins/haml/test/haml/results/original_engine.xhtml +22 -0
- data/vendor/plugins/haml/test/haml/results/partials.xhtml +21 -0
- data/vendor/plugins/haml/test/haml/results/silent_script.xhtml +74 -0
- data/vendor/plugins/haml/test/haml/results/standard.xhtml +42 -0
- data/vendor/plugins/haml/test/haml/results/tag_parsing.xhtml +28 -0
- data/vendor/plugins/haml/test/haml/results/very_basic.xhtml +7 -0
- data/vendor/plugins/haml/test/haml/results/whitespace_handling.xhtml +94 -0
- data/vendor/plugins/haml/test/haml/rhtml/_av_partial_1.rhtml +12 -0
- data/vendor/plugins/haml/test/haml/rhtml/_av_partial_2.rhtml +8 -0
- data/vendor/plugins/haml/test/haml/rhtml/action_view.rhtml +62 -0
- data/vendor/plugins/haml/test/haml/rhtml/standard.rhtml +54 -0
- data/vendor/plugins/haml/test/haml/template_test.rb +168 -0
- data/vendor/plugins/haml/test/haml/templates/_av_partial_1.haml +9 -0
- data/vendor/plugins/haml/test/haml/templates/_av_partial_2.haml +5 -0
- data/vendor/plugins/haml/test/haml/templates/_partial.haml +8 -0
- data/vendor/plugins/haml/test/haml/templates/_text_area.haml +3 -0
- data/vendor/plugins/haml/test/haml/templates/action_view.haml +47 -0
- data/vendor/plugins/haml/test/haml/templates/breakage.haml +8 -0
- data/vendor/plugins/haml/test/haml/templates/content_for_layout.haml +10 -0
- data/vendor/plugins/haml/test/haml/templates/eval_suppressed.haml +11 -0
- data/vendor/plugins/haml/test/haml/templates/filters.haml +81 -0
- data/vendor/plugins/haml/test/haml/templates/helpers.haml +69 -0
- data/vendor/plugins/haml/test/haml/templates/helpful.haml +11 -0
- data/vendor/plugins/haml/test/haml/templates/just_stuff.haml +77 -0
- data/vendor/plugins/haml/test/haml/templates/list.haml +12 -0
- data/vendor/plugins/haml/test/haml/templates/original_engine.haml +17 -0
- data/vendor/plugins/haml/test/haml/templates/partialize.haml +1 -0
- data/vendor/plugins/haml/test/haml/templates/partials.haml +12 -0
- data/vendor/plugins/haml/test/haml/templates/silent_script.haml +40 -0
- data/vendor/plugins/haml/test/haml/templates/standard.haml +42 -0
- data/vendor/plugins/haml/test/haml/templates/tag_parsing.haml +24 -0
- data/vendor/plugins/haml/test/haml/templates/very_basic.haml +4 -0
- data/vendor/plugins/haml/test/haml/templates/whitespace_handling.haml +87 -0
- data/vendor/plugins/haml/test/haml/test_helper.rb +15 -0
- data/vendor/plugins/haml/test/profile.rb +65 -0
- data/vendor/plugins/haml/test/sass/engine_test.rb +276 -0
- data/vendor/plugins/haml/test/sass/plugin_test.rb +159 -0
- data/vendor/plugins/haml/test/sass/results/alt.css +4 -0
- data/vendor/plugins/haml/test/sass/results/basic.css +9 -0
- data/vendor/plugins/haml/test/sass/results/compact.css +5 -0
- data/vendor/plugins/haml/test/sass/results/complex.css +87 -0
- data/vendor/plugins/haml/test/sass/results/compressed.css +1 -0
- data/vendor/plugins/haml/test/sass/results/constants.css +14 -0
- data/vendor/plugins/haml/test/sass/results/expanded.css +19 -0
- data/vendor/plugins/haml/test/sass/results/import.css +29 -0
- data/vendor/plugins/haml/test/sass/results/mixins.css +95 -0
- data/vendor/plugins/haml/test/sass/results/multiline.css +24 -0
- data/vendor/plugins/haml/test/sass/results/nested.css +22 -0
- data/vendor/plugins/haml/test/sass/results/parent_ref.css +13 -0
- data/vendor/plugins/haml/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
- data/vendor/plugins/haml/test/sass/results/subdir/subdir.css +1 -0
- data/vendor/plugins/haml/test/sass/templates/_partial.sass +2 -0
- data/vendor/plugins/haml/test/sass/templates/alt.sass +16 -0
- data/vendor/plugins/haml/test/sass/templates/basic.sass +23 -0
- data/vendor/plugins/haml/test/sass/templates/bork.sass +2 -0
- data/vendor/plugins/haml/test/sass/templates/bork2.sass +2 -0
- data/vendor/plugins/haml/test/sass/templates/compact.sass +17 -0
- data/vendor/plugins/haml/test/sass/templates/complex.sass +310 -0
- data/vendor/plugins/haml/test/sass/templates/compressed.sass +15 -0
- data/vendor/plugins/haml/test/sass/templates/constants.sass +97 -0
- data/vendor/plugins/haml/test/sass/templates/expanded.sass +17 -0
- data/vendor/plugins/haml/test/sass/templates/import.sass +11 -0
- data/vendor/plugins/haml/test/sass/templates/importee.sass +14 -0
- data/vendor/plugins/haml/test/sass/templates/mixins.sass +76 -0
- data/vendor/plugins/haml/test/sass/templates/multiline.sass +20 -0
- data/vendor/plugins/haml/test/sass/templates/nested.sass +25 -0
- data/vendor/plugins/haml/test/sass/templates/parent_ref.sass +25 -0
- data/vendor/plugins/haml/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
- data/vendor/plugins/haml/test/sass/templates/subdir/subdir.sass +6 -0
- metadata +185 -24
- data/app/views/admin/extension/index.html.erb +0 -40
- data/app/views/admin/layout/edit.html.erb +0 -39
- data/app/views/admin/layout/index.html.erb +0 -38
- data/app/views/admin/layout/remove.html.erb +0 -17
- data/app/views/admin/page/_meta_row.html.erb +0 -4
- data/app/views/admin/page/_node.html.erb +0 -28
- data/app/views/admin/page/_part.html.erb +0 -13
- data/app/views/admin/page/_tag_reference.html.erb +0 -4
- data/app/views/admin/page/children.html.erb +0 -4
- data/app/views/admin/page/edit.html.erb +0 -140
- data/app/views/admin/page/index.html.erb +0 -31
- data/app/views/admin/page/remove.html.erb +0 -14
- data/app/views/admin/snippet/edit.html.erb +0 -29
- data/app/views/admin/snippet/index.html.erb +0 -36
- data/app/views/admin/snippet/remove.html.erb +0 -16
- data/app/views/admin/user/edit.html.erb +0 -54
- data/app/views/admin/user/index.html.erb +0 -43
- data/app/views/admin/user/preferences.html.erb +0 -29
- data/app/views/admin/user/remove.html.erb +0 -16
- data/app/views/admin/welcome/login.html.erb +0 -51
- data/app/views/layouts/application.html.erb +0 -83
- data/app/views/site/not_found.html.erb +0 -3
@@ -0,0 +1,413 @@
|
|
1
|
+
require 'haml/helpers/action_view_mods'
|
2
|
+
require 'haml/helpers/action_view_extensions'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
# This module contains various helpful methods to make it easier to do
|
6
|
+
# various tasks. Haml::Helpers is automatically included in the context
|
7
|
+
# that a Haml template is parsed in, so all these methods are at your
|
8
|
+
# disposal from within the template.
|
9
|
+
module Helpers
|
10
|
+
self.extend self
|
11
|
+
|
12
|
+
@@action_view_defined = defined?(ActionView)
|
13
|
+
@@force_no_action_view = false
|
14
|
+
|
15
|
+
# Returns whether or not ActionView is installed on the system.
|
16
|
+
def self.action_view?
|
17
|
+
@@action_view_defined
|
18
|
+
end
|
19
|
+
|
20
|
+
# Note: this does *not* need to be called
|
21
|
+
# when using Haml helpers normally
|
22
|
+
# in Rails.
|
23
|
+
#
|
24
|
+
# Initializes the current object
|
25
|
+
# as though it were in the same context
|
26
|
+
# as a normal ActionView rendering
|
27
|
+
# using Haml.
|
28
|
+
# This is useful if you want to use the helpers in a context
|
29
|
+
# other than the normal setup with ActionView.
|
30
|
+
# For example:
|
31
|
+
#
|
32
|
+
# context = Object.new
|
33
|
+
# class << context
|
34
|
+
# include Haml::Helpers
|
35
|
+
# end
|
36
|
+
# context.init_haml_helpers
|
37
|
+
# context.haml_tag :p, "Stuff"
|
38
|
+
#
|
39
|
+
def init_haml_helpers
|
40
|
+
@haml_buffer = Haml::Buffer.new(@haml_buffer, Haml::Engine.new('').send(:options_for_buffer))
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
|
44
|
+
# call-seq:
|
45
|
+
# non_haml { ... }
|
46
|
+
#
|
47
|
+
# Runs a block of code in a non-Haml context
|
48
|
+
# (i.e. #is_haml? will return false).
|
49
|
+
#
|
50
|
+
# This is mainly useful for rendering sub-templates such as partials in a non-Haml language,
|
51
|
+
# particularly where helpers may behave differently when run from Haml.
|
52
|
+
#
|
53
|
+
# Note that this is automatically applied to Rails partials.
|
54
|
+
def non_haml
|
55
|
+
was_active = @haml_buffer.active?
|
56
|
+
@haml_buffer.active = false
|
57
|
+
res = yield
|
58
|
+
@haml_buffer.active = was_active
|
59
|
+
res
|
60
|
+
end
|
61
|
+
|
62
|
+
# call-seq:
|
63
|
+
# find_and_preserve(input)
|
64
|
+
# find_and_preserve {...}
|
65
|
+
#
|
66
|
+
# Isolates the whitespace-sensitive tags in the string and uses preserve
|
67
|
+
# to convert any endlines inside them into HTML entities for endlines.
|
68
|
+
def find_and_preserve(input = '', &block)
|
69
|
+
return find_and_preserve(capture_haml(&block)) if block
|
70
|
+
|
71
|
+
input = input.to_s
|
72
|
+
input.gsub(/<(textarea|code|pre)([^>]*)>(.*?)(<\/\1>)/im) do
|
73
|
+
"<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# call-seq:
|
78
|
+
# preserve(input)
|
79
|
+
# preserve {...}
|
80
|
+
#
|
81
|
+
# Takes any string, finds all the endlines and converts them to
|
82
|
+
# HTML entities for endlines so they'll render correctly in
|
83
|
+
# whitespace-sensitive tags without screwing up the indentation.
|
84
|
+
def preserve(input = '', &block)
|
85
|
+
return preserve(capture_haml(&block)) if block
|
86
|
+
|
87
|
+
input.gsub(/\n/, '
').gsub(/\r/, '')
|
88
|
+
end
|
89
|
+
|
90
|
+
alias_method :flatten, :preserve
|
91
|
+
|
92
|
+
# Takes an Enumerable object and a block
|
93
|
+
# and iterates over the object,
|
94
|
+
# yielding each element to a Haml block
|
95
|
+
# and putting the result into <tt><li></tt> elements.
|
96
|
+
# This creates a list of the results of the block.
|
97
|
+
# For example:
|
98
|
+
#
|
99
|
+
# = list_of([['hello'], ['yall']]) do |i|
|
100
|
+
# = i[0]
|
101
|
+
#
|
102
|
+
# Produces:
|
103
|
+
#
|
104
|
+
# <li>hello</li>
|
105
|
+
# <li>yall</li>
|
106
|
+
#
|
107
|
+
# And
|
108
|
+
#
|
109
|
+
# = list_of({:title => 'All the stuff', :description => 'A book about all the stuff.'}) do |key, val|
|
110
|
+
# %h3= key.humanize
|
111
|
+
# %p= val
|
112
|
+
#
|
113
|
+
# Produces:
|
114
|
+
#
|
115
|
+
# <li>
|
116
|
+
# <h3>Title</h3>
|
117
|
+
# <p>All the stuff</p>
|
118
|
+
# </li>
|
119
|
+
# <li>
|
120
|
+
# <h3>Description</h3>
|
121
|
+
# <p>A book about all the stuff.</p>
|
122
|
+
# </li>
|
123
|
+
#
|
124
|
+
def list_of(array, &block) # :yields: item
|
125
|
+
to_return = array.collect do |i|
|
126
|
+
result = capture_haml(i, &block)
|
127
|
+
|
128
|
+
if result.count("\n") > 1
|
129
|
+
result.gsub!("\n", "\n ")
|
130
|
+
result = "\n #{result.strip}\n"
|
131
|
+
else
|
132
|
+
result.strip!
|
133
|
+
end
|
134
|
+
|
135
|
+
"<li>#{result}</li>"
|
136
|
+
end
|
137
|
+
to_return.join("\n")
|
138
|
+
end
|
139
|
+
|
140
|
+
# Returns a hash containing default assignments for the xmlns and xml:lang
|
141
|
+
# attributes of the <tt>html</tt> HTML element.
|
142
|
+
# It also takes an optional argument for the value of xml:lang and lang,
|
143
|
+
# which defaults to 'en-US'.
|
144
|
+
# For example,
|
145
|
+
#
|
146
|
+
# %html{html_attrs}
|
147
|
+
#
|
148
|
+
# becomes
|
149
|
+
#
|
150
|
+
# <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US' lang='en-US'>
|
151
|
+
#
|
152
|
+
def html_attrs(lang = 'en-US')
|
153
|
+
{:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
|
154
|
+
end
|
155
|
+
|
156
|
+
# Increments the number of tabs the buffer automatically adds
|
157
|
+
# to the lines of the template.
|
158
|
+
# For example:
|
159
|
+
#
|
160
|
+
# %h1 foo
|
161
|
+
# - tab_up
|
162
|
+
# %p bar
|
163
|
+
# - tab_down
|
164
|
+
# %strong baz
|
165
|
+
#
|
166
|
+
# Produces:
|
167
|
+
#
|
168
|
+
# <h1>foo</h1>
|
169
|
+
# <p>bar</p>
|
170
|
+
# <strong>baz</strong>
|
171
|
+
#
|
172
|
+
def tab_up(i = 1)
|
173
|
+
haml_buffer.tabulation += i
|
174
|
+
end
|
175
|
+
|
176
|
+
# Decrements the number of tabs the buffer automatically adds
|
177
|
+
# to the lines of the template.
|
178
|
+
#
|
179
|
+
# See also tab_up.
|
180
|
+
def tab_down(i = 1)
|
181
|
+
haml_buffer.tabulation -= i
|
182
|
+
end
|
183
|
+
|
184
|
+
# Surrounds the given block of Haml code with the given characters,
|
185
|
+
# with no whitespace in between.
|
186
|
+
# For example:
|
187
|
+
#
|
188
|
+
# = surround '(', ')' do
|
189
|
+
# %a{:href => "food"} chicken
|
190
|
+
#
|
191
|
+
# Produces:
|
192
|
+
#
|
193
|
+
# (<a href='food'>chicken</a>)
|
194
|
+
#
|
195
|
+
# and
|
196
|
+
#
|
197
|
+
# = surround '*' do
|
198
|
+
# %strong angry
|
199
|
+
#
|
200
|
+
# Produces:
|
201
|
+
#
|
202
|
+
# *<strong>angry</strong>*
|
203
|
+
#
|
204
|
+
def surround(front, back = nil, &block)
|
205
|
+
back ||= front
|
206
|
+
output = capture_haml(&block)
|
207
|
+
|
208
|
+
"#{front}#{output.chomp}#{back}\n"
|
209
|
+
end
|
210
|
+
|
211
|
+
# Prepends the given character to the beginning of the Haml block,
|
212
|
+
# with no whitespace between.
|
213
|
+
# For example:
|
214
|
+
#
|
215
|
+
# = precede '*' do
|
216
|
+
# %span.small Not really
|
217
|
+
#
|
218
|
+
# Produces:
|
219
|
+
#
|
220
|
+
# *<span class='small'>Not really</span>
|
221
|
+
#
|
222
|
+
def precede(char, &block)
|
223
|
+
"#{char}#{capture_haml(&block).chomp}\n"
|
224
|
+
end
|
225
|
+
|
226
|
+
# Appends the given character to the end of the Haml block,
|
227
|
+
# with no whitespace between.
|
228
|
+
# For example:
|
229
|
+
#
|
230
|
+
# click
|
231
|
+
# = succeed '.' do
|
232
|
+
# %a{:href=>"thing"} here
|
233
|
+
#
|
234
|
+
# Produces:
|
235
|
+
#
|
236
|
+
# click
|
237
|
+
# <a href='thing'>here</a>.
|
238
|
+
#
|
239
|
+
def succeed(char, &block)
|
240
|
+
"#{capture_haml(&block).chomp}#{char}\n"
|
241
|
+
end
|
242
|
+
|
243
|
+
# Captures the result of the given block of Haml code,
|
244
|
+
# gets rid of the excess indentation,
|
245
|
+
# and returns it as a string.
|
246
|
+
# For example, after the following,
|
247
|
+
#
|
248
|
+
# .foo
|
249
|
+
# - foo = capture_haml(13) do |a|
|
250
|
+
# %p= a
|
251
|
+
#
|
252
|
+
# the local variable <tt>foo</tt> would be assigned to "<p>13</p>\n".
|
253
|
+
#
|
254
|
+
def capture_haml(*args, &block)
|
255
|
+
capture_haml_with_buffer(haml_buffer.buffer, *args, &block)
|
256
|
+
end
|
257
|
+
|
258
|
+
# Outputs text directly to the Haml buffer, with the proper tabulation
|
259
|
+
def puts(text = "")
|
260
|
+
haml_buffer.buffer << (' ' * haml_buffer.tabulation) << text.to_s << "\n"
|
261
|
+
nil
|
262
|
+
end
|
263
|
+
|
264
|
+
#
|
265
|
+
# call-seq:
|
266
|
+
# haml_tag(name, attributes = {}) {...}
|
267
|
+
# haml_tag(name, text, attributes = {}) {...}
|
268
|
+
#
|
269
|
+
# Creates an HTML tag with the given name and optionally text and attributes.
|
270
|
+
# Can take a block that will be executed
|
271
|
+
# between when the opening and closing tags are output.
|
272
|
+
# If the block is a Haml block or outputs text using puts,
|
273
|
+
# the text will be properly indented.
|
274
|
+
#
|
275
|
+
# For example,
|
276
|
+
#
|
277
|
+
# haml_tag :table do
|
278
|
+
# haml_tag :tr do
|
279
|
+
# haml_tag :td, {:class => 'cell'} do
|
280
|
+
# haml_tag :strong, "strong!"
|
281
|
+
# puts "data"
|
282
|
+
# end
|
283
|
+
# haml_tag :td do
|
284
|
+
# puts "more_data"
|
285
|
+
# end
|
286
|
+
# end
|
287
|
+
# end
|
288
|
+
#
|
289
|
+
# outputs
|
290
|
+
#
|
291
|
+
# <table>
|
292
|
+
# <tr>
|
293
|
+
# <td class='cell'>
|
294
|
+
# <strong>
|
295
|
+
# strong!
|
296
|
+
# </strong>
|
297
|
+
# data
|
298
|
+
# </td>
|
299
|
+
# <td>
|
300
|
+
# more_data
|
301
|
+
# </td>
|
302
|
+
# </tr>
|
303
|
+
# </table>
|
304
|
+
#
|
305
|
+
def haml_tag(name, attributes = {}, alt_atts = {}, &block)
|
306
|
+
name = name.to_s
|
307
|
+
|
308
|
+
text = nil
|
309
|
+
if attributes.is_a? String
|
310
|
+
text = attributes
|
311
|
+
attributes = alt_atts
|
312
|
+
end
|
313
|
+
|
314
|
+
attributes = Haml::Precompiler.build_attributes(
|
315
|
+
haml_buffer.html?, haml_buffer.options[:attr_wrapper], attributes)
|
316
|
+
|
317
|
+
if text.nil? && block.nil? && haml_buffer.options[:autoclose].include?(name)
|
318
|
+
puts "<#{name}#{attributes} />"
|
319
|
+
return nil
|
320
|
+
end
|
321
|
+
|
322
|
+
puts "<#{name}#{attributes}>"
|
323
|
+
unless text && text.empty?
|
324
|
+
tab_up
|
325
|
+
# Print out either the text (using push_text) or call the block and add an endline
|
326
|
+
if text
|
327
|
+
puts(text)
|
328
|
+
elsif block
|
329
|
+
block.call
|
330
|
+
end
|
331
|
+
tab_down
|
332
|
+
end
|
333
|
+
puts "</#{name}>"
|
334
|
+
nil
|
335
|
+
end
|
336
|
+
|
337
|
+
# Characters that need to be escaped to HTML entities from user input
|
338
|
+
HTML_ESCAPE = { '&'=>'&', '<'=>'<', '>'=>'>', '"'=>'"', "'"=>''', }
|
339
|
+
|
340
|
+
# Returns a copy of <tt>text</tt> with ampersands, angle brackets and quotes
|
341
|
+
# escaped into HTML entities.
|
342
|
+
def html_escape(text)
|
343
|
+
text.to_s.gsub(/[\"><&]/) { |s| HTML_ESCAPE[s] }
|
344
|
+
end
|
345
|
+
|
346
|
+
# Escapes HTML entities in <tt>text</tt>, but without escaping an ampersand
|
347
|
+
# that is already part of an escaped entity.
|
348
|
+
def escape_once(text)
|
349
|
+
text.to_s.gsub(/[\"><]|&(?!([a-zA-Z]+|(#\d+));)/) { |s| HTML_ESCAPE[s] }
|
350
|
+
end
|
351
|
+
|
352
|
+
# Returns whether or not the current template is a Haml template.
|
353
|
+
#
|
354
|
+
# This function, unlike other Haml::Helpers functions,
|
355
|
+
# also works in other ActionView templates,
|
356
|
+
# where it will always return false.
|
357
|
+
def is_haml?
|
358
|
+
!@haml_buffer.nil? && @haml_buffer.active?
|
359
|
+
end
|
360
|
+
|
361
|
+
private
|
362
|
+
|
363
|
+
# Gets a reference to the current Haml::Buffer object.
|
364
|
+
def haml_buffer
|
365
|
+
@haml_buffer
|
366
|
+
end
|
367
|
+
|
368
|
+
# Gives a proc the same local "_hamlout" and "_erbout" variables
|
369
|
+
# that the current template has.
|
370
|
+
def haml_bind_proc(&proc)
|
371
|
+
_hamlout = haml_buffer
|
372
|
+
_erbout = _hamlout.buffer
|
373
|
+
proc { |*args| proc.call(*args) }
|
374
|
+
end
|
375
|
+
|
376
|
+
# Performs the function of capture_haml, assuming <tt>local_buffer</tt>
|
377
|
+
# is where the output of block goes.
|
378
|
+
def capture_haml_with_buffer(local_buffer, *args, &block)
|
379
|
+
position = local_buffer.length
|
380
|
+
|
381
|
+
block.call *args
|
382
|
+
|
383
|
+
captured = local_buffer.slice!(position..-1)
|
384
|
+
|
385
|
+
min_tabs = nil
|
386
|
+
captured.each do |line|
|
387
|
+
tabs = line.index(/[^ ]/)
|
388
|
+
min_tabs ||= tabs
|
389
|
+
min_tabs = min_tabs > tabs ? tabs : min_tabs
|
390
|
+
end
|
391
|
+
|
392
|
+
result = captured.map do |line|
|
393
|
+
line[min_tabs..-1]
|
394
|
+
end
|
395
|
+
result.to_s
|
396
|
+
end
|
397
|
+
|
398
|
+
include ActionViewExtensions if self.const_defined? "ActionViewExtensions"
|
399
|
+
end
|
400
|
+
end
|
401
|
+
|
402
|
+
class Object
|
403
|
+
# Haml overrides various ActionView helpers,
|
404
|
+
# which call an #is_haml? method
|
405
|
+
# to determine whether or not the current context object
|
406
|
+
# is a proper Haml context.
|
407
|
+
# Because ActionView helpers may be included in non-ActionView::Base classes,
|
408
|
+
# it's a good idea to define is_haml? for all objects.
|
409
|
+
def is_haml?
|
410
|
+
false
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'haml/helpers/action_view_mods'
|
2
|
+
|
3
|
+
if defined?(ActionView)
|
4
|
+
module Haml
|
5
|
+
module Helpers
|
6
|
+
# This module contains various useful helper methods
|
7
|
+
# that either tie into ActionView or the rest of the ActionPack stack,
|
8
|
+
# or are only useful in that context.
|
9
|
+
# Thus, the methods defined here are only available
|
10
|
+
# if ActionView is installed.
|
11
|
+
module ActionViewExtensions
|
12
|
+
# Returns a value for the "class" attribute
|
13
|
+
# unique to this controller/action pair.
|
14
|
+
# This can be used to target styles specifically at this action or controller.
|
15
|
+
# For example, if the current action were EntryController#show,
|
16
|
+
#
|
17
|
+
# %div{:class => page_class} My Div
|
18
|
+
#
|
19
|
+
# would become
|
20
|
+
#
|
21
|
+
# <div class="entry show">My Div</div>
|
22
|
+
#
|
23
|
+
# Then, in a stylesheet
|
24
|
+
# (shown here as Sass),
|
25
|
+
# you could refer to this specific action:
|
26
|
+
#
|
27
|
+
# .entry.show
|
28
|
+
# :font-weight bold
|
29
|
+
#
|
30
|
+
# or to all actions in the entry controller:
|
31
|
+
#
|
32
|
+
# .entry
|
33
|
+
# :color #00f
|
34
|
+
#
|
35
|
+
def page_class
|
36
|
+
controller.controller_name + " " + controller.action_name
|
37
|
+
end
|
38
|
+
|
39
|
+
# :stopdoc:
|
40
|
+
alias_method :generate_content_class_names, :page_class
|
41
|
+
# :startdoc:
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|