Changeset 96

Show
Ignore:
Timestamp:
12/14/2006 14:52:37 (2 years ago)
Author:
tec
Message:
  • lib/markaby/template.rb: rework Template so errors can include line number
  • lib/markaby/rails.rb: hack AV::B to pass the template path to the handler
  • test/rails_test.rb: test that a TemplateError? includes the correct line number
  • test/rails/markaby/broken.mab: template for the above test
Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/markaby/kernel_method.rb

    r86 r96  
     1# You'll need to <tt>require 'markaby/kernel_method'</tt> for this. 
    12module Kernel 
    2   def mab(*args, &block) # :nodoc: 
     3  # Shortcut for creating a quick block of Markaby. 
     4  def mab(*args, &block) 
    35    Markaby::Builder.new(*args, &block).to_s 
    46  end 
  • trunk/lib/markaby/rails.rb

    r95 r96  
     1module ActionView # :nodoc: 
     2  class Base # :nodoc: 
     3    def render_template(template_extension, template, file_path = nil, local_assigns = {}) 
     4      if handler = @@template_handlers[template_extension] 
     5        template ||= read_template_file(file_path, template_extension) 
     6        handler.new(self).render(template, local_assigns, file_path) 
     7      else 
     8        compile_and_render_template(template_extension, template, file_path, local_assigns) 
     9      end 
     10    end 
     11  end 
     12end 
     13 
    114module Markaby 
    215 
     
    1225  end 
    1326 
    14   class ActionViewTemplateHandler 
     27  class ActionViewTemplateHandler # :nodoc: 
    1528    def initialize(action_view) 
    1629      @action_view = action_view 
    1730    end 
    18     def render(template, local_assigns = {}) 
    19       Template.new(template).render(@action_view.assigns.merge(local_assigns), @action_view) 
     31    def render(template, local_assigns, file_path) 
     32      template = Template.new(template) 
     33      template.path = file_path 
     34      template.render(@action_view.assigns.merge(local_assigns), @action_view) 
    2035    end 
    2136  end 
    2237 
    23   class FauxErbout < ::Builder::BlankSlate 
     38  class FauxErbout < ::Builder::BlankSlate # :nodoc: 
    2439    def initialize(builder) 
    2540      @builder = builder 
     
    3348  end 
    3449   
    35   class Builder 
     50  class Builder # :nodoc: 
    3651    def flash(*args) 
    3752      @helpers.controller.send(:flash, *args) 
  • trunk/lib/markaby/template.rb

    r1 r96  
    11module Markaby 
    22  class Template 
    3     def initialize(template) 
    4       @template = template       
     3 
     4    attr_accessor :source, :path 
     5     
     6    def initialize(source) 
     7      @source = source.to_s 
    58    end 
     9 
    610    def render(*args) 
    711      output = Builder.new(*args) 
    8       output.instance_eval @template 
     12 
     13      if path.nil? 
     14        output.instance_eval source 
     15      else 
     16        output.instance_eval source, path 
     17      end 
     18       
    919      return output.to_s 
    1020    end 
     21 
    1122  end 
    1223end 
  • trunk/test/rails_test.rb

    r95 r96  
    1 # 
    2 # run `rake test:plugins PLUGIN=markaby` from your RAILS_ROOT 
    3 # 
    41require File.join(File.dirname(__FILE__), 'rails', 'test_preamble') 
    52 
     
    1714  end 
    1815 
     16  def broken 
     17  end 
     18   
    1919  def partial_rendering 
    2020    render :partial => 'monkeys', :locals => @@locals 
     
    8484    assert_select 'p', 'Hello World' 
    8585  end 
     86   
     87  def test_template_error_has_correct_line_number 
     88    begin 
     89      process :broken 
     90    rescue ActionView::TemplateError => error 
     91      assert_equal 5, error.line_number.to_i 
     92    end 
     93  end 
    8694end