Sha256: f3231d50c4c74de6f0d3ce4020b9ca3d4e61b97bba2b917dada739020fccc0c5

Contents?: true

Size: 963 Bytes

Versions: 8

Compression:

Stored size: 963 Bytes

Contents

module PgEngine
  module PgRailsHelper
    def img_placeholder(src: nil, width: '100%', height: '100%', fade_in: false, **img_opts)
      if fade_in || src.nil?
        img_opts = img_opts.merge(style: [img_opts[:style], 'display:none'].compact.join(';'))
        do_placeholder(src, width:, height:, **img_opts)
      else
        image_tag src, **img_opts
      end
    end

    def dev_user_or_env?
      Rails.env.development? || dev_user?
    end

    def dev_user?
      Current.user&.developer?
    end

    private

    def do_placeholder(src = nil, width: '100%', height: '100%', **img_opts)
      content_tag('div', class: 'placeholder-glow', style: "width: #{width}; height: #{height}") do
        content_tag('div', class: 'placeholder w-100 h-100') do
          if src.present?
            image_tag src,
                      'data-controller': 'fadein_onload',
                      **img_opts
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
pg_rails-7.6.27 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.26 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.25 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.24 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.24.pre.5 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.24.pre.4 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.24.pre.3 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.6.23 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb