Sha256: 158f6cc2f293efbf946fb4cb525dc59c79dfbc5377fd2f1ebda18cabd0ef65a5

Contents?: true

Size: 1.35 KB

Versions: 73

Compression:

Stored size: 1.35 KB

Contents

module Effective
  module FormInputs
    class StaticField < Effective::FormInput

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

      def feedback_options
        false
      end

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

        content_tag(:p, content, options[:input].except(:readonly, :required, :value).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

73 entries across 73 versions & 1 rubygems

Version Path
effective_bootstrap-0.4.4 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.4.3 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.4.2 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.4.1 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.4.0 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.22 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.21 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.20 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.19 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.18 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.17 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.16 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.15 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.14 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.13 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.12 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.11 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.10 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.9 app/models/effective/form_inputs/static_field.rb
effective_bootstrap-0.3.8 app/models/effective/form_inputs/static_field.rb