Sha256: af6eea294b19d8b44e0e7b4fe6ba5073e542f71f3bf8b4525f0a4100c07dc3fd

Contents?: true

Size: 983 Bytes

Versions: 2

Compression:

Stored size: 983 Bytes

Contents

require 'type_station/blocks'

module TypeStation
  module Helpers
    module Editable
      
      def ts_editable(model, key, user_options = {}, &block)
        content = ''
        options = { type: :text }.merge(user_options)

        presenter = model.try(key)

        if presenter.present?
          if presenter.value.is_a? Hash
            content += capture(OpenStruct.new(presenter.value), &block)
          else
            content += presenter.value
          end
        else
          content += capture(OpenStruct.new({}), &block)
        end

        if type_station_current_user
          klass ||= "TypeStation::Blocks::Editable#{options[:type].to_s.classify}".constantize
          klass.new(model, key, options).render(content)
        else
          if options[:stick].present?
            TypeStation::Blocks::Stickable.new(model, key, options).render(content)
          else
            content.html_safe
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
type_station-0.1.3 lib/type_station/helpers/editable.rb
type_station-0.1.1 lib/type_station/helpers/editable.rb