Class: BlockInstance

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/block_instance.rb

Instance Method Summary collapse

Instance Method Details

#display_versionObject



8
9
10
11
12
13
# File 'app/models/block_instance.rb', line 8

def display_version
  return "Current" if self.version==0
  return "Draft" if self.version==-1
  return "Autosave" if self.version==-2
  return self.version
end

#promptObject



15
16
17
18
19
20
21
22
23
# File 'app/models/block_instance.rb', line 15

def prompt
  body = self.block.body

  if body =~ /\[\[#{self.field_name}\:[^\:]+\:([^\:]+)\]\]/
    return $1
  else
    field_name.titleize
  end
end

#renderObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/block_instance.rb', line 25

def render
  return "[No block definition #{self.block_id}]" unless self.block

  self.block.body.gsub(/\[\[([^\:]+)\:([^\:]+)\:[^\]]+\]\]/) do
    if self.page
      bi = self.page.get_block_instances(self.instance_id, self.version, $1, self.block_id)
      return "[No block instances]" unless bi
     block_instance = bi.first
    else
      block_instance = self
    end

    if block_instance && block_instance.field_value
      if $2 == "friendly"
        block_instance.field_value.friendly_format 
      else
        block_instance.field_value
      end
    else
      "[Missing value '#{$1}']"
    end
  end
end