# -*- encoding : utf-8 -*-
format do
def wrap_item item, args={}
item #no wrap in base
end
view :core do |args|
pointer_items args[:item], joint=', '
end
def pointer_items itemview=nil, joint=' '
args = { :view => ( itemview || (@inclusion_opts && @inclusion_opts[:view]) || default_item_view ) }
if type = card.item_type
args[:type] = type
end
card.item_cards.map do |icard|
wrap_item process_inclusion(icard, args.clone), args
end.join joint
end
end
format :html do
view :core do |args|
%{
}
end
view :select do |args|
options = [["-- Select --",""]] + card.options.map{|x| [x.name,x.name]}
select_tag("pointer_select", options_for_select(options, card.item_names.first), :class=>'pointer-select')
end
def pointer_option_description option
pod_name = card.rule(:options_label) || 'description'
dcard = Card[ "#{option.name}+#{pod_name}" ]
if dcard and dcard.ok? :read
subformat(dcard).render_core
end
end
def wrap_item item, args
%{
#{item}
}
end
end
format :css do
view :titled do |args|
%(#{major_comment "STYLE GROUP: \"#{card.name}\"", '='}#{ _render_core })
end
view :content, :core
view :core do |args|
card.item_cards.map do |item|
process_inclusion item, :view=>(params[:item] || :content)
end.join "\n\n"
end
end
format :data do
view :core do |args|
card.item_cards.map do |c|
process_inclusion c
end
end
end
event :standardize_items, :before=>:approve, :on=>:save do
if updates.for? :content
self.content = item_names(:context=>:raw).map { |name| "[[#{name}]]" }.join "\n"
end
end
def item_cards args={}
if args[:complete]
#warn "item_card[#{args.inspect}], :complete"
Card::Query.new({:referred_to_by=>name}.merge(args)).run
else
#warn "item_card[#{inspect}], :complete"
item_names(args).map do |name|
new_args = args[:type] ? { :type=>args[:type] } : {}
Card.fetch name, :new=>new_args
end.compact # compact? can't be nil, right?
end
end
def item_names args={}
context = args[:context] || self.cardname
self.raw_content.split(/\n+/).map do |line|
item_name = line.gsub /\[\[|\]\]/, ''
if context == :raw
item_name
else
item_name.to_name.to_absolute context
end
end
end
def item_ids args={}
item_names(args).map do |name|
Card.fetch_id name
end.compact
end
def item_type
opt = options_card
if !opt or opt==self #fixme, need better recursion prevention
nil
else
opt.item_type
end
end
def items= array
self.content=''
array.each { |i| self << i }
save!
end
def << item
newname = case item
when Card ; item.name
when Integer ; c = Card[item] and c.name
else item
end
add_item newname
end
def add_item newname
inames = item_names
unless inames.include? newname
self.content="[[#{(inames << newname).reject(&:blank?)*"]]\n[["}]]"
end
end
def drop_item name
inames = item_names
if inames.include? name
inames = inames.reject{|n|n==name}
self.content= inames.empty? ? '' : "[[#{inames * "]]\n[["}]]"
end
end
def options_card
self.rule_card :options
end
def options
if oc = options_card
oc.item_cards :default_limit=>50, :context=>name
else
Card.search :sort=>'alpha', :limit=>50
end
end