lib/scrivito/attribute_content.rb in scrivito_sdk-0.16.0 vs lib/scrivito/attribute_content.rb in scrivito_sdk-0.17.0

- old
+ new

@@ -2,19 +2,19 @@ module AttributeContent extend ActiveSupport::Concern def respond_to?(method_id, include_private=false) - if has_attribute?(method_id) + if has_custom_attribute?(method_id) true else super end end def method_missing(method_name, *args) - if has_attribute?(method_name) + if has_custom_attribute?(method_name) read_attribute(method_name.to_s) else super end end @@ -37,13 +37,14 @@ @attribute_cache[attribute_name] = prepare_attribute_value(raw_value, attribute_type, attribute_name) end end - def has_attribute?(name) + def has_custom_attribute?(name) data_from_cms.has_custom_attribute?(name.to_s) end + alias_method :has_attribute?, :has_custom_attribute? # @return [String] def type_of_attribute(field_name) data_from_cms.type_of(field_name.to_s) end @@ -119,10 +120,12 @@ StringTagging.tag_as_html(attribute_value) when "date" DateAttribute.parse(attribute_value) if attribute_value when "linklist" build_links(attribute_value) + when "link" + build_link(attribute_value) when "reference" BasicObj.find([attribute_value]).first when "referencelist" BasicObj.find(attribute_value).compact when "widget" @@ -144,9 +147,42 @@ links << link if link.resolved? end else [] end + end + + def build_link(attribute_value) + return unless attribute_value + + if attribute_value['destination'] + build_internal_link(attribute_value) + else + build_external_link(attribute_value) + end + end + + def build_internal_link(attribute_value) + properties = { + obj: Obj.find(attribute_value['destination']), + title: attribute_value['title'], + query: attribute_value['query'], + fragment: attribute_value['fragment'], + target: attribute_value['target'], + } + + Link.new(properties) + rescue ResourceNotFound + end + + def build_external_link(attribute_value) + properties = { + url: attribute_value['url'], + title: attribute_value['title'], + target: attribute_value['target'], + } + + Link.new(properties) end def build_widgets(widget_data, attribute_name) widget_data.map do |widget_id| widget = widget_from_pool(widget_id)