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

Returns a new instance of 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



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

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

#get_bindingObject



31
32
33
# File 'lib/fdoc/presenters/base_presenter.rb', line 31

def get_binding
  binding
end

#html_directoryObject



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

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

#index_path(subdirectory = "") ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/fdoc/presenters/base_presenter.rb', line 43

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
# File 'lib/fdoc/presenters/base_presenter.rb', line 17

def render_erb(erb_name, binding = get_binding)
  template_path = path_for_template(erb_name)
  template = ERB.new(File.read(template_path), nil, '-')
  template.result(binding)
end

#render_markdown(markdown_str) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/fdoc/presenters/base_presenter.rb', line 23

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



52
53
54
55
56
57
58
59
60
61
# File 'lib/fdoc/presenters/base_presenter.rb', line 52

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