public
Description: Markaby patched to run on rails 2.0.2
Homepage: http://code.whytheluckystiff.net/markaby/
Clone URL: git://github.com/giraffesoft/markaby.git
 * lib/markaby/rails.rb: give helpers access to assigns (ticket:51); new 
 namespace
 * lib/markaby/template.rb: allow different builder classes
 * test/rails_test.rb: test that helpers have access to assigns
 * test/rails/test_helper.rb: a helper to test with
 * test/rails/test_preamble.rb: make sure the helpers can be loaded
 * test/rails/markaby/index.mab: use the helper
 * init.rb: new namespace


git-svn-id: http://code.whytheluckystiff.net/svn/markaby/trunk@104 
2c81c6a9-7b7e-da11-ae0f-006097933fb5
tec (author)
Sun Feb 04 10:07:32 -0800 2007
commit  9c2e501f386d305cd1e6e8181722e0769951bb33
tree    f8f123e5991e425927accad4623775b4b961d061
parent  2510c86566970873840ba0a1dc3aa136d81ed4a6
...
3
4
5
6
 
7
8
 
...
3
4
5
 
6
7
 
8
0
@@ -3,6 +3,6 @@ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
0
 require 'markaby'
0
 require 'markaby/rails'
0
 
0
-ActionView::Base::register_template_handler 'mab', Markaby::ActionViewTemplateHandler
0
+ActionView::Base::register_template_handler 'mab', Markaby::Rails::ActionViewTemplateHandler
0
 
0
-ActionController::Base.send :include, Markaby::ActionControllerHelpers
0
+ActionController::Base.send :include, Markaby::Rails::ActionControllerHelpers
...
12
13
14
15
16
17
18
19
20
21
22
23
 
 
 
 
 
 
 
 
 
 
24
25
26
27
28
29
30
31
32
33
34
 
 
 
 
 
 
 
 
 
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
 
54
55
56
57
 
 
 
 
 
 
 
 
 
 
 
 
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
...
12
13
14
 
 
 
 
 
 
 
 
 
15
16
17
18
19
20
21
22
23
24
25
 
26
 
 
 
 
 
 
 
 
27
28
29
30
31
32
33
34
35
36
 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
 
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
0
@@ -12,68 +12,79 @@ module ActionView # :nodoc:
0
 end
0
 
0
 module Markaby
0
-
0
- # Markaby helpers for Rails.
0
- module ActionControllerHelpers
0
- # Returns a string of HTML built from the attached +block+. Any +options+ are
0
- # passed into the render method.
0
- #
0
- # Use this method in your controllers to output Markaby directly from inside.
0
- def render_markaby(options = {}, &block)
0
- render options.merge({ :text => Builder.new(options[:locals], self, &block).to_s })
0
+ module Rails
0
+ # Markaby helpers for Rails.
0
+ module ActionControllerHelpers
0
+ # Returns a string of HTML built from the attached +block+. Any +options+ are
0
+ # passed into the render method.
0
+ #
0
+ # Use this method in your controllers to output Markaby directly from inside.
0
+ def render_markaby(options = {}, &block)
0
+ render options.merge({ :text => Builder.new(options[:locals], self, &block).to_s })
0
+ end
0
     end
0
- end
0
 
0
- class ActionViewTemplateHandler # :nodoc:
0
- def initialize(action_view)
0
- @action_view = action_view
0
- end
0
- def render(template, local_assigns, file_path)
0
- template = Template.new(template)
0
- template.path = file_path
0
- template.render(@action_view.assigns.merge(local_assigns), @action_view)
0
+ class ActionViewTemplateHandler # :nodoc:
0
+ def initialize(action_view)
0
+ @action_view = action_view
0
+ end
0
+ def render(template, local_assigns, file_path)
0
+ template = Template.new(template)
0
+ template.path = file_path
0
+ template.render(@action_view.assigns.merge(local_assigns), @action_view)
0
+ end
0
     end
0
- end
0
+
0
+ class Builder < Markaby::Builder # :nodoc:
0
+ def initialize(*args, &block)
0
+ super *args, &block
0
+
0
+ @assigns.each { |k, v| @helpers.instance_variable_set("@#{k}", v) }
0
+ end
0
+
0
+ def flash(*args)
0
+ @helpers.controller.send(:flash, *args)
0
+ end
0
+
0
+ # Emulate ERB to satisfy helpers like <tt>form_for</tt>.
0
+ def _erbout
0
+ @_erbout ||= FauxErbout.new(self)
0
+ end
0
 
0
- class FauxErbout < ::Builder::BlankSlate # :nodoc:
0
- def initialize(builder)
0
- @builder = builder
0
- end
0
- def nil? # see ActionView::Helpers::CaptureHelper#capture
0
- true
0
- end
0
- def method_missing(*args, &block)
0
- @builder.send *args, &block
0
- end
0
- end
0
-
0
- class Builder # :nodoc:
0
- def flash(*args)
0
- @helpers.controller.send(:flash, *args)
0
+ # Content_for will store the given block in an instance variable for later use
0
+ # in another template or in the layout.
0
+ #
0
+ # The name of the instance variable is content_for_<name> to stay consistent
0
+ # with @content_for_layout which is used by ActionView's layouts.
0
+ #
0
+ # Example:
0
+ #
0
+ # content_for("header") do
0
+ # h1 "Half Shark and Half Lion"
0
+ # end
0
+ #
0
+ # If used several times, the variable will contain all the parts concatenated.
0
+ def content_for(name, &block)
0
+ @helpers.assigns["content_for_#{name}"] =
0
+ eval("@content_for_#{name} = (@content_for_#{name} || '') + capture(&block)")
0
+ end
0
     end
0
+
0
+
0
     
0
- # Emulate ERB to satisfy helpers like <tt>form_for</tt>.
0
- def _erbout
0
- @_erbout ||= FauxErbout.new(self)
0
+ Template.builder_class = Builder
0
+
0
+ class FauxErbout < ::Builder::BlankSlate # :nodoc:
0
+ def initialize(builder)
0
+ @builder = builder
0
+ end
0
+ def nil? # see ActionView::Helpers::CaptureHelper#capture
0
+ true
0
+ end
0
+ def method_missing(*args, &block)
0
+ @builder.send *args, &block
0
+ end
0
     end
0
 
0
- # Content_for will store the given block in an instance variable for later use
0
- # in another template or in the layout.
0
- #
0
- # The name of the instance variable is content_for_<name> to stay consistent
0
- # with @content_for_layout which is used by ActionView's layouts.
0
- #
0
- # Example:
0
- #
0
- # content_for("header") do
0
- # h1 "Half Shark and Half Lion"
0
- # end
0
- #
0
- # If used several times, the variable will contain all the parts concatenated.
0
- def content_for(name, &block)
0
- @helpers.assigns["content_for_#{name}"] =
0
- eval("@content_for_#{name} = (@content_for_#{name} || '') + capture(&block)")
0
- end
0
   end
0
-
0
 end
...
1
2
3
 
 
 
 
 
 
 
 
4
5
6
...
8
9
10
11
 
12
13
14
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
16
17
18
 
19
20
21
22
0
@@ -1,6 +1,14 @@
0
 module Markaby
0
   class Template
0
 
0
+ def self.builder_class=(builder)
0
+ @@builder_class = builder
0
+ end
0
+
0
+ def self.builder_class
0
+ @@builder_class ||= Builder
0
+ end
0
+
0
     attr_accessor :source, :path
0
     
0
     def initialize(source)
0
@@ -8,7 +16,7 @@ module Markaby
0
     end
0
 
0
     def render(*args)
0
- output = Builder.new(*args)
0
+ output = self.class.builder_class.new(*args)
0
 
0
       if path.nil?
0
         output.instance_eval source
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 ul {
0
+ check_ivar_exists :monkeys
0
+
0
   @monkeys.each { |monkey|
0
     li monkey.name
0
   }
...
14
15
16
 
 
17
18
19
...
14
15
16
17
18
19
20
21
0
@@ -14,6 +14,8 @@ Rails::Initializer.run
0
 
0
 require 'action_controller/test_process'
0
 
0
+Dependencies.load_paths.unshift File.dirname(__FILE__)
0
+
0
 $:.unshift MARKABY_ROOT
0
 
0
 require 'init'
...
1
2
3
 
 
 
4
5
6
...
31
32
33
 
34
35
36
...
91
92
93
 
94
...
1
2
3
4
5
6
7
8
9
...
34
35
36
37
38
39
40
...
95
96
97
98
99
0
@@ -1,6 +1,9 @@
0
 require File.join(File.dirname(__FILE__), 'rails', 'test_preamble')
0
 
0
 class MarkabyController < ActionController::Base
0
+
0
+ helper :test
0
+
0
   @@locals = { :monkeys => Monkey.find(:all) }
0
 
0
   def rescue_action(e) raise e end;
0
@@ -31,6 +34,7 @@ class MarkabyController < ActionController::Base
0
   def basic_inline_rendering
0
     render :inline => mab { ul { Monkey.find(:all).each { |m| li m.name } } }
0
   end
0
+
0
 end
0
 
0
 class MarkabyOnRailsTest < Test::Unit::TestCase
0
@@ -91,4 +95,5 @@ class MarkabyOnRailsTest < Test::Unit::TestCase
0
       assert_equal 5, error.line_number.to_i
0
     end
0
   end
0
+
0
 end

Comments

    No one has commented yet.