Module: Cmsify::Helpers

Defined in:
lib/cmsify/helpers.rb

Instance Method Summary collapse

Instance Method Details

#abc(opts = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/cmsify/helpers.rb', line 3

def abc(opts={})
  if opts[:slug]
    abc_slug(opts)
  elsif opts[:object] && opts[:field]
    abc_object(opts)
  end
end

#abc_object(opts) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/cmsify/helpers.rb', line 26

def abc_object(opts)
  object = opts[:object]
  field = opts[:field]

  if can_update?
    return "<div cmsify-text-edit text='#{object.try(field)}' object-model='#{object.class}' object-id='#{object.id}' field='#{field}'></div>".html_safe
  else
    return object.try(field)
  end
end

#abc_slug(opts) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/cmsify/helpers.rb', line 17

def abc_slug(opts)
  slug = opts[:slug]
  text_obj = ::Cmsify::Text.find_or_create_by(slug: slug) do |text|
    text.content = "Lorem ipsum dolor sit amet"
  end

  abc_object(object: text_obj, field: :content)
end

#can_update?Boolean

private

Returns:

  • (Boolean)


13
14
15
# File 'lib/cmsify/helpers.rb', line 13

def can_update?
  Cmsify.configuration.can_update && Cmsify.configuration.can_update.call(request)
end