Module: ComfortableMexicanSofa::Tag::ClassMethods

Defined in:
lib/comfortable_mexican_sofa/tag.rb

Instance Method Summary collapse

Instance Method Details

#initialize_tag(page, tag_signature) ⇒ Object

Initializing tag object for a particular Tag type First capture group in the regex is the tag identifier



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/comfortable_mexican_sofa/tag.rb', line 32

def initialize_tag(page, tag_signature)
  if match = tag_signature.match(regex_tag_signature)
    
    params = begin
      (CSV.parse_line(match[2].to_s, (RUBY_VERSION < '1.9.2' ? ':' : {:col_sep => ':'})) || []).compact
    rescue
      []
    end.map{|p| p.gsub(/\\|'/) { |c| "\\#{c}" } }
    
    tag = self.new
    tag.page        = page
    tag.identifier  = match[1]
    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}}


26
27
28
# File 'lib/comfortable_mexican_sofa/tag.rb', line 26

def regex_tag_signature(identifier = nil)
  nil
end