Sha256: a6addbd73659727f8a75c9db617938ea544f8117b6f818fa2d66369a57ecd888

Contents?: true

Size: 1.97 KB

Versions: 62

Compression:

Stored size: 1.97 KB

Contents

module Workarea
  module ApplicationHelper
    def product_image_url(image, job)
      host = Rails.application.config.action_controller.asset_host
      source = image_url(product_image_path(image, job))
      return source if host.blank? || source =~ /^(http|\/\/)/

      # These shenanigans are here to work around a Rails problem where the
      # configured asset host isn't being used if it's a proc. We use a proc in
      # the multi_site plugin.
      #
      # The gist of it was copied from the Rails `compute_asset_host` helper.
      #

      host_value = if host.respond_to?(:call)
        request = respond_to?(:request) ? request : nil
        arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
        args = [source]

        args << request if request && (arity > 1 || arity < 0)
        host.call(*args)
      elsif host.include?('%d')
        host % (Zlib.crc32(source) % 4)
      else
        host
      end

      host_value.present? ? File.join(host_value, source) : source
    end

    def product_image_path(image, job)
      if image.placeholder?
        mounted_core.product_image_placeholder_path(
          job,
          c: image.updated_at.to_i
        )
      elsif image.option.present?
        mounted_core.dynamic_product_image_path(
          slug: image.product.slug,
          option: image.option,
          image_id: image.id,
          job: job,
          c: image.updated_at.to_i
        )
      else
        mounted_core.dynamic_product_image_path(
          slug: image.product.slug,
          image_id: image.id,
          option: nil,
          job: job,
          c: image.updated_at.to_i
        )
      end
    end

    def datetime_picker_tag(name, value = nil, options = {})
      if value.present? && (value.is_a?(DateTime) || value.is_a?(Time))
        value = value.to_s(:iso8601)
      end

      text_field_tag(name, value, options)
    end

    private

    def mounted_core
      send(Workarea::Core::Engine.mount_point)
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/helpers/workarea/application_helper.rb
workarea-core-3.4.36 app/helpers/workarea/application_helper.rb
workarea-core-3.5.14 app/helpers/workarea/application_helper.rb
workarea-core-3.4.35 app/helpers/workarea/application_helper.rb
workarea-core-3.5.13 app/helpers/workarea/application_helper.rb
workarea-core-3.4.34 app/helpers/workarea/application_helper.rb
workarea-core-3.5.12 app/helpers/workarea/application_helper.rb
workarea-core-3.4.33 app/helpers/workarea/application_helper.rb
workarea-core-3.5.11 app/helpers/workarea/application_helper.rb
workarea-core-3.5.10 app/helpers/workarea/application_helper.rb
workarea-core-3.4.32 app/helpers/workarea/application_helper.rb
workarea-core-3.5.9 app/helpers/workarea/application_helper.rb
workarea-core-3.4.31 app/helpers/workarea/application_helper.rb
workarea-core-3.5.8 app/helpers/workarea/application_helper.rb
workarea-core-3.4.30 app/helpers/workarea/application_helper.rb
workarea-core-3.5.7 app/helpers/workarea/application_helper.rb
workarea-core-3.4.29 app/helpers/workarea/application_helper.rb
workarea-core-3.5.6 app/helpers/workarea/application_helper.rb
workarea-core-3.4.28 app/helpers/workarea/application_helper.rb
workarea-core-3.5.5 app/helpers/workarea/application_helper.rb