Sha256: 30c3c16b9981ee7459b7385bc38a49578cc432419e914c58bcf5f71c202e7417

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require "microformats-helper/version"

module MicroformatsHelper
  module Helper


    PROP_TYPE_BASE_URL = "http://data-vocabulary.org/"

    def generate_microformats(container,props,childs=nil)


      "#{span_outer(container)}#{parse_props(props)}#{childs}#{span_end}".html_safe
    end

    def type_url(type)

      "#{PROP_TYPE_BASE_URL}#{type}"
    end

    def span_outer(container)
      "<span style='display:none' #{parse_itemprop(container[:itemprop])} #{type_prop(container[:type])}>"
    end

    def parse_itemprop(itemprop)
      "itemprop='#{itemprop}'" if itemprop
    end

    def span_end
      "</span>"
    end

    def span(key,content)
      "<span style='display:none' itemprop='#{key.to_s}' #{parse_content(content)}>"

    end

    def parse_content(content)
      "content='#{content}'" if content
    end

    def parse_props(props)
      html=""
      props.each do |key,prop|

        html+="#{span(key,prop[:content])}#{prop[:value]}#{span_end}"
      end
      return html
    end

    def type_prop(type)
      "itemscope itemtype='#{type_url(type)}'"
    end
  end
end

ActiveSupport.on_load(:action_view) do
  include MicroformatsHelper::Helper
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
microformats-helper-0.3.1 lib/microformats-helper.rb
microformats-helper-0.3.0 lib/microformats-helper.rb
microformats-helper-0.2.6 lib/microformats-helper.rb