module Yarrow::Format
Constants
- Registry
Public Class Methods
read(name)
click to toggle source
Pass in a source path and get back a parsed representation of the content if it is in a known text format. Mostly used as a fallback if a custom parser or processing chain is not configured for a content type.
# File lib/yarrow/format.rb, line 43 def self.read(name) path = if name.is_a?(Pathname) name else Pathname.new(name) end # case path.extname # when '.htm', '.md', '.txt', '.yfm' # Markdown.read(path) # when '.yml' # [nil, YAML.load(File.read(path.to_s), symbolize_names: true)] # when '.json' # [nil, JSON.parse(File.read(path.to_s))] # end unless Registry.key?(path.extname) raise "Unsupported format: #{path.extname} (#{path})" end Registry[path.extname].read(path) end