Module: InplaceEditingHelper
- Defined in:
- app/helpers/inplace_editing_helper.rb
Defined Under Namespace
Instance Method Summary collapse
- #content_tag(*args) ⇒ Object
- #editor_locals(localized_object, property, place_holder = nil, default_value = nil, label = nil) ⇒ Object
- #element_editor(localized_object, property, place_holder = nil, label = nil) ⇒ Object
- #empty_content_tag(*args) ⇒ Object
- #image_bg_editor(localized_object, property, container_tag, attrs) ⇒ Object
- #image_editor(localized_object, property, place_holder = nil, default_value = nil, tag_attributes = { }) ⇒ Object
- #markdown(text, placeholder = '[texto aqui]', options = nil) ⇒ Object
- #only_valid_editor(localized_object, property) ⇒ Object
- #optional_editor(localized_object, property) ⇒ Object
- #should_show?(optional_string_value) ⇒ Boolean
- #string_editor(localized_object, property, place_holder = nil) ⇒ Object
- #text_editor(localized_object, property, place_holder = nil) ⇒ Object
Instance Method Details
#content_tag(*args) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/inplace_editing_helper.rb', line 91 def content_tag(*args) if block_given? tag = Tag.new(args[0], args[1] || {}) old_buf = @output_buffer @output_buffer = ActionView::OutputBuffer.new value = yield(tag) content = tag.render(@output_buffer.presence || value) @output_buffer = old_buf content else super end end |
#editor_locals(localized_object, property, place_holder = nil, default_value = nil, label = nil) ⇒ Object
44 45 46 |
# File 'app/helpers/inplace_editing_helper.rb', line 44 def editor_locals(localized_object, property, place_holder = nil, default_value = nil, label = nil) { localized_object: localized_object, property: property, place_holder: place_holder, default_value: default_value, label: label } end |
#element_editor(localized_object, property, place_holder = nil, label = nil) ⇒ Object
38 39 40 41 42 |
# File 'app/helpers/inplace_editing_helper.rb', line 38 def element_editor(localized_object, property, place_holder = nil, label = nil) render layout: 'inplace_editing/element', :locals => editor_locals(localized_object, property, place_holder, nil, label) do |locals| yield locals end end |
#empty_content_tag(*args) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/helpers/inplace_editing_helper.rb', line 105 def empty_content_tag(*args) if block_given? tag = EmptyTag.new(args[0], args[1] || {}) old_buf = @output_buffer @output_buffer = ActionView::OutputBuffer.new yield(tag) content = tag.render(@output_buffer.presence) @output_buffer = old_buf content else super end end |
#image_bg_editor(localized_object, property, container_tag, attrs) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/inplace_editing_helper.rb', line 48 def image_bg_editor(localized_object, property, container_tag, attrs) if localized_object[property] image = localized_object.public_send(property) image = image.url if image.respond_to?(:url) attrs[:style] = 'background-image:url("' + image + '");' + (attrs[:style] ? attrs[:style] : '') end locals = editor_locals(localized_object, property) locals[:tag] = container_tag locals[:attrs] = attrs render layout: 'inplace_editing/image_bg', :locals => locals do |view_locals| yield view_locals end end |
#image_editor(localized_object, property, place_holder = nil, default_value = nil, tag_attributes = { }) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/helpers/inplace_editing_helper.rb', line 26 def image_editor(localized_object, property, place_holder = nil, default_value = nil, tag_attributes = { }) locals = editor_locals(localized_object, property, place_holder, default_value) image_src = default_value if localized_object[property] image_src = localized_object.public_send(property) image_src = image_src.url if image_src.respond_to?(:url) end locals[:image_src] = image_src locals[:attrs] = tag_attributes render partial: 'inplace_editing/image', :locals => locals end |
#markdown(text, placeholder = '[texto aqui]', options = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/helpers/inplace_editing_helper.rb', line 63 def markdown(text, placeholder = '[texto aqui]', = nil) return placeholder if !text = { filter_html: false, hard_wrap: true, link_attributes: { rel: 'nofollow', target: "_blank" }, space_after_headers: true, fenced_code_blocks: true, tables: true } if = .merge() else = end extensions = { autolink: true, superscript: true, disable_indented_code_blocks: true } renderer = Redcarpet::Render::HTML.new() markdown = Redcarpet::Markdown.new(renderer, extensions) markdown.render(text).html_safe end |
#only_valid_editor(localized_object, property) ⇒ Object
12 13 14 15 16 |
# File 'app/helpers/inplace_editing_helper.rb', line 12 def only_valid_editor(localized_object, property) render :layout => 'inplace_editing/only_valid', :locals => editor_locals(localized_object, property) do |locals| yield locals end end |
#optional_editor(localized_object, property) ⇒ Object
6 7 8 9 10 |
# File 'app/helpers/inplace_editing_helper.rb', line 6 def optional_editor(localized_object, property) render :layout => 'inplace_editing/optional', :locals => editor_locals(localized_object, property) do |locals| yield locals end end |
#should_show?(optional_string_value) ⇒ Boolean
2 3 4 |
# File 'app/helpers/inplace_editing_helper.rb', line 2 def should_show?(optional_string_value) @can_edit || !optional_string_value.blank? end |
#string_editor(localized_object, property, place_holder = nil) ⇒ Object
22 23 24 |
# File 'app/helpers/inplace_editing_helper.rb', line 22 def string_editor(localized_object, property, place_holder = nil) render partial: 'inplace_editing/string', :locals => editor_locals(localized_object, property, place_holder) end |
#text_editor(localized_object, property, place_holder = nil) ⇒ Object
18 19 20 |
# File 'app/helpers/inplace_editing_helper.rb', line 18 def text_editor(localized_object, property, place_holder = nil) render partial: 'inplace_editing/text', :locals => editor_locals(localized_object, property, place_holder) end |