Sha256: 38765fa841fabcceda7a472d133dde7452f59cbd8d2165bb3d784b7b8cc4ff8c

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

require 'roxie/version'
require 'roxie/extractor'
require 'yaml'

module Roxie

  # The root path for Roxie's source libraries
  ROOT = File.expand_path(File.dirname(__FILE__))

  # Languages that Roxie understands
  LANGUAGES = YAML.load_file(File.join(ROOT, 'roxie', 'languages.yml')).each do |name, lang|
    # Generate matchers for the language
    match = {}
    match[:start_single] = Regexp.new("^\s*#{Regexp.escape(lang['single'])} ") if lang['single']
    if lang['multi']
      match[:start_multi] = Regexp.new("^\s*#{Regexp.escape(lang['multi']['start'])}[ ]?") if lang['multi']['start']
      match[:middle_multi] = Regexp.new("^\s*#{Regexp.escape(lang['multi']['middle'])}[ ]?") if lang['multi']['middle']
      if lang['multi']['end']
        match[:end_multi] = Regexp.new("#{Regexp.escape(lang['multi']['end'])}")
        match[:end_multi_with] = Regexp.new("(?=#{Regexp.escape(lang['multi']['end'])}.*$)")
      end
    end

    lang[:matchers] ||= {}
    lang[:matchers].merge!(match)
  end.freeze

module_function

  # Extract comments from text
  def extract(text, options = {})
    Extractor.new(options).extract(text)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
roxie-0.0.3 lib/roxie.rb
roxie-0.0.2 lib/roxie.rb