Sha256: 3d3d809154da382c923327dcb0cc37ab3d94dfcbdf399102d26ef6ac3c0e4e4d

Contents?: true

Size: 775 Bytes

Versions: 1

Compression:

Stored size: 775 Bytes

Contents

require "action_view"

module ActionviewPrecompiler
  class TemplateParser
    include ASTParser

    attr_reader :filename, :basename, :handler

    class FakeTemplate
      def type
        nil
      end
    end

    def initialize(filename)
      @filename = filename
      @basename = File.basename(filename)
      handler_ext = @basename.split(".").last
      @handler = ActionView::Template.handler_for_extension(handler_ext)
      @is_partial = !!@basename.start_with?("_")
    end

    def partial?
      @is_partial
    end

    def render_calls
      RenderParser.new(parsed).render_calls
    end

    def parsed
      @parsed ||= parse(compiled_source)
    end

    def compiled_source
      @handler.call(FakeTemplate.new, File.read(@filename))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
actionview_precompiler-0.2.0 lib/actionview_precompiler/template_parser.rb