Module: EditableContent::ApplicationHelper

Includes:
Mercury::Authentication
Defined in:
app/helpers/editable_content/application_helper.rb

Instance Method Summary collapse

Methods included from Mercury::Authentication

#can_edit?

Instance Method Details

#editable_content(name = nil, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/editable_content/application_helper.rb', line 5

def editable_content(name = nil, &block)
	contents = capture(&block)
	key = Digest::MD5.hexdigest(name ? name : contents)
	e = ::EditableContent::Editable.find_by_key(key) || ::EditableContent::Editable.create(:key => key, :text => contents)
	contents = e.text if !e.text.empty?

	if can_edit?
		return (:div, contents.html_safe, {:id => key, 'data-mercury' => 'full'}) 
	else
		return contents.html_safe
	end
end

#editable_image_tag(src, *args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/helpers/editable_content/application_helper.rb', line 18

def editable_image_tag(src, *args)
	options = args.extract_options!
	size = options[:size]
	if !size
		raise "The attribute :size must be specified on editable_image_tag"
	end

	key = Digest::MD5.hexdigest(src)
	if @editable = ::EditableContent::Editable.where(:key => key).first
		src = @editable.src
	else
		@editable = ::EditableContent::Editable.create(:key => key, :src => src)
	end

	if can_edit?
		image_tag(src, options.merge({:id => key, "data-size" => size, "data-mercury" => "image"}))
	else
		image_tag(src, options) 
	end
end