1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Resurrect support of #haml_object_ref

Close #1097
This commit is contained in:
Takashi Kokubun 2022-10-04 23:56:32 -07:00
parent 90f9ac6ec8
commit 78811edc3a
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD
3 changed files with 15 additions and 8 deletions

View file

@ -6,7 +6,12 @@ module Haml
object, prefix = args
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('_'),
'id' => [prefix, suffix, object.id || 'new'].compact.join('_'),

View file

@ -1299,22 +1299,22 @@ HAML
render("%p[user] New User", :locals => {:user => user}))
end
def test_object_ref_before_attrs; skip # object reference
def test_object_ref_before_attrs
user = User.new 42
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
def test_object_ref_with_custom_haml_class; skip # object reference
def test_object_ref_with_custom_haml_class
custom = CustomHamlClass.new 42
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
def test_object_ref_with_multiple_ids; skip # object reference
def test_object_ref_with_multiple_ids
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",
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
def test_non_literal_attributes

View file

@ -58,12 +58,14 @@ class Haml::TestCase < BASE_TEST_CLASS
eval Haml::Engine.new(options).call(text), scope
end
def assert_haml_ugly(text, options = {})
def render_template(text, options = {})
haml_base = { escape_html: true }
scope = options.delete(:scope) || Object.new
locals = options.delete(:locals) || {}
Haml::Template.new(haml_base.merge(options)) { text }.render(scope, locals)
end
# TODO: fix the usages of assert_haml_ugly
alias :assert_haml_ugly :render_template
def assert_warning(message)
the_real_stderr, $stderr = $stderr, StringIO.new