Skip to content

Instantly share code, notes, and snippets.

@cognitom
Created March 6, 2012 04:48
Show Gist options
  • Select an option

  • Save cognitom/1983635 to your computer and use it in GitHub Desktop.

Select an option

Save cognitom/1983635 to your computer and use it in GitHub Desktop.
YinYangのテンプレートタグ用正規表現 for codeReview.cafe
re =
pend: /<!--\{end\}-->/
more: /<!--\{more\}-->/
pvar: /<!--\{(@[a-zA-Z0-9_\.\#>=\[\]]+|[a-zA-Z][a-zA-Z0-9_\.]*)(\|.*?)*\}-->/
ivar: /\#\{(@[a-zA-Z0-9_\.\#>=\[\]]+|[a-zA-Z][a-zA-Z0-9_\.]*)(\|.*?)*\}/
loop: /<!--\{[a-zA-Z][a-zA-Z0-9_\.]* in (@[a-zA-Z0-9_\.\#>=\[\]]+|[a-zA-Z][a-zA-Z0-9_\.]*)\}-->/
if value.match re.pend then @ignore = false; @parent
else if value.match re.more then @ignore = true; @
else unless @ignore
if value.match re.pvar then @_add 'child', new TemplateVar @, value.replace(/<!--{|}-->/g, ''), true
else if value.match re.ivar then @_add 'self', new TemplateVar @, value.replace /\#\{|\}/g, ''
else if value.match re.loop then @_add 'child', new TemplateLoop @, value.replace /<!--{|}-->/g, ''
else @_add 'self', new TemplateText @, value
else @
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment