Class: Httpdoc::Rendering::SingleFileRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/httpdoc/rendering.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SingleFileRenderer

Returns a new instance of SingleFileRenderer.



123
124
125
126
# File 'lib/httpdoc/rendering.rb', line 123

def initialize(options = {})
  @base_url = options[:base_url]
  @base_url ||= 'http://example.com/'
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



150
151
152
# File 'lib/httpdoc/rendering.rb', line 150

def base_url
  @base_url
end

#template_nameObject

Returns the value of attribute template_name.



151
152
153
# File 'lib/httpdoc/rendering.rb', line 151

def template_name
  @template_name
end

Instance Method Details

#find_template(name) ⇒ Object



145
146
147
148
# File 'lib/httpdoc/rendering.rb', line 145

def find_template(name)
  %(erb).each do |extension|
  end
end

#render_controller(controller) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/httpdoc/rendering.rb', line 128

def render_controller(controller)
  %w(erb).each do |extension|
    template_file_name = "#{@template_name}"
    template_file_name = "#{template_file_name}.#{extension}" unless template_file_name =~ /#{Regexp.escape(extension)}$/
    unless File.exist?(template_file_name)
      possible_template_file_name = File.join(File.dirname(__FILE__), "templates/#{template_file_name}")
      if File.exist?(possible_template_file_name)
        template_file_name = possible_template_file_name
      end
    end
    template_content = File.read(template_file_name)
    context = ControllerContext.new(self, controller)
    erb = ERB.new(template_content, nil, "-")
    return erb.result(context.get_binding)
  end
end