Class: Haml::Buffer
- Inherits:
-
Object
- Object
- Haml::Buffer
- Defined in:
- lib/green_monkey/ext/haml.rb
Overview
this hack looks at active-record object’s :html_schema_type field and adds itemscope, itemid and itemtype to element example:
> <article class=“post” itemscope itemtype=“schema.org/BlogPosting” itemid=“1”>
> <section itemscope itemtype=“schema.org/Blog”>
%section[Mida(:Blog), :sexjokes]
> <section itemscope itemtype=“schema.org/Blog/SexJokes”>
according to “Extension Mechanism” at schema.org/docs/extension.html
%span Hello
> <span itemprop=“title”>Hello</span>
Instance Method Summary collapse
-
#parse_object_ref(ref) ⇒ Object
this methods calls then you pass %tag[object1, object2] ref argument is array.
- #process_object_ref(obj) ⇒ Object
Instance Method Details
#parse_object_ref(ref) ⇒ Object
this methods calls then you pass %tag[object1, object2] ref argument is array
24 25 26 27 28 29 30 31 32 |
# File 'lib/green_monkey/ext/haml.rb', line 24 def parse_object_ref(ref) = {} ref.each do |obj| next if obj == "local-variable" self.class.merge_attrs(, process_object_ref(obj)) end end |
#process_object_ref(obj) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/green_monkey/ext/haml.rb', line 34 def process_object_ref(obj) return {} if !obj if obj.is_a?(Symbol) # symbol => "itemprop" attribute return {'itemprop' => obj.to_s} elsif obj.kind_of?(Mida::Vocabulary) # Mida::Vocabulary => itemprop and itemtype return {itemscope: true, itemtype: obj.itemtype.source} elsif obj.is_a?(String) return {class: obj} else = {} [:class] = obj.respond_to?(:haml_object_ref) ? obj.haml_object_ref : underscore(obj.class) [:id] = "#{[:class]}_#{obj.id || 'new'}" if obj.respond_to?(:id) # my hack for microdata attributes if obj.respond_to?(:html_schema_type) [:itemscope] = true [:itemid] = obj.id if obj.html_schema_type.kind_of?(Mida::Vocabulary) [:itemtype] = obj.html_schema_type.itemtype.source else raise "No vocabulary found (#{obj.html_schema_type})" unless Mida::Vocabulary.find(obj.html_schema_type) [:itemtype] = obj.html_schema_type end end return end end |