Sha256: 151e79ec4302b70b74fe9e77af3d293edd56bfdaa9e9d9be9a69025d7d1105d5

Contents?: true

Size: 895 Bytes

Versions: 2

Compression:

Stored size: 895 Bytes

Contents

module LookupHelper

  def lookup code, default = nil, &block
    _lookup code, 'string', default, &block
  end

  def memo_lookup code, default = nil, &block
    sf(unsafe_memo_lookup(code, default, &block))
  end

  def unsafe_memo_lookup code, default = nil, &block
    _lookup code, 'memo', default, &block
  end

  def wysiwyg_lookup code, default = nil, &block
    raw(_lookup code, 'wysiwyg', default, &block)
  end

  def lookup_name code
    t("lookups.#{code}")
  end

  def sf text
    h(text).gsub("\n", "<br/>").html_safe
  end

  private

  def _lookup code, type, default, &block
    l = Lookup.where(code: code, type_code: type).first
    return l.value if l

    value = if block.present?
      capture(self, &block)
    else
      default
    end
    value = value.strip if value

    l = Lookup.create!(code: code, value: value, type_code: type)

    l.reload.value
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coalla-cms-0.4.2.0 app/helpers/lookup_helper.rb
coalla-cms-0.4.4.3 app/helpers/lookup_helper.rb