public this repo is viewable by everyone
Fork of nex3/haml
Description: HTML Abstraction Markup Language - A Markup Haiku
Homepage: http://haml.hamptoncatlin.com
Clone URL: git://github.com/chriseppstein/haml.git
Better handling for monkeypatched modules when they are used outside the 
ActionView context.
chriseppstein (author)
16 days ago
commit  da66b1cedb997f26343ee7eceeaf8ee3eff94fa1
tree    1312493d8ca5ee59e30958e15bcf19ca003f3c05
parent  3b8cf8b913620ba3e1df949d5cf386c0234da509
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
3
 
 
 
4
5
6
...
18
19
20
 
 
 
21
22
 
23
24
25
...
29
30
31
32
 
33
34
35
...
40
41
42
 
 
 
43
44
 
45
46
47
...
52
53
54
 
 
 
55
56
57
58
 
59
60
61
...
68
69
70
 
 
71
72
73
...
81
82
83
 
 
 
84
85
 
86
87
88
...
93
94
95
96
 
97
98
99
...
104
105
106
 
 
 
107
108
 
109
110
111
...
114
115
116
117
 
118
119
120
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
36
37
38
39
40
41
42
 
43
44
45
46
...
50
51
52
 
53
54
55
56
...
61
62
63
64
65
66
67
 
68
69
70
71
...
76
77
78
79
80
81
82
83
84
 
85
86
87
88
...
95
96
97
98
99
100
101
102
...
110
111
112
113
114
115
116
 
117
118
119
120
...
125
126
127
 
128
129
130
131
...
136
137
138
139
140
141
142
 
143
144
145
146
...
149
150
151
 
152
153
154
155
0
@@ -1,6 +1,24 @@
0
 if defined?(ActionView) and not defined?(Merb::Plugins)
0
+
0
+ module Haml
0
+ module Helpers
0
+ module TemplateChecker
0
+ # Handle the case where a module is uses outside of an ActionView context
0
+ # calls to is_haml if it is defined, otherwise returns false.
0
+ def check_is_haml?
0
+ is_haml?
0
+ rescue NoMethodError
0
+ false
0
+ end
0
+ end
0
+ end
0
+ end
0
+
0
   module ActionView
0
     class Base # :nodoc:
0
+
0
+ include Haml::Helpers::TemplateChecker
0
+
0
       def is_haml?
0
         false
0
       end
0
@@ -18,8 +36,11 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
     module Helpers
0
       # :stopdoc:
0
       module CaptureHelper
0
+
0
+ include Haml::Helpers::TemplateChecker
0
+
0
         def capture_with_haml(*args, &block)
0
- if is_haml?
0
+ if check_is_haml?
0
             capture_haml(*args, &block)
0
           else
0
             capture_without_haml(*args, &block)
0
@@ -29,7 +50,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
         alias_method :capture, :capture_with_haml
0
 
0
         def capture_erb_with_buffer_with_haml(*args, &block)
0
- if is_haml?
0
+ if check_is_haml?
0
             capture_haml_with_buffer(*args, &block)
0
           else
0
             capture_erb_with_buffer_without_haml(*args, &block)
0
@@ -40,8 +61,11 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
       end
0
 
0
       module TextHelper
0
+
0
+ include Haml::Helpers::TemplateChecker
0
+
0
         def concat_with_haml(string, binding = nil)
0
- if is_haml?
0
+ if check_is_haml?
0
             haml_buffer.buffer.concat(string)
0
           else
0
             concat_without_haml(string, binding)
0
@@ -52,10 +76,13 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
       end
0
 
0
       module TagHelper
0
+
0
+ include Haml::Helpers::TemplateChecker
0
+
0
         def content_tag_with_haml(name, *args, &block)
0
           content = content_tag_without_haml(name, *args, &block)
0
 
0
- if is_haml? && haml_buffer.options[:preserve].include?(name.to_s)
0
+ if check_is_haml? && haml_buffer.options[:preserve].include?(name.to_s)
0
             content = Haml::Helpers.preserve content
0
           end
0
 
0
@@ -68,6 +95,8 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
       class InstanceTag
0
         # Includes TagHelper
0
 
0
+ include Haml::Helpers::TemplateChecker
0
+
0
         def haml_buffer
0
           @template_object.send :haml_buffer
0
         end
0
@@ -81,8 +110,11 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
       end
0
 
0
       module FormTagHelper
0
+
0
+ include Haml::Helpers::TemplateChecker
0
+
0
         def form_tag_with_haml(url_for_options = {}, options = {}, *parameters_for_url, &proc)
0
- if is_haml?
0
+ if check_is_haml?
0
             if block_given?
0
               oldproc = proc
0
               proc = haml_bind_proc do |*args|
0
@@ -93,7 +125,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
               end
0
             end
0
             res = form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc) + "\n"
0
- concat "\n" if block_given? && is_haml?
0
+ concat "\n" if block_given? && check_is_haml?
0
             res
0
           else
0
             form_tag_without_haml(url_for_options, options, *parameters_for_url, &proc)
0
@@ -104,8 +136,11 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
       end
0
 
0
       module FormHelper
0
+
0
+ include Haml::Helpers::TemplateChecker
0
+
0
         def form_for_with_haml(object_name, *args, &proc)
0
- if block_given? && is_haml?
0
+ if block_given? && check_is_haml?
0
             oldproc = proc
0
             proc = haml_bind_proc do |*args|
0
               tab_up
0
@@ -114,7 +149,7 @@ if defined?(ActionView) and not defined?(Merb::Plugins)
0
             end
0
           end
0
           form_for_without_haml(object_name, *args, &proc)
0
- concat "\n" if block_given? && is_haml?
0
+ concat "\n" if block_given? && check_is_haml?
0
         end
0
         alias_method :form_for_without_haml, :form_for
0
         alias_method :form_for, :form_for_with_haml

Comments

    No one has commented yet.