class Specific::Renderer::Markdown

Public Class Methods

new(spec) click to toggle source
# File lib/specific/renderer/markdown.rb, line 8
def initialize(spec)
  @spec = spec
end

Public Instance Methods

render() click to toggle source
# File lib/specific/renderer/markdown.rb, line 12
def render
  out = "# Project Specific\n\n"

  grouped_features = @spec.features.group_by(&:group)

  grouped_features.each do |group, features|
    if group
      group_title = "## Features '#{group.name}'"
    else
      group_title = "## Ungrouped"
    end

    out << group_title + "\n\n"

    features.each do |feature|
      out << "* [#{feature_to_s feature}](#feature-#{feature.id})\n"
    end

    out << "\n"

    features.sort_by(&:id).each do |feature|
      out << [
        "### #{feature_to_s feature}",
        "<a href=\"feature-#{feature.id}\"></a>",
        "\n"
      ].join("\n")
      out << feature.description.join(" \n") + "\n\n"

      feature.scenarios.each do |scenario|
        out << "#### Scenario: #{scenario.name}\n"
        scenario.steps.each do |step|
          out << "* #{step.keyword} #{step.text}\n"
        end
        out << "\n"
      end

      out << "\n"
    end
  end

  out
end

Private Instance Methods

feature_to_s(feature) click to toggle source
# File lib/specific/renderer/markdown.rb, line 57
def feature_to_s(feature)
  ("[F%0.4d] - %s" % [feature.id, feature.name])
end