Sha256: f8a003c187aea423ad3cfb2b58063d98de586985b60bcf90c8479b7655a2a49c

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require 'erb'
require 'json'
require 'forwardable'

class Lurker::BasePresenter
  attr_reader :options

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

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

  def url_base_path
    options[:url_base_path] || '/'
  end

  def assets
    options[:assets] || {}
  end

  def asset_path(asset)
    "#{html_directory}/#{assets[asset] || asset}"
  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

  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

  def markup(content)
    return unless content
    Lurker.safe_require 'kramdown'
    defined?(Kramdown) ? Kramdown::Document.new(content).to_html : content
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lurker-1.0.0 lib/lurker/presenters/base_presenter.rb
lurker-0.6.12 lib/lurker/presenters/base_presenter.rb
lurker-0.6.11 lib/lurker/presenters/base_presenter.rb