Class: ExpressTemplates::Template::Handler
- Inherits:
-
Object
- Object
- ExpressTemplates::Template::Handler
- Defined in:
- lib/express_templates/template/handler.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.call(template) ⇒ Object
6 7 8 |
# File 'lib/express_templates/template/handler.rb', line 6 def self.call(template) new.call(template) end |
Instance Method Details
#call(template) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/express_templates/template/handler.rb', line 10 def call(template) # returns a string to be eval'd source = "(#{ExpressTemplates.compile(template)}).html_safe" warn_contains_logic(source) if ENV['NO_TEMPLATE_WARN'].nil? # pass the source code source end |
#warn_contains_logic(compiled_template) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/express_templates/template/handler.rb', line 17 def warn_contains_logic(compiled_template) keywords = %w(if until unless case for do loop while) # array of conditional keywords tokens = [] if Ripper.lex(compiled_template).select do |element| # since it outputs an array [[line, col], type, token] element[1]==:on_kw # type must match ':on_kw' type (type is keyword) end.each { |match| tokens.push(match) if keywords.include? match[2] } # check if token is in given /keyword/ array, then push to new array match tokens.each do |first| warn "PAGE TEMPLATE INCLUDES #{first[2]} STATEMENT AT LINE #{first[0][0]}: #{first}\n#{compiled_template}" # warn on first occurence of conditional logic end end end |