Class: Daifuku::Compiler
- Inherits:
-
Object
- Object
- Daifuku::Compiler
- Defined in:
- lib/daifuku/compiler.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#compile(directory_path, options = {}) ⇒ String: Category
Compile markdowns into Ruby objects.
- #parser ⇒ Object
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/daifuku/compiler.rb', line 5 def @options end |
Instance Method Details
#compile(directory_path, options = {}) ⇒ String: Category
Compile markdowns into Ruby objects.
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 = 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 |
#parser ⇒ Object
27 28 29 |
# File 'lib/daifuku/compiler.rb', line 27 def parser @parser ||= Parser.new end |