Sha256: d480e988db6a44c4056ad71647b52809b8871a894d52b7b58c8c80289909f0b8

Contents?: true

Size: 838 Bytes

Versions: 11

Compression:

Stored size: 838 Bytes

Contents

module Innate
  module View
    module Etanni
      def self.call(action, string)
        etanni = View.compile(string){|s| Innate::Etanni.new(s) }
        html = etanni.result(action.binding, (action.view || action.method))
        return html, 'text/html'
      end
    end
  end

  class Etanni
    SEPARATOR = "E69t116A65n110N78i105S83e101P80a97R82a97T84o111R82"
    START = "\n<<#{SEPARATOR}.chomp\n"
    STOP = "\n#{SEPARATOR}\n"
    ADD = "_out_ << "

    def initialize(template)
      @template = template
      compile
    end

    def compile
      temp = @template.dup
      temp.gsub!(/<\?r\s+(.*?)\s+\?>/m, "#{STOP} \\1; #{ADD} #{START}")
      @compiled = "_out_ = #{START} #{temp} #{STOP} _out_"
    end

    def result(binding, filename = '<Etanni>')
      eval(@compiled, binding, filename).to_s.strip
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
manveru-innate-2009.05 lib/innate/view/etanni.rb
manveru-innate-2009.06.12 lib/innate/view/etanni.rb
manveru-innate-2009.06 lib/innate/view/etanni.rb
manveru-innate-2009.07 lib/innate/view/etanni.rb
rjspotter-innate-2009.06.29 lib/innate/view/etanni.rb
rjspotter-innate-2009.06.30 lib/innate/view/etanni.rb
rjspotter-innate-2009.06.31 lib/innate/view/etanni.rb
innate-2009.07 lib/innate/view/etanni.rb
innate-2009.05 lib/innate/view/etanni.rb
innate-2009.06.12 lib/innate/view/etanni.rb
innate-2009.06 lib/innate/view/etanni.rb