Class: Effective::FormInputs::StaticField

Inherits:
Effective::FormInput show all
Defined in:
app/models/effective/form_inputs/static_field.rb

Constant Summary

Constants inherited from Effective::FormInput

Effective::FormInput::BLANK, Effective::FormInput::EXCLUSIVE_CLASS_PREFIXES, Effective::FormInput::EXCLUSIVE_CLASS_SUFFIXES

Instance Attribute Summary

Attributes inherited from Effective::FormInput

#name, #options

Instance Method Summary collapse

Methods inherited from Effective::FormInput

#hint_options, #initialize, #input_group_options, #input_js_options, #label_options, #to_html, #wrapper_options

Constructor Details

This class inherits a constructor from Effective::FormInput

Instance Method Details

#build_input(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/effective/form_inputs/static_field.rb', line 13

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

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

#feedback_optionsObject



9
10
11
# File 'app/models/effective/form_inputs/static_field.rb', line 9

def feedback_options
  false
end

#input_html_optionsObject



5
6
7
# File 'app/models/effective/form_inputs/static_field.rb', line 5

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

#resource_pathObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/effective/form_inputs/static_field.rb', line 27

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