Class: ComfortableMexicanSofa::Tag::Partial

Inherits:
Object
  • Object
show all
Includes:
ComfortableMexicanSofa::Tag
Defined in:
lib/comfortable_mexican_sofa/tags/partial.rb

Constant Summary

Constants included from ComfortableMexicanSofa::Tag

IDENTIFIER_REGEX, TOKENIZER_REGEX

Instance Attribute Summary

Attributes included from ComfortableMexicanSofa::Tag

#blockable, #identifier, #namespace, #params, #parent

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.regex_tag_signature(identifier = nil) ⇒ Object



4
5
6
7
# File 'lib/comfortable_mexican_sofa/tags/partial.rb', line 4

def self.regex_tag_signature(identifier = nil)
  identifier ||= /[\w\/\-]+/
  /\{\{\s*cms:partial:(#{identifier}):?(.*?)\s*\}\}/
end

Instance Method Details

#contentObject



9
10
11
12
# File 'lib/comfortable_mexican_sofa/tags/partial.rb', line 9

def content
  ps = params.collect_with_index{|p, i| ":param_#{i+1} => '#{p}'"}.join(', ')
  "<%= render :partial => '#{identifier}'#{ps.blank?? nil : ", :locals => {#{ps}}"} %>"
end

#renderObject



14
15
16
17
18
19
20
21
# File 'lib/comfortable_mexican_sofa/tags/partial.rb', line 14

def render
  whitelist = ComfortableMexicanSofa.config.allowed_partials
  if whitelist.is_a?(Array)
    content if whitelist.member?(identifier)
  else
    content
  end
end