Class: Harbor::XMLView

Inherits:
View
  • Object
show all
Defined in:
lib/harbor/xml_view.rb

Instance Attribute Summary collapse

Attributes inherited from View

#content_type, #context, #extension, #path

Instance Method Summary collapse

Methods inherited from View

cache, cache=, cache_templates!, cache_templates?, #content, exists?, layouts, path, plugins

Constructor Details

#initialize(view, context = {}) ⇒ XMLView

Returns a new instance of XMLView.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/harbor/xml_view.rb', line 27

def initialize(view, context = {})
  super
  @content_type = "text/xml"
  @extension = ".rxml"
  @output = ""
  @filename = ::File.extname(view) == "" ? (view + @extension) : view

  if context.is_a?(ViewContext)
    @context = context
    @xml = context.view.xml
  else
    @xml = Builder::XmlMarkup.new(:indent => 2, :target => @output)
    @context = XMLViewContext.new(self, context)
  end
end

Instance Attribute Details

#outputObject

Returns the value of attribute output.



25
26
27
# File 'lib/harbor/xml_view.rb', line 25

def output
  @output
end

#xmlObject

Returns the value of attribute xml.



25
26
27
# File 'lib/harbor/xml_view.rb', line 25

def xml
  @xml
end

Instance Method Details

#supports_layouts?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/harbor/xml_view.rb', line 43

def supports_layouts?
  false
end

#to_s(layout = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/harbor/xml_view.rb', line 47

def to_s(layout = nil)
  path = View::path.detect { |dir| ::File.exists?(dir + @filename) }
  raise "Could not find '#{@filename}' in #{View::path.inspect}" if path.nil?
  
  eval_code = ::File.read(path + @filename)
  XMLViewContext.new(self, @context).instance_eval(eval_code, __FILE__, __LINE__)

  @output
end