Class: PDoc::Generators::Html::Page

Inherits:
Object
  • Object
show all
Includes:
Helpers::BaseHelper, Helpers::LinkHelper
Defined in:
lib/pdoc/generators/html/page.rb

Direct Known Subclasses

DocPage

Instance Method Summary collapse

Methods included from Helpers::LinkHelper

#auto_link, #auto_link_code, #auto_link_content, #auto_link_types, #dom_id, #path_prefix, #path_to

Methods included from Helpers::BaseHelper

#content_tag, #htmlize, #img_tag, #inline_htmlize, #javascript_include_tag, #link_to, #stylesheet_link_tag, #tag

Constructor Details

#initialize(template, layout, variables = {}) ⇒ Page



9
10
11
12
13
# File 'lib/pdoc/generators/html/page.rb', line 9

def initialize(template, layout, variables = {})
  @template = template
  @layout = layout
  assign_variables(variables)
end

Instance Method Details

#include(path, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pdoc/generators/html/page.rb', line 33

def include(path, options = {})
  r = ''
  options.each { |k, v| r << "#{k.to_s} = options[:#{k}];" }
  eval(r)
  
  if options[:collection]
    options[:collection].map { |object| Template.new(path, @templates_directory).result(binding) }.join("\n")
  else
    Template.new(path, @templates_directory).result(binding)
  end
end

#renderObject

Renders the page as a string using the assigned layout.



16
17
18
19
20
21
22
23
# File 'lib/pdoc/generators/html/page.rb', line 16

def render
  if @layout
    @content_for_layout = Template.new(@template, @templates_directory).result(binding)
    Template.new(@layout, @templates_directory).result(binding)
  else
    Template.new(@template, @templates_directory).result(binding)
  end
end

#render_to_file(filename) ⇒ Object

Creates a new file and renders the page to it using the assigned layout.



27
28
29
30
31
# File 'lib/pdoc/generators/html/page.rb', line 27

def render_to_file(filename)
  filename ||= ""
  FileUtils.mkdir_p(File.dirname(filename))
  File.open(filename, "w+") { |f| f << render }
end