Sha256: ff1d5ac8bbd87ff724dd85d525074a48cb8826c66d9bf178e60a9b19d5615065

Contents?: true

Size: 1.05 KB

Versions: 11

Compression:

Stored size: 1.05 KB

Contents

require 'unindent'

# This is used to generate a document automatically.
class TestCase < Struct.new(:file, :dir, :lineno, :src_haml, :haml_html, :faml_html, :hamlit_html)
  def document(impl)
    base_path = '/spec/hamlit'
    path = File.join(base_path, dir, file)
    doc = <<-DOC
# [#{escape_markdown("#{file}:#{lineno}")}](#{path}#L#{lineno})
## Input
```haml
#{src_haml}
```

## Output
    DOC

    html_by_name = {
      'Haml' => haml_html,
      'Faml' => faml_html,
      'Hamlit' => hamlit_html,
    }

    case impl
    when 'haml'
      html_by_name.delete('Faml')
    when 'faml'
      html_by_name.delete('Haml')
    end

    html_by_name.group_by(&:last).each do |html, pairs|
      doc << "### #{pairs.map(&:first).join(', ')}\n"
      doc << "```html\n"
      doc << "#{html}\n"
      doc << "```\n\n"
    end

    doc
  end

  def doc_path
    File.join(dir, file.gsub(/_spec\.rb$/, '.md'))
  end

  def spec_path
    path = File.join(dir, file)
    escape_markdown(path)
  end

  private

  def escape_markdown(text)
    text.gsub(/_/, '\\_')
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hamlit-1.7.2 spec/spec_helper/test_case.rb
hamlit-1.7.1 spec/spec_helper/test_case.rb
hamlit-1.7.0 spec/spec_helper/test_case.rb
hamlit-1.6.7 spec/spec_helper/test_case.rb
hamlit-1.6.6 spec/spec_helper/test_case.rb
hamlit-1.6.5 spec/spec_helper/test_case.rb
hamlit-1.6.4 spec/spec_helper/test_case.rb
hamlit-1.6.3 spec/spec_helper/test_case.rb
hamlit-1.6.2 spec/spec_helper/test_case.rb
hamlit-1.6.1 spec/spec_helper/test_case.rb
hamlit-1.6.0 spec/spec_helper/test_case.rb