Sha256: 71e6d05bc68a13fcb7715e2e142da891c018fc69212b570c90f721c277013f71

Contents?: true

Size: 882 Bytes

Versions: 1

Compression:

Stored size: 882 Bytes

Contents

require 'action_view/helpers'

module RenuoCmsRails
  module CmsHelper
    def cms(path, default_value = nil, &block)
      content_path = RenuoCmsRails.config.content_path_generator.call(path)
      default_translation = capture_default_value(path, default_value, &block)
      content_tag(:div, default_translation, data: cms_attributes(content_path))
    end

    private

    # :reek:FeatureEnvy

    def cms_attributes(content_path)
      config = RenuoCmsRails.config
      cms_attributes = { content_path: content_path, api_host: config.api_host_with_protocol, api_key: config.api_key }
      cms_attributes[:private_api_key] = config.private_api_key if cms_admin?
      cms_attributes
    end

    def capture_default_value(path, default_value)
      return default_value if default_value
      return capture { yield } if block_given?

      I18n.t(path)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
renuo-cms-rails-0.1.0 lib/renuo_cms_rails/cms_helper.rb