Class: Perron::Site::Builder::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/perron/site/builder/page.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Page

Returns a new instance of Page.



9
10
11
# File 'lib/perron/site/builder/page.rb', line 9

def initialize(path)
  @output_path, @path = Rails.root.join(Perron.configuration.output), path
end

Instance Method Details

#renderObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/perron/site/builder/page.rb', line 13

def render
  action = route_info[:action]
  request = ActionDispatch::Request.new(env)
  response = ActionDispatch::Response.new

  request.path_parameters = route_info

  controller.dispatch(action, request, response)

  return puts "  ❌ ERROR: Request failed for '#{@path}' (Status: #{response.status})" unless response.successful?

  save_html(response.body)
rescue => error
  puts "  ❌ ERROR: Failed to generate page for '#{@path}'. Details: #{error.class} - #{error.message}\n#{error.backtrace.first(3).join("\n")}"
end