Sha256: 6b42ed0a77ddc0cc7f87872e538cb4ef5312cbe3641842e3a09d815b31b9c0fc
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
require 'erb' require 'kramdown' # HtmlPresenters assist in generating Html for fdoc classes. # HtmlPresenters is an abstract class with a lot of helper methods # for URLs and common text styling tasks (like #render_markdown # and #render_json) class Fdoc::HtmlPresenter attr_reader :options def initialize(options = {}) @options = options end def render_erb(erb_name) template_path = File.join(File.dirname(__FILE__), "../templates", erb_name) template = ERB.new(File.read(template_path)) template.result(binding) end def render_markdown(markdown_str) if markdown_str Kramdown::Document.new(markdown_str, :entity_output => :numeric).to_html else nil end end def render_json(json) if json.kind_of? String '<tt>"%s"</tt>' % json.gsub(/\"/, 'quot;') elsif json.kind_of?(Numeric) || json.kind_of?(TrueClass) || json.kind_of?(FalseClass) '<tt>%s</tt>' % json elsif json.kind_of?(Hash) || json.kind_of?(Array) '<pre><code>%s</code></pre>' % JSON.pretty_generate(json) end end def html_directory options[:url_base_path] || options[:html_directory] || "" end def css_path File.join(html_directory, "styles.css") end 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fdoc-0.2.1 | lib/fdoc/presenters/html_presenter.rb |