Class: Daifuku::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/daifuku/compiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/daifuku/compiler.rb', line 5

def options
  @options
end

Instance Method Details

#compile(directory_path, options = {}) ⇒ String: Category

Compile markdowns into Ruby objects.

Parameters:

  • String Directory path containing log definitions.

  • (defaults to: {})

    Compiler options

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/daifuku/compiler.rb', line 11

def compile(directory_path, options = {})
  @options = options
  categories = Dir.entries(directory_path).map do |file|
    if file.end_with?('.md')
      category_name = File.basename(file, '.md')
      path = File.join(directory_path, file)
      # This situation implicates missing LANG, use UTF-8 by default.
      enc = (Encoding.default_external == Encoding::US_ASCII) ? Encoding::UTF_8 : Encoding.default_external
      str = File.read(path, encoding: enc)
      parser.parse(str, category_name)
    end
  end.compact.map { |category| [category.name, category] }.to_h
  validator.validate!(categories)
  categories
end

#parserObject



27
28
29
# File 'lib/daifuku/compiler.rb', line 27

def parser
  @parser ||= Parser.new
end