Sha256: 0cedfc986f3790392f413f80809a89983c7ede1a9ec8e6c4a8043f8f736a3918

Contents?: true

Size: 1.03 KB

Versions: 19

Compression:

Stored size: 1.03 KB

Contents

module Fiona7
  module AttributeWriters
    module Helpers
      class LinkSerializer
        def initialize(obj, klass)
          self.obj   = obj
          self.klass = klass
        end

        def call(link)
          link = link.symbolize_keys
          new_link = {}

          if link[:url]
            # handle www.example.com
            new_link[:url] = "external:#{link[:url]}" unless link[:url] =~ /\A[a-zA-Z][a-zA-Z0-9+.-]:/
          elsif obj_id = link[:obj_id] 
            # FIXME: use a repository here to speed up the lookup
            new_link[:url] = self.klass.find(obj_id).path
          end


          new_link[:url] ||= link[:url] 
          new_link[:title] = link[:title] if link[:title]
          new_link[:target] = link[:target] if link[:target]
          new_link[:url] = "#{new_link[:url]}?#{link[:query]}" if link[:query]
            new_link[:url] = "#{new_link[:url]}##{link[:fragment]}" if link[:fragment]

          new_link
        end

        protected
        attr_accessor :obj, :klass
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.2.0.2.3 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.2.0.2.1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.2.0.2.2 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.5.5.1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.2.0.1.4 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.2.0.1.3 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.5.3.1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.4.3.0 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.3.2.0 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.3.2.0.pre.beta1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.2.1.0.pre.beta1 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.5.2.0.0 lib/fiona7/attribute_writers/helpers/link_serializer.rb
infopark_fiona7-1.2.0.1.1 lib/fiona7/attribute_writers/helpers/link_serializer.rb