Module: HalloRails::ViewHelpers

Defined in:
lib/hallo_rails.rb

Instance Method Summary collapse

Instance Method Details

#editable(object, method, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hallo_rails.rb', line 19

def editable object, method, options = {}
  object_name = object.class.to_s.underscore
  options.reverse_merge! tag: :div,
                         content: object.send(method).try(:html_safe),
                         update_url: "/#{object_name.pluralize}/#{object.to_param}",
                         blank_text: "<i>Click to Edit</i>".html_safe

  options[:content] = sanitize(options[:content]) if options[:sanitize]

  is_editable = !options.has_key?(:editable) || options[:editable]
   = if is_editable
    {update_url: options[:update_url],
    model: object_name,
    method: method.to_s,
    editable_options: options[:hallo_options],
    editable_plugins: options[:plugins] }.merge(options[:params] || {})
  end

  ( :div, class: 'editable_wrapper', style: options[:inline] ? 'display:inline-block' : nil ) do
     options[:tag], options[:content].present? ? options[:content] : options[:blank_text],
                  class: "#{'editable' if is_editable}",
                  id: "#{object_name}_#{method.to_s}",
                  data: 
  end
end

#form_editable(object, method, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hallo_rails.rb', line 46

def form_editable object, method, options = {}
  object_name = object.class.to_s.underscore
  options.reverse_merge! tag: :div,
                         content: object.send(method).try(:html_safe),
                         blank_text: "<i>Click to Edit</i>".html_safe
  options[:content] = sanitize(options[:content]) if options[:sanitize]
  ( :div, class: 'editable_wrapper', style: options[:inline] ? 'display:inline-block' : nil) do
    ( options[:tag], options[:content].present? ? options[:content] : options[:blank_text],
                                  class: 'form_editable',
                                  data: { model: object_name,
                                          method: method.to_s,
                                         editable_options: options[:hallo_options],
                                         editable_plugins: options[:plugins] }.merge(options[:params] || {})) +
    text_area_tag( "#{object_name}[#{method}]", options[:content], style: "display:none" )
  end
end