mack-haml 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gems.rb +13 -0
- data/lib/gems/haml-2.0.4/VERSION +1 -0
- data/lib/gems/haml-2.0.4/bin/css2sass +7 -0
- data/lib/gems/haml-2.0.4/bin/haml +9 -0
- data/lib/gems/haml-2.0.4/bin/html2haml +7 -0
- data/lib/gems/haml-2.0.4/bin/sass +8 -0
- data/lib/gems/haml-2.0.4/lib/haml.rb +1040 -0
- data/lib/gems/haml-2.0.4/lib/haml/buffer.rb +239 -0
- data/lib/gems/haml-2.0.4/lib/haml/engine.rb +265 -0
- data/lib/gems/haml-2.0.4/lib/haml/error.rb +22 -0
- data/lib/gems/haml-2.0.4/lib/haml/exec.rb +364 -0
- data/lib/gems/haml-2.0.4/lib/haml/filters.rb +275 -0
- data/lib/gems/haml-2.0.4/lib/haml/helpers.rb +453 -0
- data/lib/gems/haml-2.0.4/lib/haml/helpers/action_view_extensions.rb +45 -0
- data/lib/gems/haml-2.0.4/lib/haml/helpers/action_view_mods.rb +179 -0
- data/lib/gems/haml-2.0.4/lib/haml/html.rb +227 -0
- data/lib/gems/haml-2.0.4/lib/haml/precompiler.rb +805 -0
- data/lib/gems/haml-2.0.4/lib/haml/template.rb +51 -0
- data/lib/gems/haml-2.0.4/lib/haml/template/patch.rb +58 -0
- data/lib/gems/haml-2.0.4/lib/haml/template/plugin.rb +72 -0
- data/lib/gems/haml-2.0.4/lib/sass.rb +863 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant.rb +214 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant/color.rb +101 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant/literal.rb +54 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant/nil.rb +9 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant/number.rb +87 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant/operation.rb +30 -0
- data/lib/gems/haml-2.0.4/lib/sass/constant/string.rb +22 -0
- data/lib/gems/haml-2.0.4/lib/sass/css.rb +394 -0
- data/lib/gems/haml-2.0.4/lib/sass/engine.rb +466 -0
- data/lib/gems/haml-2.0.4/lib/sass/error.rb +35 -0
- data/lib/gems/haml-2.0.4/lib/sass/plugin.rb +169 -0
- data/lib/gems/haml-2.0.4/lib/sass/plugin/merb.rb +56 -0
- data/lib/gems/haml-2.0.4/lib/sass/plugin/rails.rb +24 -0
- data/lib/gems/haml-2.0.4/lib/sass/tree/attr_node.rb +53 -0
- data/lib/gems/haml-2.0.4/lib/sass/tree/comment_node.rb +20 -0
- data/lib/gems/haml-2.0.4/lib/sass/tree/directive_node.rb +46 -0
- data/lib/gems/haml-2.0.4/lib/sass/tree/node.rb +42 -0
- data/lib/gems/haml-2.0.4/lib/sass/tree/rule_node.rb +89 -0
- data/lib/gems/haml-2.0.4/lib/sass/tree/value_node.rb +16 -0
- data/lib/gems/haml-2.0.4/rails/init.rb +1 -0
- data/lib/mack-haml.rb +1 -0
- metadata +65 -16
@@ -0,0 +1,22 @@
|
|
1
|
+
module Haml
|
2
|
+
# An exception raised by Haml code.
|
3
|
+
class Error < StandardError
|
4
|
+
# :stopdoc:
|
5
|
+
|
6
|
+
# By default, an error is taken to refer to the line of the template
|
7
|
+
# that was being processed when the exception was raised.
|
8
|
+
# However, if line is non-nil, it + 1 is used instead.
|
9
|
+
attr_reader :line
|
10
|
+
|
11
|
+
def initialize(message = nil, line = nil)
|
12
|
+
super(message)
|
13
|
+
@line = line
|
14
|
+
end
|
15
|
+
# :startdoc:
|
16
|
+
end
|
17
|
+
|
18
|
+
# SyntaxError is the type of exception raised when Haml encounters an
|
19
|
+
# ill-formatted document.
|
20
|
+
# It's not particularly interesting, except in that it includes Haml::Error.
|
21
|
+
class SyntaxError < Haml::Error; end
|
22
|
+
end
|
@@ -0,0 +1,364 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module Haml
|
5
|
+
# This module contains code for working with the
|
6
|
+
# haml, sass, and haml2html executables,
|
7
|
+
# such as command-line parsing stuff.
|
8
|
+
# It shouldn't need to be invoked by client code.
|
9
|
+
module Exec # :nodoc:
|
10
|
+
# A class that encapsulates the executable code
|
11
|
+
# for all three executables.
|
12
|
+
class Generic # :nodoc:
|
13
|
+
def initialize(args)
|
14
|
+
@args = args
|
15
|
+
@options = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse!
|
19
|
+
begin
|
20
|
+
@opts = OptionParser.new(&method(:set_opts))
|
21
|
+
@opts.parse!(@args)
|
22
|
+
|
23
|
+
process_result
|
24
|
+
|
25
|
+
@options
|
26
|
+
rescue Exception => e
|
27
|
+
raise e if @options[:trace] || e.is_a?(SystemExit)
|
28
|
+
|
29
|
+
$stderr.puts e.message
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
@opts.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def get_line(exception)
|
42
|
+
# SyntaxErrors have weird line reporting
|
43
|
+
# when there's trailing whitespace,
|
44
|
+
# which there is for Haml documents.
|
45
|
+
return exception.message.scan(/:(\d+)/)[0] if exception.is_a?(::SyntaxError)
|
46
|
+
exception.backtrace[0].scan(/:(\d+)/)[0]
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def set_opts(opts)
|
52
|
+
opts.on('-s', '--stdin', :NONE, 'Read input from standard input instead of an input file') do
|
53
|
+
@options[:input] = $stdin
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('--trace', :NONE, 'Show a full traceback on error') do
|
57
|
+
@options[:trace] = true
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on_tail("-?", "-h", "--help", "Show this message") do
|
61
|
+
puts opts
|
62
|
+
exit
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on_tail("-v", "--version", "Print version") do
|
66
|
+
puts("Haml #{::Haml.version[:string]}")
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_result
|
72
|
+
input, output = @options[:input], @options[:output]
|
73
|
+
input_file, output_file = if input
|
74
|
+
[nil, open_file(ARGV[0], 'w')]
|
75
|
+
else
|
76
|
+
[open_file(ARGV[0]), open_file(ARGV[1], 'w')]
|
77
|
+
end
|
78
|
+
|
79
|
+
input ||= input_file
|
80
|
+
output ||= output_file
|
81
|
+
input ||= $stdin
|
82
|
+
output ||= $stdout
|
83
|
+
|
84
|
+
@options[:input], @options[:output] = input, output
|
85
|
+
end
|
86
|
+
|
87
|
+
def open_file(filename, flag = 'r')
|
88
|
+
return if filename.nil?
|
89
|
+
File.open(filename, flag)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# A class encapsulating the executable functionality
|
94
|
+
# specific to Haml and Sass.
|
95
|
+
class HamlSass < Generic # :nodoc:
|
96
|
+
def initialize(args)
|
97
|
+
super
|
98
|
+
@options[:for_engine] = {}
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def set_opts(opts)
|
104
|
+
opts.banner = <<END
|
105
|
+
Usage: #{@name.downcase} [options] [INPUT] [OUTPUT]
|
106
|
+
|
107
|
+
Description:
|
108
|
+
Uses the #{@name} engine to parse the specified template
|
109
|
+
and outputs the result to the specified file.
|
110
|
+
|
111
|
+
Options:
|
112
|
+
END
|
113
|
+
|
114
|
+
opts.on('--rails RAILS_DIR', "Install Haml and Sass from the Gem to a Rails project") do |dir|
|
115
|
+
original_dir = dir
|
116
|
+
|
117
|
+
dir = File.join(dir, 'vendor', 'plugins')
|
118
|
+
|
119
|
+
unless File.exists?(dir)
|
120
|
+
puts "Directory #{dir} doesn't exist"
|
121
|
+
exit
|
122
|
+
end
|
123
|
+
|
124
|
+
dir = File.join(dir, 'haml')
|
125
|
+
|
126
|
+
if File.exists?(dir)
|
127
|
+
print "Directory #{dir} already exists, overwrite [y/N]? "
|
128
|
+
exit if gets !~ /y/i
|
129
|
+
FileUtils.rm_rf(dir)
|
130
|
+
end
|
131
|
+
|
132
|
+
begin
|
133
|
+
Dir.mkdir(dir)
|
134
|
+
rescue SystemCallError
|
135
|
+
puts "Cannot create #{dir}"
|
136
|
+
exit
|
137
|
+
end
|
138
|
+
|
139
|
+
File.open(File.join(dir, 'init.rb'), 'w') do |file|
|
140
|
+
file.puts "require 'rubygems'"
|
141
|
+
file << File.read(File.dirname(__FILE__) + "/../../init.rb")
|
142
|
+
end
|
143
|
+
|
144
|
+
puts "Haml plugin added to #{original_dir}"
|
145
|
+
exit
|
146
|
+
end
|
147
|
+
|
148
|
+
opts.on('-c', '--check', "Just check syntax, don't evaluate.") do
|
149
|
+
require 'stringio'
|
150
|
+
@options[:check_syntax] = true
|
151
|
+
@options[:output] = StringIO.new
|
152
|
+
end
|
153
|
+
|
154
|
+
super
|
155
|
+
end
|
156
|
+
|
157
|
+
def process_result
|
158
|
+
super
|
159
|
+
require File.dirname(__FILE__) + "/../#{@name.downcase}"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
# A class encapsulating executable functionality
|
164
|
+
# specific to Sass.
|
165
|
+
class Sass < HamlSass # :nodoc:
|
166
|
+
def initialize(args)
|
167
|
+
super
|
168
|
+
@name = "Sass"
|
169
|
+
end
|
170
|
+
|
171
|
+
def set_opts(opts)
|
172
|
+
super
|
173
|
+
|
174
|
+
opts.on('-t', '--style NAME',
|
175
|
+
'Output style. Can be nested (default), compact, compressed, or expanded.') do |name|
|
176
|
+
@options[:for_engine][:style] = name.to_sym
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def process_result
|
181
|
+
super
|
182
|
+
input = @options[:input]
|
183
|
+
output = @options[:output]
|
184
|
+
|
185
|
+
template = input.read()
|
186
|
+
input.close() if input.is_a? File
|
187
|
+
|
188
|
+
begin
|
189
|
+
# We don't need to do any special handling of @options[:check_syntax] here,
|
190
|
+
# because the Sass syntax checking happens alongside evaluation
|
191
|
+
# and evaluation doesn't actually evaluate any code anyway.
|
192
|
+
result = ::Sass::Engine.new(template, @options[:for_engine]).render
|
193
|
+
rescue ::Sass::SyntaxError => e
|
194
|
+
raise e if @options[:trace]
|
195
|
+
raise "Syntax error on line #{get_line e}: #{e.message}"
|
196
|
+
end
|
197
|
+
|
198
|
+
output.write(result)
|
199
|
+
output.close() if output.is_a? File
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# A class encapsulating executable functionality
|
204
|
+
# specific to Haml.
|
205
|
+
class Haml < HamlSass # :nodoc:
|
206
|
+
def initialize(args)
|
207
|
+
super
|
208
|
+
@name = "Haml"
|
209
|
+
@options[:requires] = []
|
210
|
+
@options[:load_paths] = []
|
211
|
+
end
|
212
|
+
|
213
|
+
def set_opts(opts)
|
214
|
+
super
|
215
|
+
|
216
|
+
opts.on('-t', '--style NAME',
|
217
|
+
'Output style. Can be indented (default) or ugly.') do |name|
|
218
|
+
@options[:for_engine][:ugly] = true if name.to_sym == :ugly
|
219
|
+
end
|
220
|
+
|
221
|
+
opts.on('-f', '--format NAME',
|
222
|
+
'Output format. Can be xhtml (default), html4, or html5.') do |name|
|
223
|
+
@options[:for_engine][:format] = name.to_sym
|
224
|
+
end
|
225
|
+
|
226
|
+
opts.on('-e', '--escape-html',
|
227
|
+
'Escape HTML characters (like ampersands and angle brackets) by default.') do
|
228
|
+
@options[:for_engine][:escape_html] = true
|
229
|
+
end
|
230
|
+
|
231
|
+
opts.on('-r', '--require FILE', "Same as 'ruby -r'.") do |file|
|
232
|
+
@options[:requires] << file
|
233
|
+
end
|
234
|
+
|
235
|
+
opts.on('-I', '--load-path PATH', "Same as 'ruby -I'.") do |path|
|
236
|
+
@options[:load_paths] << path
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def process_result
|
241
|
+
super
|
242
|
+
input = @options[:input]
|
243
|
+
output = @options[:output]
|
244
|
+
|
245
|
+
template = input.read()
|
246
|
+
input.close() if input.is_a? File
|
247
|
+
|
248
|
+
begin
|
249
|
+
engine = ::Haml::Engine.new(template, @options[:for_engine])
|
250
|
+
if @options[:check_syntax]
|
251
|
+
puts "Syntax OK"
|
252
|
+
return
|
253
|
+
end
|
254
|
+
|
255
|
+
@options[:load_paths].each {|p| $LOAD_PATH << p}
|
256
|
+
@options[:requires].each {|f| require f}
|
257
|
+
result = engine.to_html
|
258
|
+
rescue Exception => e
|
259
|
+
raise e if @options[:trace]
|
260
|
+
|
261
|
+
case e
|
262
|
+
when ::Haml::SyntaxError; raise "Syntax error on line #{get_line e}: #{e.message}"
|
263
|
+
when ::Haml::Error; raise "Haml error on line #{get_line e}: #{e.message}"
|
264
|
+
else raise "Exception on line #{get_line e}: #{e.message}\n Use --trace for backtrace."
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
output.write(result)
|
269
|
+
output.close() if output.is_a? File
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
# A class encapsulating executable functionality
|
274
|
+
# specific to the html2haml executable.
|
275
|
+
class HTML2Haml < Generic # :nodoc:
|
276
|
+
def initialize(args)
|
277
|
+
super
|
278
|
+
|
279
|
+
@module_opts = {}
|
280
|
+
|
281
|
+
begin
|
282
|
+
require 'haml/html'
|
283
|
+
rescue LoadError => err
|
284
|
+
dep = err.message.scan(/^no such file to load -- (.*)/)[0]
|
285
|
+
puts "Required dependency #{dep} not found!"
|
286
|
+
exit 1
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def set_opts(opts)
|
291
|
+
opts.banner = <<END
|
292
|
+
Usage: html2haml [options] [INPUT] [OUTPUT]
|
293
|
+
|
294
|
+
Description: Transforms an HTML file into corresponding Haml code.
|
295
|
+
|
296
|
+
Options:
|
297
|
+
END
|
298
|
+
|
299
|
+
opts.on('-r', '--rhtml', 'Parse RHTML tags.') do
|
300
|
+
@module_opts[:rhtml] = true
|
301
|
+
end
|
302
|
+
|
303
|
+
opts.on('--no-rhtml', "Don't parse RHTML tags.") do
|
304
|
+
@options[:no_rhtml] = true
|
305
|
+
end
|
306
|
+
|
307
|
+
opts.on('-x', '--xhtml', 'Parse the input using the more strict XHTML parser.') do
|
308
|
+
@module_opts[:xhtml] = true
|
309
|
+
end
|
310
|
+
|
311
|
+
super
|
312
|
+
end
|
313
|
+
|
314
|
+
def process_result
|
315
|
+
super
|
316
|
+
|
317
|
+
input = @options[:input]
|
318
|
+
output = @options[:output]
|
319
|
+
|
320
|
+
@module_opts[:rhtml] ||= input.respond_to?(:path) && input.path =~ /\.(rhtml|erb)$/
|
321
|
+
@module_opts[:rhtml] &&= @options[:no_rhtml] != false
|
322
|
+
|
323
|
+
output.write(::Haml::HTML.new(input, @module_opts).render)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
# A class encapsulating executable functionality
|
328
|
+
# specific to the css2sass executable.
|
329
|
+
class CSS2Sass < Generic # :nodoc:
|
330
|
+
def initialize(args)
|
331
|
+
super
|
332
|
+
|
333
|
+
@module_opts = {}
|
334
|
+
|
335
|
+
require 'sass/css'
|
336
|
+
end
|
337
|
+
|
338
|
+
def set_opts(opts)
|
339
|
+
opts.banner = <<END
|
340
|
+
Usage: css2sass [options] [INPUT] [OUTPUT]
|
341
|
+
|
342
|
+
Description: Transforms a CSS file into corresponding Sass code.
|
343
|
+
|
344
|
+
Options:
|
345
|
+
END
|
346
|
+
|
347
|
+
opts.on('-a', '--alternate', 'Output using alternative Sass syntax (margin: 1px)') do
|
348
|
+
@module_opts[:alternate] = true
|
349
|
+
end
|
350
|
+
|
351
|
+
super
|
352
|
+
end
|
353
|
+
|
354
|
+
def process_result
|
355
|
+
super
|
356
|
+
|
357
|
+
input = @options[:input]
|
358
|
+
output = @options[:output]
|
359
|
+
|
360
|
+
output.write(::Sass::CSS.new(input, @module_opts).render)
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
module Haml
|
2
|
+
# The module containing the default filters,
|
3
|
+
# as well as the base module,
|
4
|
+
# Haml::Filters::Base.
|
5
|
+
module Filters
|
6
|
+
# Returns a hash of defined filters.
|
7
|
+
def self.defined
|
8
|
+
@defined ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# The base module for Haml filters.
|
12
|
+
# User-defined filters should be modules including this module.
|
13
|
+
#
|
14
|
+
# A user-defined filter should override either Base#render or Base #compile.
|
15
|
+
# Base#render is the most common.
|
16
|
+
# It takes a string, the filter source,
|
17
|
+
# and returns another string,
|
18
|
+
# the result of the filter.
|
19
|
+
# For example:
|
20
|
+
#
|
21
|
+
# module Haml::Filters::Sass
|
22
|
+
# include Haml::Filters::Base
|
23
|
+
#
|
24
|
+
# def render(text)
|
25
|
+
# ::Sass::Engine.new(text).render
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# For details on overriding #compile, see its documentation.
|
30
|
+
#
|
31
|
+
module Base
|
32
|
+
def self.included(base) # :nodoc:
|
33
|
+
Filters.defined[base.name.split("::").last.downcase] = base
|
34
|
+
base.extend(base)
|
35
|
+
base.instance_variable_set "@lazy_requires", nil
|
36
|
+
end
|
37
|
+
|
38
|
+
# Takes a string, the source text that should be passed to the filter,
|
39
|
+
# and returns the string resulting from running the filter on <tt>text</tt>.
|
40
|
+
#
|
41
|
+
# This should be overridden in most individual filter modules
|
42
|
+
# to render text with the given filter.
|
43
|
+
# If compile is overridden, however, render doesn't need to be.
|
44
|
+
def render(text)
|
45
|
+
raise Error.new("#{self.inspect}#render not defined!")
|
46
|
+
end
|
47
|
+
|
48
|
+
# Same as render, but takes the Haml options hash as well.
|
49
|
+
# It's only safe to rely on options made available in Haml::Engine#options_for_buffer.
|
50
|
+
def render_with_options(text, options)
|
51
|
+
render(text)
|
52
|
+
end
|
53
|
+
|
54
|
+
def internal_compile(*args) # :nodoc:
|
55
|
+
resolve_lazy_requires
|
56
|
+
compile(*args)
|
57
|
+
end
|
58
|
+
|
59
|
+
# compile should be overridden when a filter needs to have access
|
60
|
+
# to the Haml evaluation context.
|
61
|
+
# Rather than applying a filter to a string at compile-time,
|
62
|
+
# compile uses the Haml::Precompiler instance to compile the string to Ruby code
|
63
|
+
# that will be executed in the context of the active Haml template.
|
64
|
+
#
|
65
|
+
# Warning: the Haml::Precompiler interface is neither well-documented
|
66
|
+
# nor guaranteed to be stable.
|
67
|
+
# If you want to make use of it,
|
68
|
+
# you'll probably need to look at the source code
|
69
|
+
# and should test your filter when upgrading to new Haml versions.
|
70
|
+
def compile(precompiler, text)
|
71
|
+
resolve_lazy_requires
|
72
|
+
filter = self
|
73
|
+
precompiler.instance_eval do
|
74
|
+
if contains_interpolation?(text)
|
75
|
+
return if options[:suppress_eval]
|
76
|
+
|
77
|
+
push_script(<<RUBY, false)
|
78
|
+
find_and_preserve(#{filter.inspect}.render_with_options(#{unescape_interpolation(text)}, _hamlout.options))
|
79
|
+
RUBY
|
80
|
+
return
|
81
|
+
end
|
82
|
+
|
83
|
+
rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, precompiler.options), precompiler.options[:preserve])
|
84
|
+
|
85
|
+
if !options[:ugly]
|
86
|
+
push_text(rendered.rstrip.gsub("\n", "\n#{' ' * @output_tabs}"))
|
87
|
+
else
|
88
|
+
push_text(rendered.rstrip)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# This becomes a class method of modules that include Base.
|
94
|
+
# It allows the module to specify one or more Ruby files
|
95
|
+
# that Haml should try to require when compiling the filter.
|
96
|
+
#
|
97
|
+
# The first file specified is tried first,
|
98
|
+
# then the second, etc.
|
99
|
+
# If none are found, the compilation throws an exception.
|
100
|
+
#
|
101
|
+
# For example:
|
102
|
+
#
|
103
|
+
# module Haml::Filters::Markdown
|
104
|
+
# lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
|
105
|
+
#
|
106
|
+
# ...
|
107
|
+
# end
|
108
|
+
#
|
109
|
+
def lazy_require(*reqs)
|
110
|
+
@lazy_requires = reqs
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def resolve_lazy_requires
|
116
|
+
return unless @lazy_requires
|
117
|
+
|
118
|
+
@lazy_requires[0...-1].each do |req|
|
119
|
+
begin
|
120
|
+
@required = req
|
121
|
+
require @required
|
122
|
+
return
|
123
|
+
rescue LoadError; end # RCov doesn't see this, but it is run
|
124
|
+
end
|
125
|
+
|
126
|
+
begin
|
127
|
+
@required = @lazy_requires[-1]
|
128
|
+
require @required
|
129
|
+
rescue LoadError => e
|
130
|
+
classname = self.name.match(/\w+$/)[0]
|
131
|
+
|
132
|
+
if @lazy_requires.size == 1
|
133
|
+
raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found")
|
134
|
+
else
|
135
|
+
raise Error.new("Can't run #{classname} filter; required #{@lazy_requires.map { |r| "'#{r}'" }.join(' or ')}, but none were found")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
# :stopdoc:
|
144
|
+
|
145
|
+
begin
|
146
|
+
require 'rubygems'
|
147
|
+
rescue LoadError; end
|
148
|
+
|
149
|
+
module Haml
|
150
|
+
module Filters
|
151
|
+
module Plain
|
152
|
+
include Base
|
153
|
+
|
154
|
+
def render(text); text; end
|
155
|
+
end
|
156
|
+
|
157
|
+
module Javascript
|
158
|
+
include Base
|
159
|
+
|
160
|
+
def render_with_options(text, options)
|
161
|
+
<<END
|
162
|
+
<script type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}>
|
163
|
+
//<![CDATA[
|
164
|
+
#{text.rstrip.gsub("\n", "\n ")}
|
165
|
+
//]]>
|
166
|
+
</script>
|
167
|
+
END
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
module Cdata
|
172
|
+
include Base
|
173
|
+
|
174
|
+
def render(text)
|
175
|
+
"<![CDATA[#{("\n" + text).rstrip.gsub("\n", "\n ")}\n]]>"
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
module Escaped
|
180
|
+
include Base
|
181
|
+
|
182
|
+
def render(text)
|
183
|
+
Haml::Helpers.html_escape text
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
module Ruby
|
188
|
+
include Base
|
189
|
+
lazy_require 'stringio'
|
190
|
+
|
191
|
+
def compile(precompiler, text)
|
192
|
+
return if precompiler.options[:suppress_eval]
|
193
|
+
precompiler.instance_eval do
|
194
|
+
push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
|
195
|
+
_haml_old_stdout = $stdout
|
196
|
+
$stdout = StringIO.new(_hamlout.buffer, 'a')
|
197
|
+
FIRST
|
198
|
+
_haml_old_stdout, $stdout = $stdout, _haml_old_stdout
|
199
|
+
_haml_old_stdout.close
|
200
|
+
LAST
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
module Preserve
|
206
|
+
include Base
|
207
|
+
|
208
|
+
def render(text)
|
209
|
+
Haml::Helpers.preserve text
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
module Sass
|
214
|
+
include Base
|
215
|
+
lazy_require 'sass/plugin'
|
216
|
+
|
217
|
+
def render(text)
|
218
|
+
::Sass::Engine.new(text, ::Sass::Plugin.engine_options).render
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
module ERB
|
223
|
+
include Base
|
224
|
+
lazy_require 'erb'
|
225
|
+
|
226
|
+
def compile(precompiler, text)
|
227
|
+
return if precompiler.options[:suppress_eval]
|
228
|
+
src = ::ERB.new(text).src.sub(/^_erbout = '';/, "").gsub("\n", ';')
|
229
|
+
precompiler.send(:push_silent, src)
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
module Textile
|
234
|
+
include Base
|
235
|
+
lazy_require 'redcloth'
|
236
|
+
|
237
|
+
def render(text)
|
238
|
+
::RedCloth.new(text).to_html(:textile)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
RedCloth = Textile
|
242
|
+
Filters.defined['redcloth'] = RedCloth
|
243
|
+
|
244
|
+
# Uses BlueCloth or RedCloth to provide only Markdown (not Textile) parsing
|
245
|
+
module Markdown
|
246
|
+
include Base
|
247
|
+
lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth'
|
248
|
+
|
249
|
+
def render(text)
|
250
|
+
engine = case @required
|
251
|
+
when 'rdiscount'
|
252
|
+
RDiscount
|
253
|
+
when 'peg_markdown'
|
254
|
+
PEGMarkdown
|
255
|
+
when 'maruku'
|
256
|
+
Maruku
|
257
|
+
when 'bluecloth'
|
258
|
+
BlueCloth
|
259
|
+
end
|
260
|
+
engine.new(text).to_html
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
module Maruku
|
265
|
+
include Base
|
266
|
+
lazy_require 'maruku'
|
267
|
+
|
268
|
+
def render(text)
|
269
|
+
Maruku.new(text).to_html
|
270
|
+
end
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
# :startdoc:
|