class MarkdownHelper

Constants

VERSION

Attributes

pristine[RW]

Public Class Methods

comment(text) click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 71
def self.comment(text)
  "<!--#{text}-->"
end
git_clone_dir_path() click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 14
  def MarkdownHelper.git_clone_dir_path
    git_dir = `git rev-parse --show-toplevel`.chomp
    unless $?.success?
      message = <<EOT

Markdown helper must run inside a .git project.
That is, the working directory one of its parents must be a .git directory.
EOT
      raise RuntimeError.new(message)
    end
    git_dir
  end
new(options = {}) click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 27
def initialize(options = {})
  # Confirm that we're in a git project.
  # This is necessary so that we can prune file paths in the tests,
  # which otherwise would fail because of differing installation directories.
  # It also allows pruned paths to be used in the inserted comments (when not pristine).
  MarkdownHelper.git_clone_dir_path
  default_options = {
      :pristine => false,
  }
  merged_options = default_options.merge(options)
  merged_options.each_pair do |method, value|
    unless self.respond_to?(method)
      raise OptionError.new("Unknown option: #{method}")
    end
    setter_method = "#{method}="
    send(setter_method, value)
    merged_options.delete(method)
  end
end
path_in_project(file_path) click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 75
def self.path_in_project(file_path)
  abs_path = File.absolute_path(file_path)
  abs_path.sub(MarkdownHelper.git_clone_dir_path + '/', '')
end

Public Instance Methods

generate_file(method, template_file_path, markdown_file_path) { |output_lines| ... } click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 47
def generate_file(method, template_file_path, markdown_file_path)
  template_path_in_project = MarkdownHelper.path_in_project(template_file_path)
  output_lines = []
  yield output_lines
  output_lines = output_lines.collect { |line| line.chomp }
  unless pristine
    output_lines.unshift(MarkdownHelper.comment(" >>>>>> BEGIN GENERATED FILE (#{method}): SOURCE #{template_path_in_project} "))
    output_lines.push(MarkdownHelper.comment(" <<<<<< END GENERATED FILE (#{method}): SOURCE #{template_path_in_project} "))
  end
  output_lines.push('')
  output = output_lines.join("\n")
  File.write(markdown_file_path, output)
end
include(template_file_path, markdown_file_path) click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 66
def include(template_file_path, markdown_file_path)
  includer = MarkdownIncluder.new(:pristine => pristine)
  includer.include(template_file_path, markdown_file_path)
end
run_irb(template_file_path, markdown_file_path) click to toggle source
# File lib/markdown_helper/markdown_helper.rb, line 61
def run_irb(template_file_path, markdown_file_path)
  irb_runner = MarkdownIrbRunner.new(:pristine => pristine)
  irb_runner.run_irb(template_file_path, markdown_file_path)
end