haml 1.8.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/FAQ +138 -0
- data/MIT-LICENSE +1 -1
- data/{README → README.rdoc} +66 -3
- data/REVISION +1 -0
- data/Rakefile +115 -147
- data/VERSION +1 -1
- data/bin/css2sass +0 -0
- data/bin/haml +2 -1
- data/bin/html2haml +0 -0
- data/bin/sass +0 -0
- data/init.rb +6 -1
- data/lib/haml/buffer.rb +122 -64
- data/lib/haml/engine.rb +77 -46
- data/lib/haml/error.rb +15 -6
- data/lib/haml/exec.rb +61 -10
- data/lib/haml/filters.rb +229 -74
- data/lib/haml/helpers/action_view_extensions.rb +1 -1
- data/lib/haml/helpers/action_view_mods.rb +109 -24
- data/lib/haml/helpers.rb +137 -76
- data/lib/haml/html.rb +8 -8
- data/lib/haml/precompiler.rb +280 -153
- data/lib/haml/template/patch.rb +10 -3
- data/lib/haml/template/plugin.rb +61 -10
- data/lib/haml/template.rb +14 -9
- data/lib/haml.rb +483 -214
- data/lib/sass/constant/color.rb +13 -13
- data/lib/sass/constant/literal.rb +8 -7
- data/lib/sass/constant/nil.rb +9 -0
- data/lib/sass/constant/number.rb +10 -10
- data/lib/sass/constant/operation.rb +4 -4
- data/lib/sass/constant/string.rb +3 -3
- data/lib/sass/constant.rb +46 -77
- data/lib/sass/css.rb +130 -56
- data/lib/sass/engine.rb +131 -43
- data/lib/sass/plugin/merb.rb +48 -12
- data/lib/sass/plugin/rails.rb +10 -4
- data/lib/sass/plugin.rb +33 -10
- data/lib/sass/tree/attr_node.rb +5 -5
- data/lib/sass/tree/directive_node.rb +2 -7
- data/lib/sass/tree/node.rb +1 -12
- data/lib/sass/tree/rule_node.rb +39 -31
- data/lib/sass/tree/value_node.rb +1 -1
- data/lib/sass.rb +194 -19
- data/rails/init.rb +1 -0
- data/test/benchmark.rb +67 -80
- data/test/haml/engine_test.rb +368 -152
- data/test/haml/helper_test.rb +68 -16
- data/test/haml/html2haml_test.rb +3 -4
- data/test/haml/results/content_for_layout.xhtml +1 -2
- data/test/haml/results/eval_suppressed.xhtml +2 -4
- data/test/haml/results/filters.xhtml +38 -30
- data/test/haml/results/helpers.xhtml +4 -8
- data/test/haml/results/just_stuff.xhtml +8 -7
- data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
- data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
- data/test/haml/results/original_engine.xhtml +3 -7
- data/test/haml/results/partials.xhtml +1 -0
- data/test/haml/results/tag_parsing.xhtml +1 -6
- data/test/haml/results/very_basic.xhtml +2 -4
- data/test/haml/results/whitespace_handling.xhtml +13 -21
- data/test/haml/template_test.rb +42 -57
- data/test/haml/templates/_partial.haml +1 -0
- data/test/haml/templates/filters.haml +39 -21
- data/test/haml/templates/helpers.haml +10 -10
- data/test/haml/templates/just_stuff.haml +8 -3
- data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
- data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
- data/test/haml/templates/partials.haml +1 -1
- data/test/haml/templates/tag_parsing.haml +0 -3
- data/test/haml/templates/whitespace_handling.haml +10 -10
- data/test/sass/engine_test.rb +97 -39
- data/test/sass/plugin_test.rb +4 -7
- data/test/sass/results/constants.css +2 -0
- data/test/sass/results/import.css +2 -2
- data/test/sass/results/mixins.css +95 -0
- data/test/sass/results/multiline.css +24 -0
- data/test/sass/templates/constants.sass +3 -0
- data/test/sass/templates/import.sass +4 -1
- data/test/sass/templates/importee.sass +4 -0
- data/test/sass/templates/mixins.sass +76 -0
- data/test/sass/templates/multiline.sass +20 -0
- data/test/test_helper.rb +18 -0
- metadata +70 -53
- data/lib/haml/helpers/action_view_mods.rb.rej +0 -30
- data/lib/haml/util.rb +0 -18
- data/lib/sass/constant.rb.rej +0 -42
- data/test/haml/runner.rb +0 -16
- data/test/profile.rb +0 -65
- data/test/sass/engine_test.rb.rej +0 -18
data/lib/haml/template/patch.rb
CHANGED
|
@@ -26,7 +26,7 @@ module ActionView
|
|
|
26
26
|
def compile_haml(template, file_name, local_assigns)
|
|
27
27
|
render_symbol = assign_method_name(:haml, template, file_name)
|
|
28
28
|
locals = local_assigns.keys
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
@@template_args[render_symbol] ||= {}
|
|
31
31
|
locals_keys = @@template_args[render_symbol].keys | locals
|
|
32
32
|
@@template_args[render_symbol] = locals_keys.inject({}) { |h, k| h[k] = true; h }
|
|
@@ -35,14 +35,21 @@ module ActionView
|
|
|
35
35
|
options[:filename] = file_name || 'compiled-template'
|
|
36
36
|
|
|
37
37
|
begin
|
|
38
|
-
Haml::Engine.new(template, options).def_method(CompiledTemplates, render_symbol, *
|
|
38
|
+
Haml::Engine.new(template, options).def_method(CompiledTemplates, render_symbol, *locals_keys)
|
|
39
39
|
rescue Exception => e
|
|
40
40
|
if logger
|
|
41
41
|
logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
|
|
42
42
|
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
base_path = if defined?(extract_base_path_from)
|
|
46
|
+
# Rails 2.0.x
|
|
47
|
+
extract_base_path_from(file_name) || view_paths.first
|
|
48
|
+
else
|
|
49
|
+
# Rails <=1.2.6
|
|
50
|
+
@base_path
|
|
51
|
+
end
|
|
52
|
+
raise ActionView::TemplateError.new(base_path, file_name || template, @assigns, template, e)
|
|
46
53
|
end
|
|
47
54
|
|
|
48
55
|
@@compile_time[render_symbol] = Time.now
|
data/lib/haml/template/plugin.rb
CHANGED
|
@@ -1,21 +1,72 @@
|
|
|
1
|
+
# :stopdoc:
|
|
1
2
|
# This file makes Haml work with Rails
|
|
2
3
|
# using the > 2.0.1 template handler API.
|
|
3
4
|
|
|
4
5
|
module Haml
|
|
5
|
-
class
|
|
6
|
-
|
|
7
|
-
1
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def initialize(view)
|
|
11
|
-
@view = view
|
|
12
|
-
end
|
|
6
|
+
class Plugin < ActionView::TemplateHandler
|
|
7
|
+
include ActionView::TemplateHandlers::Compilable if defined?(ActionView::TemplateHandlers::Compilable)
|
|
13
8
|
|
|
14
9
|
def compile(template)
|
|
15
10
|
options = Haml::Template.options.dup
|
|
16
|
-
|
|
11
|
+
|
|
12
|
+
# template is a template object in Rails >=2.1.0,
|
|
13
|
+
# a source string previously
|
|
14
|
+
if template.respond_to? :source
|
|
15
|
+
options[:filename] = template.filename
|
|
16
|
+
source = template.source
|
|
17
|
+
else
|
|
18
|
+
source = template
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
Haml::Engine.new(source, options).send(:precompiled_with_ambles, [])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cache_fragment(block, name = {}, options = nil)
|
|
25
|
+
@view.fragment_for(block, name, options) do
|
|
26
|
+
eval("_hamlout.buffer", block.binding)
|
|
27
|
+
end
|
|
17
28
|
end
|
|
18
29
|
end
|
|
19
30
|
end
|
|
20
31
|
|
|
21
|
-
ActionView::
|
|
32
|
+
if defined? ActionView::Template and ActionView::Template.respond_to? :register_template_handler
|
|
33
|
+
ActionView::Template
|
|
34
|
+
else
|
|
35
|
+
ActionView::Base
|
|
36
|
+
end.register_template_handler(:haml, Haml::Plugin)
|
|
37
|
+
|
|
38
|
+
# In Rails 2.0.2, ActionView::TemplateError took arguments
|
|
39
|
+
# that we can't fill in from the Haml::Plugin context.
|
|
40
|
+
# Thus, we've got to monkeypatch ActionView::Base to catch the error.
|
|
41
|
+
if ActionView::TemplateError.instance_method(:initialize).arity == 5
|
|
42
|
+
class ActionView::Base
|
|
43
|
+
def compile_template(handler, template, file_name, local_assigns)
|
|
44
|
+
render_symbol = assign_method_name(handler, template, file_name)
|
|
45
|
+
|
|
46
|
+
# Move begin up two lines so it captures compilation exceptions.
|
|
47
|
+
begin
|
|
48
|
+
render_source = create_template_source(handler, template, render_symbol, local_assigns.keys)
|
|
49
|
+
line_offset = @@template_args[render_symbol].size + handler.line_offset
|
|
50
|
+
|
|
51
|
+
file_name = 'compiled-template' if file_name.blank?
|
|
52
|
+
CompiledTemplates.module_eval(render_source, file_name, -line_offset)
|
|
53
|
+
rescue Exception => e # errors from template code
|
|
54
|
+
if logger
|
|
55
|
+
logger.debug "ERROR: compiling #{render_symbol} RAISED #{e}"
|
|
56
|
+
logger.debug "Function body: #{render_source}"
|
|
57
|
+
logger.debug "Backtrace: #{e.backtrace.join("\n")}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# There's no way to tell Haml about the filename,
|
|
61
|
+
# so we've got to insert it ourselves.
|
|
62
|
+
e.backtrace[0].gsub!('(haml)', file_name) if e.is_a?(Haml::Error)
|
|
63
|
+
|
|
64
|
+
raise ActionView::TemplateError.new(extract_base_path_from(file_name) || view_paths.first, file_name || template, @assigns, template, e)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
@@compile_time[render_symbol] = Time.now
|
|
68
|
+
# logger.debug "Compiled template #{file_name || template}\n ==> #{render_symbol}" if logger
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
# :startdoc:
|
data/lib/haml/template.rb
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
require 'haml/engine'
|
|
2
|
-
require 'rubygems'
|
|
3
|
-
require 'active_support'
|
|
4
|
-
require 'action_view'
|
|
5
2
|
|
|
6
3
|
module Haml
|
|
7
4
|
class Template
|
|
8
5
|
class << self
|
|
9
6
|
@@options = {}
|
|
10
7
|
|
|
11
|
-
# Gets various options for Haml. See README for details.
|
|
8
|
+
# Gets various options for Haml. See README.rdoc for details.
|
|
12
9
|
def options
|
|
13
10
|
@@options
|
|
14
11
|
end
|
|
15
12
|
|
|
16
|
-
# Sets various options for Haml. See README for details.
|
|
13
|
+
# Sets various options for Haml. See README.rdoc for details.
|
|
17
14
|
def options=(value)
|
|
18
15
|
@@options = value
|
|
19
16
|
end
|
|
@@ -38,9 +35,17 @@ if defined?(RAILS_ROOT)
|
|
|
38
35
|
# because the new init file is sufficiently flexible
|
|
39
36
|
# to not need updating.
|
|
40
37
|
rails_init_file = File.join(RAILS_ROOT, 'vendor', 'plugins', 'haml', 'init.rb')
|
|
41
|
-
haml_init_file =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
haml_init_file = Haml.scope('init.rb')
|
|
39
|
+
begin
|
|
40
|
+
if File.exists?(rails_init_file)
|
|
41
|
+
require 'fileutils'
|
|
42
|
+
FileUtils.cp(haml_init_file, rails_init_file) unless FileUtils.cmp(rails_init_file, haml_init_file)
|
|
43
|
+
end
|
|
44
|
+
rescue SystemCallError
|
|
45
|
+
warn <<END
|
|
46
|
+
HAML WARNING:
|
|
47
|
+
#{rails_init_file} is out of date and couldn't be automatically updated.
|
|
48
|
+
Please run `haml --rails #{File.expand_path(RAILS_ROOT)}' to update it.
|
|
49
|
+
END
|
|
45
50
|
end
|
|
46
51
|
end
|