Sha256: 046c974d290491465dadef427d79d719584964f9231a9d8c7171d1f046a302a8
Contents?: true
Size: 1.25 KB
Versions: 7
Compression:
Stored size: 1.25 KB
Contents
module Polyblock module ApplicationHelper def pb(name, tag = :div, tag_options={}) # Fetch or create Polyblock if name.is_a? Polyblock::Block pb = name pb_id = pb.id name = pb.name pb_exists = true else matches = Polyblock::Block.where :name => name pb_exists = matches.any? pb = if pb_exists then matches.first() else Polyblock::Block.new({:name => name}) end pb_id = if pb_exists then pb.id else Polyblock::Block.count + 1 end end # Build output tag pb.content ||= pb.present? ? pb.content : "<p>This block is content managed by Polyblock!<br />Edit \"#{name}\" to add content here.</p>" tag_options = tag_options.deep_merge({:id => "pb-#{pb_id}", :data => {:pbid => pb_id}}) tag_options[:contenteditable] = if !respond_to?(:can?) or can?(:manage, pb) then "true" else "false" end tag_options[:class] = (tag_options.has_key?(:class) ? "#{tag_options[:class]} ":"") + "polyblock" tag_options[:data][:pb_exists] = pb_exists content_tag(tag, pb.content, tag_options, false) end def simple_fields_for_polyblock(name, f) render :partial => "polyblock/simple_fields_for", :locals => {:f => f, :name => name} end end end
Version data entries
7 entries across 7 versions & 1 rubygems