Module: Polytrix::Documentation::CommentStyles

Included in:
CodeSegmenter
Defined in:
lib/polytrix/documentation/comment_styles.rb

Overview

This class was extracted from the [Rocco](rtomayko.github.com/rocco/) project which was in turn based on the [Docco](jashkenas.github.com/docco/).

Defined Under Namespace

Classes: UnknownStyleError

Constant Summary collapse

C_STYLE_COMMENTS =
{
  single: '//',
  multi: { start: '/**', middle: '*', end: '*/' },
  heredoc: nil,
  extensions: %w(c cpp cs java js php scala go)
}
COMMENT_STYLES =
{
  'bash'          =>  { single: '#', multi: nil, extensions: %w(sh) },
  'c'             =>  C_STYLE_COMMENTS,
  'coffee-script' =>  {
    single: '#',
    multi: { start: '###', middle: nil, end: '###' },
    heredoc: nil,
    extensions: %w(coffee)
  },
  'cpp' =>  C_STYLE_COMMENTS,
  'csharp' => C_STYLE_COMMENTS,
  'css'           =>  {
    single: nil,
    multi: { start: '/**', middle: '*', end: '*/' },
    heredoc: nil,
    extensions: %w(css scss sass)
  },
  'html'           =>  {
    single: nil,
    multi: { start: '<!--', middle: nil, end: '-->' },
    heredoc: nil,
    extensions: %w(html htm)
  },
  'java'          =>  C_STYLE_COMMENTS,
  'js'            =>  C_STYLE_COMMENTS,
  'lua'           =>  {
    single: '--',
    multi: nil,
    heredoc: nil,
    extensions: %w(lua)
  },
  'php' => C_STYLE_COMMENTS,
  'python'        =>  {
    single: '#',
    multi: { start: '"""', middle: nil, end: '"""' },
    heredoc: nil,
    extensions: %w(py)
  },
  'rb'            =>  {
    single: '#',
    multi: { start: '=begin', middle: nil, end: '=end', idiomatic: false },
    heredoc: '<<-',
    extensions: %w(rb)
  },
  'scala'         =>  C_STYLE_COMMENTS,
  'scheme'        =>  { single: ';;',  multi: nil, heredoc: nil, extensions: %w(schema) },
  'xml'           =>  {
    single: nil,
    multi: { start: '<!--', middle: nil, end: '-->' },
    heredoc: nil,
    extensions: %w(xml xsl xslt)
  }
}

Class Method Summary collapse

Class Method Details

.infer(extension) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/polytrix/documentation/comment_styles.rb', line 14

def self.infer(extension)
  extension.tr! '.', ''
  return extension, COMMENT_STYLES[extension] if COMMENT_STYLES.key? extension

  COMMENT_STYLES.each do | _style_name, style |
    return extension, style if style[:extensions].include? extension
  end

  fail UnknownStyleError, extension
end