Class: Fdoc::BasePresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/fdoc/presenters/base_presenter.rb

Overview

BasePresenters assist in generating Html for fdoc classes. BasePresenters is an abstract class with a lot of helper methods for URLs and common text styling tasks (like #render_markdown and #render_json)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BasePresenter



13
14
15
# File 'lib/fdoc/presenters/base_presenter.rb', line 13

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/fdoc/presenters/base_presenter.rb', line 11

def options
  @options
end

Instance Method Details

#css_pathObject



42
43
44
# File 'lib/fdoc/presenters/base_presenter.rb', line 42

def css_path
  File.join(html_directory, "styles.css")
end

#get_bindingObject



34
35
36
# File 'lib/fdoc/presenters/base_presenter.rb', line 34

def get_binding
  binding
end

#html_directoryObject



38
39
40
# File 'lib/fdoc/presenters/base_presenter.rb', line 38

def html_directory
  options[:url_base_path] || options[:html_directory] || ""
end

#index_path(subdirectory = "") ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/fdoc/presenters/base_presenter.rb', line 46

def index_path(subdirectory = "")
  html_path = File.join(html_directory, subdirectory)
  if options[:static_html]
    File.join(html_path, 'index.html')
  else
    html_path
  end
end

#render_erb(erb_name, binding = get_binding) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/fdoc/presenters/base_presenter.rb', line 17

def render_erb(erb_name, binding = get_binding)
  template_path = File.join(options[:template_directory], erb_name)
  if !File.exists? template_path
    template_path = File.join(File.dirname(__FILE__), "../templates", erb_name)
  end
  template = ERB.new(File.read(template_path), nil, '-')
  template.result(binding)
end

#render_markdown(markdown_str) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/fdoc/presenters/base_presenter.rb', line 26

def render_markdown(markdown_str)
  if markdown_str
    Kramdown::Document.new(markdown_str, :entity_output => :numeric).to_html
  else
    nil
  end
end

#tag_with_anchor(tag, content, anchor_slug = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/fdoc/presenters/base_presenter.rb', line 55

def tag_with_anchor(tag, content, anchor_slug = nil)
  anchor_slug ||= content.downcase.gsub(' ', '_')
  "  <\#{tag} id=\"\#{anchor_slug}\">\n    <a href=\"#\#{anchor_slug}\" class=\"anchor\">\n      \#{content}\n    </a>\n  </\#{tag}>\n  EOS\nend\n"