julien51-babylon 0.1.6 → 0.1.7

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.
@@ -8,6 +8,18 @@ module Babylon
8
8
  class View
9
9
  attr_reader :view_template
10
10
 
11
+ ##
12
+ # Used to 'include' another view inside an existing view.
13
+ # The caller needs to pass the context in which the partial will be rendered
14
+ # Render must be called with :partial as well (other options will be supported later). The partial vale should be a relative path
15
+ # to another file view, from the calling view.
16
+ def render(xml, options = {})
17
+ # First, we need to identify the partial file path, based on the @view_template path.
18
+ partial_path = (@view_template.split("/")[0..-2] + options[:partial].split("/")).join("/").gsub(".xml.builder", "") + ".xml.builder"
19
+ raise ViewFileNotFound unless Babylon.views[partial_path]
20
+ eval(Babylon.views[partial_path], binding, partial_path, 1)
21
+ end
22
+
11
23
  ##
12
24
  # Instantiate a new view with the various varibales passed in assigns and the path of the template to render.
13
25
  def initialize(path = "", assigns = {})
@@ -61,4 +61,26 @@ describe Babylon::Base::View do
61
61
  end
62
62
  end
63
63
 
64
+ describe "render" do
65
+ before(:each) do
66
+ @view_template = "/a/path/to/a/view/file"
67
+ @view = Babylon::Base::View.new(@view_template, {:a => "a", :b => 123, :c => {:d => "d", :e => "123"}})
68
+ @xml_string = <<-eoxml
69
+ xml.message(:to => "you", :from => "me", :type => :chat) do |message|
70
+ message.body("salut")
71
+ render(message, {:partial => "partial"})
72
+ end
73
+ eoxml
74
+ @partial_string = <<-eoxml
75
+ xml.title("hello word")
76
+ eoxml
77
+ Babylon.views.stub!(:[]).with(@view_template).and_return(@xml_string)
78
+ Babylon.views.stub!(:[]).with("/a/path/to/a/view/partial.xml.builder").and_return(@partial_string)
79
+ end
80
+
81
+ it "should render the partial in the right context" do
82
+ @view.evaluate.xpath("//message/title").text.should == "hello word"
83
+ end
84
+ end
85
+
64
86
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: julien51-babylon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - julien Genestoux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-11 00:00:00 -07:00
12
+ date: 2009-06-16 00:00:00 -07:00
13
13
  default_executable: babylon
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency