flype-merb_markaby 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/merb_markaby/template.rb +15 -18
- metadata +1 -1
@@ -2,17 +2,14 @@ module Merb::Template
|
|
2
2
|
|
3
3
|
class Markaby
|
4
4
|
# ==== Parameters
|
5
|
-
# path<String>:: A full path to the template
|
6
5
|
# name<String>:: The name of the method that will be created
|
7
6
|
# mod<Module>:: The module that the compiled method will be placed into
|
8
|
-
|
9
|
-
|
10
|
-
path = File.expand_path(path)
|
11
|
-
template = ::Markaby::Template.new(File.read(path))
|
7
|
+
def self.compile_template(io, name, locals, mod)
|
8
|
+
template = ::Markaby::Template.new(io.read)
|
12
9
|
template.def_method(mod, name)
|
13
10
|
name
|
14
11
|
end
|
15
|
-
|
12
|
+
|
16
13
|
module Mixin
|
17
14
|
# Provides direct acccess to the buffer for this view context
|
18
15
|
def _mab_buffer( binding )
|
@@ -28,7 +25,7 @@ module Merb::Template
|
|
28
25
|
# If there is no buffer, just call the block and get the contents
|
29
26
|
if buffer.nil?
|
30
27
|
block.call(*args)
|
31
|
-
|
28
|
+
# If there is a buffer, execute the block, then extract its contents
|
32
29
|
else
|
33
30
|
pos = buffer.length
|
34
31
|
block.call(*args)
|
@@ -42,11 +39,11 @@ module Merb::Template
|
|
42
39
|
data
|
43
40
|
end
|
44
41
|
end
|
45
|
-
|
42
|
+
|
46
43
|
def _concat_mab(string, binding)
|
47
44
|
_mab_buffer(binding) << string
|
48
45
|
end
|
49
|
-
|
46
|
+
|
50
47
|
end
|
51
48
|
Merb::Template.register_extensions(self, %w[mab])
|
52
49
|
end
|
@@ -54,20 +51,20 @@ end
|
|
54
51
|
|
55
52
|
module Markaby
|
56
53
|
class Template
|
57
|
-
|
54
|
+
|
58
55
|
def def_method(object, name, filename=nil)
|
59
56
|
m = object.is_a?(Module) ? :module_eval : :instance_eval
|
60
57
|
setup = "@_engine = 'mab'"
|
61
58
|
method_body = <<-END_OF_METHOD
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
end
|
68
|
-
assigns.merge!(@_merb_partial_locals) if @_merb_partial_locals
|
69
|
-
mab = Markaby::Builder.new(assigns, self) {#{@template}}.to_s
|
59
|
+
def #{name}(assigns={})
|
60
|
+
#{setup}
|
61
|
+
if $DEBUG
|
62
|
+
require 'ruby-debug'
|
63
|
+
debugger
|
70
64
|
end
|
65
|
+
assigns.merge!(@_merb_partial_locals) if @_merb_partial_locals
|
66
|
+
mab = Markaby::Builder.new(assigns, self) {#{@template}}.to_s
|
67
|
+
end
|
71
68
|
END_OF_METHOD
|
72
69
|
object.__send__(m, method_body, filename || @filename || 'merb_markaby/lib/merb_markaby/template.rb')
|
73
70
|
end
|