Sha256: 9b5d0ecb5fda158ff9f39709fe8712e1a80f74a06a92568911d15a2fc1a189b5

Contents?: true

Size: 647 Bytes

Versions: 3

Compression:

Stored size: 647 Bytes

Contents

# frozen_string_literal: true

module PageMeta
  class Link
    def self.build(rel, options)
      klass_name = "::PageMeta::Link::#{rel.to_s.camelize}"
      klass = begin
                const_get(klass_name)
              rescue ActionView::Template::Error, NameError
                Link
              end
      klass.new(rel, options)
    end

    attr_reader :rel, :options

    def initialize(rel, options)
      @rel = rel.to_s.dasherize
      @options = options
    end

    def render
      helpers.tag(:link, options.merge(rel: rel)) unless options.empty?
    end

    def helpers
      ActionController::Base.helpers
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
page_meta-0.2.0 lib/page_meta/link.rb
page_meta-0.1.3 lib/page_meta/link.rb
page_meta-0.1.2 lib/page_meta/link.rb