mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
parent
90f9ac6ec8
commit
78811edc3a
3 changed files with 15 additions and 8 deletions
|
@ -6,7 +6,12 @@ module Haml
|
||||||
object, prefix = args
|
object, prefix = args
|
||||||
return {} unless object
|
return {} unless object
|
||||||
|
|
||||||
suffix = underscore(object.class)
|
suffix =
|
||||||
|
if object.respond_to?(:haml_object_ref)
|
||||||
|
object.haml_object_ref
|
||||||
|
else
|
||||||
|
underscore(object.class)
|
||||||
|
end
|
||||||
{
|
{
|
||||||
'class' => [prefix, suffix].compact.join('_'),
|
'class' => [prefix, suffix].compact.join('_'),
|
||||||
'id' => [prefix, suffix, object.id || 'new'].compact.join('_'),
|
'id' => [prefix, suffix, object.id || 'new'].compact.join('_'),
|
||||||
|
|
|
@ -1299,22 +1299,22 @@ HAML
|
||||||
render("%p[user] New User", :locals => {:user => user}))
|
render("%p[user] New User", :locals => {:user => user}))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_object_ref_before_attrs; skip # object reference
|
def test_object_ref_before_attrs
|
||||||
user = User.new 42
|
user = User.new 42
|
||||||
assert_equal("<p class='struct_user' id='struct_user_42' style='width: 100px;'>New User</p>\n",
|
assert_equal("<p class='struct_user' id='struct_user_42' style='width: 100px;'>New User</p>\n",
|
||||||
render("%p[user]{:style => 'width: 100px;'} New User", :locals => {:user => user}))
|
render_template("%p[user]{:style => 'width: 100px;'} New User", locals: { user: user }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_object_ref_with_custom_haml_class; skip # object reference
|
def test_object_ref_with_custom_haml_class
|
||||||
custom = CustomHamlClass.new 42
|
custom = CustomHamlClass.new 42
|
||||||
assert_equal("<p class='my_thing' id='my_thing_42' style='width: 100px;'>My Thing</p>\n",
|
assert_equal("<p class='my_thing' id='my_thing_42' style='width: 100px;'>My Thing</p>\n",
|
||||||
render("%p[custom]{:style => 'width: 100px;'} My Thing", :locals => {:custom => custom}))
|
render_template("%p[custom]{:style => 'width: 100px;'} My Thing", locals: { custom: custom }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_object_ref_with_multiple_ids; skip # object reference
|
def test_object_ref_with_multiple_ids
|
||||||
cpk_record = CpkRecord.new([42,6,9])
|
cpk_record = CpkRecord.new([42,6,9])
|
||||||
assert_equal("<p class='struct_cpk_record' id='struct_cpk_record_42_6_9' style='width: 100px;'>CPK Record</p>\n",
|
assert_equal("<p class='struct_cpk_record' id='struct_cpk_record_42_6_9' style='width: 100px;'>CPK Record</p>\n",
|
||||||
render("%p[cpk_record]{:style => 'width: 100px;'} CPK Record", :locals => {:cpk_record => cpk_record}))
|
render_template("%p[cpk_record]{:style => 'width: 100px;'} CPK Record", locals: { cpk_record: cpk_record }))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_non_literal_attributes
|
def test_non_literal_attributes
|
||||||
|
|
|
@ -58,12 +58,14 @@ class Haml::TestCase < BASE_TEST_CLASS
|
||||||
eval Haml::Engine.new(options).call(text), scope
|
eval Haml::Engine.new(options).call(text), scope
|
||||||
end
|
end
|
||||||
|
|
||||||
def assert_haml_ugly(text, options = {})
|
def render_template(text, options = {})
|
||||||
haml_base = { escape_html: true }
|
haml_base = { escape_html: true }
|
||||||
scope = options.delete(:scope) || Object.new
|
scope = options.delete(:scope) || Object.new
|
||||||
locals = options.delete(:locals) || {}
|
locals = options.delete(:locals) || {}
|
||||||
Haml::Template.new(haml_base.merge(options)) { text }.render(scope, locals)
|
Haml::Template.new(haml_base.merge(options)) { text }.render(scope, locals)
|
||||||
end
|
end
|
||||||
|
# TODO: fix the usages of assert_haml_ugly
|
||||||
|
alias :assert_haml_ugly :render_template
|
||||||
|
|
||||||
def assert_warning(message)
|
def assert_warning(message)
|
||||||
the_real_stderr, $stderr = $stderr, StringIO.new
|
the_real_stderr, $stderr = $stderr, StringIO.new
|
||||||
|
|
Loading…
Reference in a new issue