Sha256: 79224476cb0a861e00756a10f60d9ac9d6c5fdfc42afc2c2031aa081a3e67668

Contents?: true

Size: 977 Bytes

Versions: 10

Compression:

Stored size: 977 Bytes

Contents

module PgEngine
  module PgRailsHelper
    def dev?
      Rails.env.development? || current_user&.developer?
    end

    def current_account
      current_user&.current_account
    end

    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

    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

10 entries across 10 versions & 1 rubygems

Version Path
pg_rails-7.0.8.pre.alpha.24 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.23 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.22 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.21 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.20 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.19 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.18 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.17 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.16 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
pg_rails-7.0.8.pre.alpha.15 pg_engine/app/helpers/pg_engine/pg_rails_helper.rb