Sha256: c4b400a78206106d7afcedc73a60ff2c2982912ff597b4daa2b0fade1a5f8482

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module Revelry::Content::ContentsHelper

  def revelry_content_text(key, default: "")
    lookup = @revelry_content_contents

    if lookup.present? && lookup.has_key?(key)
      content = lookup[key]
    else
      content = {
        key: key,
        content: default,
        html_content: default
      }
    end
    content = HashWithIndifferentAccess.new(content)

    props = {
      content: content,
      canEdit: Revelry::Content.config.authorize(controller)
    }.to_json

    content_tag :span, 'data-react-class' => 'Rev.Content.EditableText', 'data-react-props' => props do
      content[:html_content].html_safe
    end
  end

  def revelry_content_image(key, default: nil)
    lookup = @revelry_content_contents

    if lookup.present? && lookup.has_key?(key)
      content = lookup[key]
    else
      content = {
        key: key,
        src: default
      }
    end
    content = HashWithIndifferentAccess.new(content)

    if Revelry::Content.config.authorize(controller)
      props = {
        content: content,
        canEdit: true
      }.to_json

      content_tag :span, 'data-react-class' => 'Rev.Content.EditableImage', 'data-react-props' => props do
        image_tag content["src"]
      end
    else
      image_tag content["src"]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
revelry_content-1.0.0 lib/revelry/content/contents_helper.rb