class Fdoc::BasePresenter
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)
Attributes
options[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/fdoc/presenters/base_presenter.rb, line 13 def initialize(options = {}) @options = options end
Public Instance Methods
css_path()
click to toggle source
# File lib/fdoc/presenters/base_presenter.rb, line 39 def css_path File.join(html_directory, "styles.css") end
get_binding()
click to toggle source
# File lib/fdoc/presenters/base_presenter.rb, line 31 def get_binding binding end
html_directory()
click to toggle source
# File lib/fdoc/presenters/base_presenter.rb, line 35 def html_directory options[:url_base_path] || options[:html_directory] || "" end
index_path(subdirectory = "")
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Protected Instance Methods
path_for_template(filename)
click to toggle source
# File lib/fdoc/presenters/base_presenter.rb, line 65 def path_for_template(filename) template_dir = options[:template_directory] template_path = File.join(template_dir, filename) if template_dir if template_path.nil? || !File.exists?(template_path) template_path = File.join(File.dirname(__FILE__), "../templates", filename) end template_path end