# encoding: UTF-8 require "helper" require "fileutils" require "slim" require "haml" require "haml/template" module Keynote describe Inline do let(:presenter) { InlineUser.new(:view) } def clean_whitespace(str) str.gsub(/\s/, "") end class InlineUser < Keynote::Presenter extend Keynote::Inline inline :slim, :haml def simple_template erb # Here's some math: <%= 2 + 2 %> end def ivars @greetee = "world" erb # Hello <%= @greetee %>! end def locals_from_hash erb local: "H" # Local <%= local %> end def locals_from_binding local = "H" erb binding # Local <%= local %> end def method_calls erb # <%= locals_from_hash %> # <%= locals_from_binding %> end def error_handling erb # <% raise "UH OH" %> end def fix_indentation slim # .indented_slightly # - (2..4).each do |i| # ' #{i} times end def erb_escaping erb + # <%= "" %> erb # <%= "".html_safe %> end def slim_escaping slim + # = "" slim # = "".html_safe end def haml_escaping haml + # = "" haml # = "".html_safe end end before do Keynote::Inline::Cache.reset end it "should render a template" do presenter.simple_template.strip.must_equal "Here's some math: 4" end it "should see instance variables from the presenter" do presenter.ivars.strip.must_equal "Hello world!" end it "should see locals passed in as a hash" do presenter.locals_from_hash.strip.must_equal "Local H" end it "should see locals passed in as a binding" do presenter.locals_from_binding.strip.must_equal "Local H" end it "should be able to call other methods from the same object" do presenter.method_calls.strip.squeeze(" ").must_equal "Local H\nLocal H" end it "should handle errors relatively gracefully" do begin presenter.error_handling rescue => e end e.must_be_instance_of ActionView::Template::Error e.original_exception.must_be_instance_of RuntimeError e.original_exception.message.must_equal "UH OH" end it "should remove leading indentation" do presenter.fix_indentation.must_equal \ "