Sha256: 7e581849cf9e48a55629dc2dfd70789795dadf581f8b1a431c60c258e534fd95

Contents?: true

Size: 832 Bytes

Versions: 1

Compression:

Stored size: 832 Bytes

Contents

require "action_view"

module ActionviewPrecompiler
  class TemplateParser
    attr_reader :filename, :basename, :handler

    class FakeTemplate
      def identifier
        "fake_template"
      end

      def type
        nil
      end

      def format
        nil
      end
    end

    def initialize(filename)
      @filename = filename
      @basename = File.basename(filename)
      handler_ext = @basename.split(".").last
      @handler = HANDLERS_FOR_EXTENSION[handler_ext]
    end

    def render_calls
      src = File.read(@filename)
      if src.include?("render")
        compiled_source = @handler.call(FakeTemplate.new, File.read(@filename))
        compiled_source = "def _template; #{compiled_source}; end"
        RenderParser.new(compiled_source).render_calls
      else
        []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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