Changeset 96
- Timestamp:
- 12/14/2006 14:52:37 (2 years ago)
- Location:
- trunk
- Files:
-
- 4 modified
-
lib/markaby/kernel_method.rb (modified) (1 diff)
-
lib/markaby/rails.rb (modified) (3 diffs)
-
lib/markaby/template.rb (modified) (1 diff)
-
test/rails_test.rb (modified) (3 diffs)
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. 1 2 module Kernel 2 def mab(*args, &block) # :nodoc: 3 # Shortcut for creating a quick block of Markaby. 4 def mab(*args, &block) 3 5 Markaby::Builder.new(*args, &block).to_s 4 6 end -
trunk/lib/markaby/rails.rb
r95 r96 1 module 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 12 end 13 1 14 module Markaby 2 15 … … 12 25 end 13 26 14 class ActionViewTemplateHandler 27 class ActionViewTemplateHandler # :nodoc: 15 28 def initialize(action_view) 16 29 @action_view = action_view 17 30 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) 20 35 end 21 36 end 22 37 23 class FauxErbout < ::Builder::BlankSlate 38 class FauxErbout < ::Builder::BlankSlate # :nodoc: 24 39 def initialize(builder) 25 40 @builder = builder … … 33 48 end 34 49 35 class Builder 50 class Builder # :nodoc: 36 51 def flash(*args) 37 52 @helpers.controller.send(:flash, *args) -
trunk/lib/markaby/template.rb
r1 r96 1 1 module Markaby 2 2 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 5 8 end 9 6 10 def render(*args) 7 11 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 9 19 return output.to_s 10 20 end 21 11 22 end 12 23 end -
trunk/test/rails_test.rb
r95 r96 1 #2 # run `rake test:plugins PLUGIN=markaby` from your RAILS_ROOT3 #4 1 require File.join(File.dirname(__FILE__), 'rails', 'test_preamble') 5 2 … … 17 14 end 18 15 16 def broken 17 end 18 19 19 def partial_rendering 20 20 render :partial => 'monkeys', :locals => @@locals … … 84 84 assert_select 'p', 'Hello World' 85 85 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 86 94 end