Sha256: b9c88a6881a8a4d147d62cc130385a81cbefcb3c4aa82e26f6684173da164df2

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

module TypeStation
  class ContentPresenter < BasePresenter
    presents :content

    def tag(default, options = {})
      css_class = options.delete(:class) if options.include?(:class)
      cl_image_tag((content.present? ? content['identifier'] : default), options.merge({class: ['ts-editable-image-tag', css_class], data: options}))
    end

    def link(default, html_options = nil, &block)
      css_class = html_options.delete(:class) if html_options.include?(:class)
      content_tag(:a, nil, html_options.merge({class: ['ts-editable-link-tag', css_class], href: link_href(default), data: link_data_attribute }), &block)
    end

    def value_is_hash?
      content.is_a? Hash
    end

    def value
      sanitized_value
    end

    private

    def sanitized_value
      @sanitized_value ||= Rails::Html::WhiteListSanitizer.new.sanitize(content)
    end

    def link_href(default)
      if content.present?
        if @options[:private]
          type_station.download_url(identifier: content['identifier'], format: content['format'])
        else
          cloudinary_url(content['identifier'], format: content['format'])
        end
      else
        default
      end
    end

    def link_data_attribute
       @options[:private] ? {download_url: type_station.download_url(identifier: 'IDENTIFIER', format: 'FORMAT')} : nil
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
type_station-0.7.0 app/presenters/type_station/content_presenter.rb
type_station-0.6.0 app/presenters/type_station/content_presenter.rb
type_station-0.5.4 app/presenters/type_station/content_presenter.rb
type_station-0.5.3 app/presenters/type_station/content_presenter.rb
type_station-0.5.2 app/presenters/type_station/content_presenter.rb
type_station-0.5.1 app/presenters/type_station/content_presenter.rb
type_station-0.4.7 app/presenters/type_station/content_presenter.rb
type_station-0.4.6 app/presenters/type_station/content_presenter.rb
type_station-0.4.5 app/presenters/type_station/content_presenter.rb
type_station-0.4.4 app/presenters/type_station/content_presenter.rb
type_station-0.4.3 app/presenters/type_station/content_presenter.rb
type_station-0.4.2 app/presenters/type_station/content_presenter.rb
type_station-0.4.1 app/presenters/type_station/content_presenter.rb
type_station-0.4.0 app/presenters/type_station/content_presenter.rb