Module: ComfortableMexicanSofa::Tag::InstanceMethods

Defined in:
lib/comfortable_mexican_sofa/tag.rb

Instance Method Summary collapse

Instance Method Details

#ancestorsObject

Ancestors of this tag constructed during rendering process.



47
48
49
50
51
# File 'lib/comfortable_mexican_sofa/tag.rb', line 47

def ancestors
  node, nodes = self, []
  nodes << node = node.parent while node.parent
  nodes
end

#blockObject

Find or initialize Cms::Block object



78
79
80
# File 'lib/comfortable_mexican_sofa/tag.rb', line 78

def block
  page.blocks.detect{|b| b.label == self.label.to_s} || page.blocks.build(:label => self.label.to_s)
end

#contentObject

Content that is accociated with Tag instance.



61
62
63
# File 'lib/comfortable_mexican_sofa/tag.rb', line 61

def content
  nil
end

#identifierObject

String indentifier of the tag



42
43
44
# File 'lib/comfortable_mexican_sofa/tag.rb', line 42

def identifier
  "#{self.class.to_s.demodulize.underscore}_#{self.label}"
end

#is_cms_block?Boolean

Checks if this tag is using Cms::Block

Returns:

  • (Boolean)


88
89
90
# File 'lib/comfortable_mexican_sofa/tag.rb', line 88

def is_cms_block?
  %w(page field).member?(self.class.to_s.demodulize.underscore.split(/_/).first)
end

#record_idObject

Used in displaying form elements for Cms::Block



93
94
95
# File 'lib/comfortable_mexican_sofa/tag.rb', line 93

def record_id
  block.id
end

#regex_tag_signatureObject

Regex that is used to identify instance of the tag Example:

/<\{\s*?cms:page:tag_label\}/


56
57
58
# File 'lib/comfortable_mexican_sofa/tag.rb', line 56

def regex_tag_signature
  self.class.regex_tag_signature(label)
end

#renderObject

Content that is used during page rendering. Outputting existing content as a default.



67
68
69
70
71
72
73
74
75
# File 'lib/comfortable_mexican_sofa/tag.rb', line 67

def render
  # cleaning content from possible irb stuff. Partial and Helper tags are OK.
  if !ComfortableMexicanSofa.config.allow_irb && 
      ![ComfortableMexicanSofa::Tag::Partial, ComfortableMexicanSofa::Tag::Helper].member?(self.class)
    content.to_s.gsub('<%', '&lt;%').gsub('%>', '%&gt;')
  else
    content.to_s
  end
end

#snippetObject

Find or initialize Cms::Snippet object



83
84
85
# File 'lib/comfortable_mexican_sofa/tag.rb', line 83

def snippet
  page.site.snippets.detect{|s| s.slug == self.label.to_s} || page.site.snippets.build(:slug => self.label.to_s)
end