Sha256: 89d9d5ffa8ce74b49925bca5bba37e4ba92e65907bb7cc812b01fae2657b0e0b

Contents?: true

Size: 1.43 KB

Versions: 20

Compression:

Stored size: 1.43 KB

Contents

require 'ripper'

module ExpressTemplates
  module Template
    class Handler
      def self.call(template)
        new.call(template)
      end

      def call(template)
        # call ripper stuff method

        warn_contains_logic("(#{ExpressTemplates.compile(template)}).html_safe")  # pass the source code
        # returns a string to be eval'd
        "(#{ExpressTemplates.compile(template)}).html_safe"
      end

      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
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
express_admin-1.6.3 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.11.1 lib/express_templates/template/handler.rb
express_admin-1.6.2 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_admin-1.6.1 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.11.0 lib/express_templates/template/handler.rb
express_admin-1.6.0 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.10.1 lib/express_templates/template/handler.rb
express_admin-1.5.0 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_admin-1.4.11 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_admin-1.4.10 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_admin-1.4.9 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.9.8 lib/express_templates/template/handler.rb
express_admin-1.4.8 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.9.7 lib/express_templates/template/handler.rb
express_admin-1.4.7 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.9.6 lib/express_templates/template/handler.rb
express_admin-1.4.6 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.9.5 lib/express_templates/template/handler.rb
express_admin-1.4.5 vendor/gems/express_templates/lib/express_templates/template/handler.rb
express_templates-0.9.4 lib/express_templates/template/handler.rb