Class: Aquanaut::Sitemap

Inherits:
Object
  • Object
show all
Defined in:
lib/aquanaut/sitemap.rb

Overview

The sitemap class is used to render the results in HTML and JavaScript.

Uses SLIM as a template engine.

Instance Method Summary collapse

Constructor Details

#initialize(graph, domain, target_dir = "#{Dir.pwd}/sitemap") ⇒ Sitemap

Returns a new instance of Sitemap.



10
11
12
13
14
15
16
17
18
# File 'lib/aquanaut/sitemap.rb', line 10

def initialize(graph, domain, target_dir="#{Dir.pwd}/sitemap")
  @graph = graph
  @domain = domain
  @target_dir = target_dir

  if Pathname.new(target_dir).relative?
    @target_dir = File.expand_path("../../../#{target_dir}", __FILE__)
  end
end

Instance Method Details

#render_resultsObject

Renders the results by initiailizing the dependencies and processingt the template.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/aquanaut/sitemap.rb', line 22

def render_results
  initialize_target_directory

  options = { disable_escape: true }
  template_path = File.expand_path('../templates/index.html.slim', __FILE__)
  rendered_template = Slim::Template.new(template_path, options).render(self)

  File.open("#{@target_dir}/index.html", 'w') do |file|
    file.write rendered_template
  end
end