GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Add support for IO templates instead of just paths. See 
PLUGIN_API_CHANGELOG for details.
wycats (author)
Wed Jun 18 16:19:26 -0700 2008
commit  191f5c8a8ea334dd465968d796d7a598fecc5545
tree    3abba2285bc766a461d271ded533d3b3e14d9bdc
parent  282a83a7e48467f27558222f44bfa4ec94db2399
...
481
482
483
484
 
485
486
487
...
481
482
483
 
484
485
486
487
0
@@ -481,7 +481,7 @@ class Merb::BootLoader::Templates < Merb::BootLoader
0
     # Loads the templates into the Merb::InlineTemplates module.
0
     def run
0
       template_paths.each do |path|
0
- Merb::Template.inline_template(path)
0
+ Merb::Template.inline_template(File.open(path))
0
       end
0
     end
0
 
...
45
46
47
48
 
49
50
51
52
 
53
54
55
...
70
71
72
73
74
75
 
 
76
77
78
...
82
83
84
85
86
 
 
87
88
 
89
90
91
...
132
133
134
135
 
136
137
138
139
140
 
 
 
141
142
143
...
45
46
47
 
48
49
50
51
 
52
53
54
55
...
70
71
72
 
 
 
73
74
75
76
77
...
81
82
83
 
 
84
85
86
 
87
88
89
90
...
131
132
133
 
134
135
136
 
 
 
137
138
139
140
141
142
0
@@ -45,11 +45,11 @@ module Merb::Template
0
       ret =
0
       if Merb::Config[:reload_templates]
0
         file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
0
- METHOD_LIST[path] = file ? inline_template(file) : nil
0
+ METHOD_LIST[path] = file ? inline_template(File.open(file)) : nil
0
       else
0
         METHOD_LIST[path] ||= begin
0
           file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
0
- file ? inline_template(file) : nil
0
+ file ? inline_template(File.open(file)) : nil
0
         end
0
       end
0
       
0
@@ -70,9 +70,8 @@ module Merb::Template
0
     # adds it to the METHOD_LIST table to speed lookup later.
0
     #
0
     # ==== Parameters
0
- # path<String>::
0
- # The full path of the template (minus the templating specifier) to
0
- # inline.
0
+ # io<#path>::
0
+ # An IO that responds to #path (File or VirtualFile)
0
     # mod<Module>::
0
     # The module to put the compiled method into. Defaults to
0
     # Merb::InlineTemplates
0
@@ -82,10 +81,10 @@ module Merb::Template
0
     # must be available to instances of AbstractController that will use it.
0
     #---
0
     # @public
0
- def inline_template(path, mod = Merb::InlineTemplates)
0
- path = File.expand_path(path)
0
+ def inline_template(io, mod = Merb::InlineTemplates)
0
+ path = File.expand_path(io.path)
0
       METHOD_LIST[path.gsub(/\.[^\.]*$/, "")] =
0
- engine_for(path).compile_template(path, template_name(path), mod)
0
+ engine_for(path).compile_template(io, template_name(path), mod)
0
     end
0
     
0
     # Finds the engine for a particular path.
0
@@ -132,12 +131,12 @@ module Merb::Template
0
 
0
   class Erubis
0
     # ==== Parameters
0
- # path<String>:: A full path to the template.
0
+ # io<#path>:: An IO containing the full path of the template.
0
     # name<String>:: The name of the method that will be created.
0
     # mod<Module>:: The module that the compiled method will be placed into.
0
- def self.compile_template(path, name, mod)
0
- template = ::Erubis::Eruby.new(File.read(path))
0
- template.def_method(mod, name, path)
0
+ def self.compile_template(io, name, mod)
0
+ template = ::Erubis::Eruby.new(io.read)
0
+ template.def_method(mod, name, File.expand_path(io.path))
0
       name
0
     end
0
 
...
10
11
12
13
 
...
10
11
12
 
13
0
@@ -10,4 +10,4 @@ require corelib/:object
0
 require corelib/:object_space
0
 require corelib/:rubygems
0
 require corelib/:set
0
-
0
+require corelib/:virtual_file
...
23
24
25
26
27
 
 
28
29
30
 
31
32
33
...
58
59
60
61
 
62
63
64
...
74
75
76
 
 
 
 
 
 
 
 
 
 
 
77
78
79
...
86
87
88
89
 
90
91
92
...
23
24
25
 
 
26
27
28
29
 
30
31
32
33
...
58
59
60
 
61
62
63
64
...
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
...
97
98
99
 
100
101
102
103
0
@@ -23,11 +23,11 @@ module Merb::Test::Fixtures
0
   
0
   class MyTemplateEngine
0
     
0
- def self.compile_template(path, name, mod)
0
- text = File.read(path)
0
+ def self.compile_template(io, name, mod)
0
+ text = io.read
0
       table = { "\r"=>"\\r", "\n"=>"\\n", "\t"=>"\\t", '"'=>'\\"', "\\"=>"\\\\" }
0
       text = (text.split("\n").map {|x| '"' + (x.gsub(/[\r\n\t"\\]/) { |m| table[m] }) + '"'}).join(" +\n")
0
- mod.class_eval <<-EOS, path
0
+ mod.class_eval <<-EOS, File.expand_path(io.path)
0
         def #{name}
0
           #{text}
0
         end
0
@@ -58,7 +58,7 @@ describe Merb::Template do
0
   # @semipublic
0
   
0
   def rendering_template(template_path)
0
- Merb::Template.inline_template(template_path, Merb::Test::Fixtures::MyHelpers)
0
+ Merb::Template.inline_template(File.open(template_path), Merb::Test::Fixtures::MyHelpers)
0
     Merb::Test::Fixtures::Environment.new.
0
       send(Merb::Template.template_name(template_path))
0
   end
0
@@ -74,6 +74,17 @@ describe Merb::Template do
0
     rendering_template(template_path).should == "Hello world!"
0
   end
0
   
0
+ it "should compile and inline templates that comes through via VirtualFile" do
0
+ Merb::Template.inline_template(VirtualFile.new("Hello",
0
+ File.dirname(__FILE__) / "templates" / "template.html.erb"),
0
+ Merb::Test::Fixtures::MyHelpers)
0
+
0
+ res = Merb::Test::Fixtures::Environment.new.
0
+ send(Merb::Template.template_name(File.dirname(__FILE__) / "templates" / "template.html.erb"))
0
+
0
+ res.should == "Hello"
0
+ end
0
+
0
   it "should know how to correctly report errors" do
0
     template_path = File.dirname(__FILE__) / "templates" / "error.html.erb"
0
     running { render_template(template_path) }.should raise_error(NameError, /`foo'/)
0
@@ -86,7 +97,7 @@ describe Merb::Template do
0
   
0
   it "should find the full template name for a path via #template_for" do
0
     template_path = File.dirname(__FILE__) / "templates" / "template.html.erb"
0
- name = Merb::Template.inline_template(template_path, Merb::Test::Fixtures::MyHelpers)
0
+ name = Merb::Template.inline_template(File.open(template_path), Merb::Test::Fixtures::MyHelpers)
0
     Merb::Test::Fixtures::Environment.new.should respond_to(name)
0
   end
0
   

Comments

    No one has commented yet.