lib/green_monkey/ext/haml.rb in green_monkey-0.2.2 vs lib/green_monkey/ext/haml.rb in green_monkey-0.3.0

- old
+ new

@@ -1,11 +1,11 @@ require "haml" # this hack looks at active-record object's :html_schema_type field and adds itemscope, itemid and itemtype to element # example: # -# %article[post] +# %article[post] # => <article class="post" itemscope itemtype="http://schema.org/BlogPosting" itemid="1"> # # %section[Mida(:Blog)] # => <section itemscope itemtype="http://schema.org/Blog"> # @@ -23,11 +23,15 @@ # ref argument is array def parse_object_ref(ref) options = {} ref.each do |obj| next if obj == "local-variable" - self.class.merge_attrs(options, process_object_ref(obj)) + if self.class.respond_to?(:merge_attrs) + self.class.merge_attrs(options, process_object_ref(obj)) + else + Haml::AttributeBuilder.merge_attributes!(options, process_object_ref(obj)) + end end options end def process_object_ref(obj) @@ -47,11 +51,11 @@ options['id'] = "#{options['class']}_#{obj.id || 'new'}" if obj.respond_to?(:id) # my hack for microdata attributes if obj.respond_to?(:html_schema_type) options['itemscope'] = true - options['itemid'] = obj.id + options['itemid'] = obj.has_attribute?(:slug) ? obj.slug : obj.id if obj.html_schema_type.kind_of?(Mida::Vocabulary) options['itemtype'] = obj.html_schema_type.itemtype.source else #raise "No vocabulary found (#{obj.html_schema_type})" unless Mida::Vocabulary.find(obj.html_schema_type) @@ -61,6 +65,6 @@ return options end end -end \ No newline at end of file +end