Class: DynamicText::LocalsSetter

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_text/locals_setter.rb

Instance Method Summary collapse

Instance Method Details

#get_dynamic_locals(resource, attribute, opts = {}) ⇒ Object

Set all locals for dynamic text view partial based on passed in arguments



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dynamic_text/locals_setter.rb', line 3

def get_dynamic_locals(resource, attribute, opts={})
  locals.merge!(opts).tap do |locals|
    locals[:resource] = resource
    locals[:attribute] = attribute
    locals[:resource_id] = resource.id
    locals[:value] = resource.send(attribute)
    locals[:resource_scope] ||= default_resource_scope
    locals[:placeholder] ||= default_placeholder
    locals[:resource_type] ||= default_resource_type
    locals[:resource_route] ||= default_resource_route
    locals[:dynamic_tag] ||= default_dynamic_tag
    locals[:style_class] ||= default_style_class
  end
end

#get_editable_locals(resource, attribute, opts = {}) ⇒ Object

Set all locals for editable text view partial based on passed in arguments



19
20
21
22
23
24
25
# File 'lib/dynamic_text/locals_setter.rb', line 19

def get_editable_locals(resource, attribute, opts={})
  get_dynamic_locals(resource, attribute, opts).tap do |locals|
    locals[:url] ||= default_url
    locals[:js_key] ||= default_js_key
    locals[:style_class] ||= default_style_class
  end
end