Sha256: 4b78a33922e33578aa44d4c07b5103ad42d9a78a6bae94c59b1180a7ae3ebce1
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
polyblock-0.1.2 | app/helpers/polyblock/application_helper.rb |
polyblock-0.0.7 | app/helpers/polyblock/application_helper.rb |