Sha256: ccdd8803c923720b37f3a5616a6391ba138f9a840053577959c42a6c839f9d0f

Contents?: true

Size: 1.02 KB

Versions: 6

Compression:

Stored size: 1.02 KB

Contents

module Innate
  module View
    module Etanni
      def self.call(action, string)
        etanni = View.compile(string) do |str|
          filename = action.view || action.method
          Innate::Etanni.new(str, filename)
        end
        html = etanni.result(action.instance)
        return html, Response.mime_type
      end
    end
  end

  class Etanni
    SEPARATOR = "E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82"
    CHOMP = "<<#{SEPARATOR}.chomp!"
    START = "\n_out_ << #{CHOMP}\n"
    STOP = "\n#{SEPARATOR}\n"
    REPLACEMENT = "#{STOP}\\1#{START}"

    def initialize(template, filename = '<Etanni>')
      @template = template
      @filename = filename
      compile
    end

    def compile(filename = @filename)
      temp = @template.strip
      temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, REPLACEMENT)
      @compiled = eval("Proc.new{ _out_ = [#{CHOMP}]\n#{temp}#{STOP}_out_.join }",
        nil, @filename)
    end

    def result(instance, filename = @filename)
      instance.instance_eval(&@compiled)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
innate-2012.03 lib/innate/view/etanni.rb
innate-2011.12 lib/innate/view/etanni.rb
innate-2011.10 lib/innate/view/etanni.rb
innate-2011.04 lib/innate/view/etanni.rb
innate-2011.01 lib/innate/view/etanni.rb
innate-2010.07 lib/innate/view/etanni.rb