Module: ComfortableMexicanSofa::Tag::ClassMethods

Defined in:
lib/comfortable_mexican_sofa/tag.rb

Instance Method Summary collapse

Instance Method Details

#initialize_tag(blockable, tag_signature) ⇒ Object

Initializing tag object for a particular Tag type First capture group in the regex is the tag identifier Namespace is the string separated by a dot. So if identifier is: ‘sidebar.about’ namespace is: ‘sidebar’



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/comfortable_mexican_sofa/tag.rb', line 36

def initialize_tag(blockable, tag_signature)
  if match = tag_signature.match(regex_tag_signature)
    
    params = begin
      (CSV.parse_line(match[2].to_s, :col_sep => ':') || []).compact
    rescue
      []
    end.map{|p| p.gsub(/\\|'/) { |c| "\\#{c}" } }
    
    tag = self.new
    tag.blockable   = blockable
    tag.identifier  = match[1]
    tag.namespace   = (ns = tag.identifier.split('.')[0...-1].join('.')).blank?? nil : ns
    tag.params      = params
    tag
  end
end

#regex_tag_signature(identifier = nil) ⇒ Object

Regex that is used to match tags in the content Example:

/\{\{\s*?cms:page:(\w+)\}\}/

will match tags like these:

{{cms:page:my_identifier}}


28
29
30
# File 'lib/comfortable_mexican_sofa/tag.rb', line 28

def regex_tag_signature(identifier = nil)
  nil
end