Module: Yarrow::Format

Defined in:
lib/yarrow/format.rb,
lib/yarrow/format/yaml.rb,
lib/yarrow/format/markdown.rb,
lib/yarrow/format/methods/metadata.rb,
lib/yarrow/format/methods/front_matter.rb

Defined Under Namespace

Modules: Methods Classes: ContentType, Contents, Markdown, Yaml

Constant Summary collapse

Registry =
{}

Class Method Summary collapse

Class Method Details

.read(name) ⇒ Object

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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