Sha256: 4a27dd4cd2eb0744c6e9ea6874589736fb80dbc6b12f510ffcd3ea900c5c7f96

Contents?: true

Size: 1.31 KB

Versions: 113

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Effective
  module FormInputs
    class StaticField < Effective::FormInput

      def input_html_options
        { class: 'form-control-plaintext', readonly: false, id: tag_id }
      end

      def feedback_options
        false
      end

      def build_input(&block)
        content = if block_given?
          capture(&block)
        elsif resource_path
          link_to(value, resource_path, title: value.to_s)
        else
          value
        end

        content_tag(:p, content, options[:input].except(:readonly, :required).merge(id: tag_id))
      end

      def resource_path
        # I don't want to hardcode effective_resources as a dependency of this gem. But it's so useful...
        return false unless defined?(EffectiveResources)

        return false unless value.kind_of?(ActiveRecord::Base)

        @_resource_path ||= (
          Effective::Resource.new(value, namespace: @template.controller_path.split('/').first).action_path(:edit) ||
          Effective::Resource.new(@template.controller_path).action_path(:edit, value) ||
          Effective::Resource.new(value, namespace: @template.controller_path.split('/').first).action_path(:show) ||
          Effective::Resource.new(@template.controller_path).action_path(:show, value)
        )
      end

    end
  end
end

Version data entries

113 entries across 113 versions & 1 rubygems

Version Path
effective_bootstrap-1.19.10 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.9 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.8 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.7 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.6 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.5 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.4 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.3 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.2 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.1 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.19.0 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.18.7 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.18.4 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.18.3 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.18.2 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.18.1 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.18.0 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.17.6 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.17.5 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-1.17.4 app/models/effective/form_inputs/static_field.rb