Sha256: 2e73a9a6568235f4750c2fc4aaec96bb34caa3a3d9a2f170373b5647cc6756ef

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

require "action_view"

module ActionviewPrecompiler
  class TemplateParser
    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 ||= RubyVM::AbstractSyntaxTree.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.1.0 lib/actionview_precompiler/template_parser.rb