Class: Mack::Rendering::Type::Layout

Inherits:
Object
  • Object
show all
Defined in:
lib/mack-distributed/views/rendering/type/layout.rb

Instance Method Summary collapse

Instance Method Details

#renderObject



8
9
10
11
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
# File 'lib/mack-distributed/views/rendering/type/layout.rb', line 8

def render
  if !self._options[:layout].starts_with?("distributed")
    # this is the regular layout, so call the local_render method
    _original_render
  else
    uri = Addressable::URI.parse(self._options[:layout])
    raise InvalidAddressableURIFormat.new("#{self._options[:layout]}") if uri.host.nil? or uri.path.nil?
    
    app_name = uri.host
    resource = File.join("app", "views", "layouts", uri.path)

    data = Mack::Distributed::View.ref(app_name)
    if data
      raw = ""
      Mack::Rendering::Engine::Registry.engines[:layout].each do |e|
        @engine = find_engine(e).new(self.view_template)

        layout_path = "#{resource}.#{self._options[:format]}.#{@engine.extension}"
        raw = data.get(layout_path)
        break if !raw.nil?
      end

      raise Mack::Errors::ResourceNotFound.new("#{self._options[:distributed]}") if raw.nil?

      old_render_value = self.view_template._render_value.dup
      self.view_template._render_value = raw
      Mack::Rendering::Type::Inline.new(self.view_template).render
    end
  end
end