Module: Kablam::KablamHelper

Defined in:
lib/kablam/kablam_helper.rb

Instance Method Summary collapse

Instance Method Details

#disable_testObject

TODO: Complete this 🤷



35
36
37
# File 'lib/kablam/kablam_helper.rb', line 35

def disable_test
  'console.log("test")'
end

#hide(model) ⇒ Object



44
45
46
# File 'lib/kablam/kablam_helper.rb', line 44

def hide(model)
  raw "document.getElementById('#{model.html_id}').style.display = 'none'"
end

#kablam_after(field, &block) ⇒ Object



28
29
30
31
32
# File 'lib/kablam/kablam_helper.rb', line 28

def kablam_after(field, &block)
  @kablam_after = {} if @kablam_after.blank?
  @kablam_after[field] = block
  nil
end

#kablam_before(field, &block) ⇒ Object



22
23
24
25
26
# File 'lib/kablam/kablam_helper.rb', line 22

def kablam_before(field, &block)
  @kablam_before = {} if @kablam_before.blank?
  @kablam_before[field] = block
  nil
end

#kablam_form_for(obj, options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/kablam/kablam_helper.rb', line 12

def kablam_form_for(obj, options = {}, &block)
  # @kablam_content = {}
  options[:obj] = obj
  # options[:block] = block_given? ? block : ""
  render layout: "kablam_forms/kablam_form", locals: options do |f|
    capture(f, &block) if block_given?
  end
  # nil
end

#render_flash(partial: 'application/flash_notice', **locals) ⇒ Object



48
49
50
51
# File 'lib/kablam/kablam_helper.rb', line 48

def render_flash(partial: 'application/flash_notice', **locals)
  html = j render partial: partial, locals: locals
  raw "document.getElementById('flash').innerHTML = '#{html}'"
end

#replace_with(id, content) ⇒ Object



3
4
# File 'lib/kablam/kablam_helper.rb', line 3

def replace_with(id, content)
end

#show(model) ⇒ Object

TODO: Use Rails UJS setData/expando to stash original state 😎



40
41
42
# File 'lib/kablam/kablam_helper.rb', line 40

def show(model)
  raw "document.getElementById('#{model.html_id}').style.display = 'table-row'"
end

#undo_destroy_path(model) ⇒ Object



6
7
8
9
10
# File 'lib/kablam/kablam_helper.rb', line 6

def undo_destroy_path(model)
  name = model.model_name.singular
  params = [[name, { destroyed_at: nil }]].to_h
  polymorphic_path("data_undo", params)
end