Giter Site home page Giter Site logo

waiting-for-dev / front_matter_parser Goto Github PK

View Code? Open in Web Editor NEW
101.0 3.0 12.0 120 KB

Ruby library to parse files or strings with a front matter. It has automatic syntax detection.

License: MIT License

Ruby 99.14% Shell 0.43% Dockerfile 0.43%
front-matter-parser frontmatter ruby-gem

front_matter_parser's Introduction

FrontMatterParser

Gem Version Build Status Code Climate Test Coverage

FrontMatterParser is a library to parse a front matter from strings or files. It allows writing syntactically correct source files, marking front matters as comments in the source file language.

Installation

Add this line to your application's Gemfile:

gem 'front_matter_parser'

or, to get the development version:

gem 'front_matter_parser', github: 'waiting-for-dev/front_matter_parser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install front_matter_parser

Usage

Front matters must be between two lines with three dashes ---.

For example, given a file example.md:

---
title: Hello World
category: Greetings
---
Some actual content

You can parse it:

parsed = FrontMatterParser::Parser.parse_file('example.md')
parsed.front_matter #=> {'title' => 'Hello World', 'category' => 'Greetings'}
parsed.content #=> 'Some actual content'

You can directly apply [] method to get a front matter value:

parsed['category'] #=> 'Greetings'

Syntax autodetection

FrontMatterParser detects the syntax of a file by its extension and it supposes that the front matter is within that syntax comment delimiters.

For example, given a file example.haml:

-#
   ---
   title: Hello
   ---
Content

The -# and the indentation enclose the front matter as a comment. FrontMatterParser is aware of that, so you can simply do:

title = FrontMatterParser::Parser.parse_file('example.haml')['title'] #=> 'Hello'

Following there is a relation of known syntaxes and their known comment delimiters:

Syntax Single line comment Start multiline comment End multiline comment
haml -# (indentation)
slim / (indentation)
liquid {% comment %} {% endcomment %}
md
html <!-- -->
erb <%# %>
coffee #
sass //
scss //

Parsing a string

You can as well parse a string providing manually the syntax:

string = File.read('example.slim')
FrontMatterParser::Parser.new(:slim).call(string)

Custom parsers

You can implement your own parsers for other syntaxes. Most of the times, they will need to parse a syntax with single line comments, multi line comments or closed by indentation comments. For these cases, this library provides helper factory methods. For example, if they weren't already implemented, you could do something like:

CoffeeParser = FrontMatterParser::SyntaxParser::SingleLineComment['#']
HtmlParser = FrontMatterParser::SyntaxParser::MultiLineComment['<!--', '-->']
SlimParser = FrontMatterParser::SyntaxParser::IndentationComment['/']

You would use them like this:

slim_parser = SlimParser.new

# For a file
FrontMatterParser::Parser.parse_file('example.slim', syntax_parser: slim_parser)

# For a string
FrontMatterParser::Parser.new(slim_parser).call(string)

For more complex scenarios, a parser can be anything responding to a method call(string) which returns a hash interface with :front_matter and :content keys, or nil if no front matter is found.

Custom loaders

Once a front matter is matched from a string, it is loaded as if it were a YAML text. However, you can also implement your own loaders. They just need to implement a call(string) method. You would use it like the following:

json_loader = ->(string) { JSON.load(string) }

# For a file
FrontMatterParser::Parser.parse_file('example.md', loader: json_loader)

# For a string
FrontMatterParser::Parser.new(:md, loader: json_loader).call(string)

If you need to allow one or more classes for the built-in YAML loader, you can just create a custom loader based on it and provide needed classes in a allowlist_classes: param:

loader = FrontMatterParser::Loader::Yaml.new(allowlist_classes: [Time])
parsed = FrontMatterParser::Parser.parse_file('example.md', loader: loader)
puts parsed['timestamp']

Development

There are docker and docker-compose files configured to create a development environment for this gem. So, if you use Docker you only need to run:

docker-compose up -d

An then, for example:

docker-compose exec app rspec

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Release Policy

front_matter_parser follows the principles of semantic versioning.

Other ruby front matter parsers

  • front-matter Can parse YAML front matters with single line comments delimiters. YAML must be correctly indented.
  • ruby_front_matter Can parse JSON front matters and can configure front matter global delimiters, but does not accept comment delimiters.

LICENSE

Copyright 2013 Marc Busqué - [email protected]

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

front_matter_parser's People

Contributors

aviflombaum avatar chris-huxtable avatar mange avatar mrrusof avatar waiting-for-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

front_matter_parser's Issues

Front matter data in documents without content parsed as content

For a document that contains only a front matter block but no content, FrontMatterParser returns the front matter data as content:

FrontMatterParser::Parser.new(:md).call("---\ntest: 1\n---")
 => #<FrontMatterParser::Parsed:0x0000000128c1d008 @front_matter={}, @content="---\ntest: 1\n---">

(Adding just a single newline after the block makes it parse correctly)

Failures when front matter contains dates

When I try to parse a doc that looks like this:

---
title: Another test
date: 2022-06-04
---

Test

It fails with:

Psych::DisallowedClass in PostsController#index
Tried to load unspecified class: Date

Full trace:

[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/class_loader.rb:97:in `find'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/class_loader.rb:28:in `load'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/class_loader.rb:39:in `block (2 levels) in <class:ClassLoader>'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/scalar_scanner.rb:60:in `tokenize'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:60:in `deserialize'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:123:in `visit_Psych_Nodes_Scalar'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:340:in `block in revive_hash'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:338:in `each'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:338:in `each_slice'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:338:in `revive_hash'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:162:in `visit_Psych_Nodes_Mapping'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:313:in `visit_Psych_Nodes_Document'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'](http://localhost:3000/posts/#)
[/Users/cjavilla/.rbenv/versions/2.7.2/lib/ruby/2.7.0/psych.rb:360:in `safe_load'](http://localhost:3000/posts/#)
[front_matter_parser (1.0.1) lib/front_matter_parser/loader/yaml.rb:22:in `call'](http://localhost:3000/posts/#)
[front_matter_parser (1.0.1) lib/front_matter_parser/parser.rb:67:in `call'](http://localhost:3000/posts/#)
[front_matter_parser (1.0.1) lib/front_matter_parser/parser.rb:25:in `block in parse_file'](http://localhost:3000/posts/#)
[front_matter_parser (1.0.1) lib/front_matter_parser/parser.rb:24:in `open'](http://localhost:3000/posts/#)
[front_matter_parser (1.0.1) lib/front_matter_parser/parser.rb:24:in `parse_file'](http://localhost:3000/posts/#)
[app/controllers/posts_controller.rb:8:in `block in index'](http://localhost:3000/posts/#)
[app/controllers/posts_controller.rb:7:in `map'](http://localhost:3000/posts/#)
[app/controllers/posts_controller.rb:7:in `index'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/abstract_controller/base.rb:220:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal/rendering.rb:53:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/abstract_controller/callbacks.rb:249:in `block in process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/callbacks.rb:118:in `block in run_callbacks'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actiontext/lib/action_text/rendering.rb:20:in `with_renderer'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actiontext/lib/action_text/engine.rb:71:in `block (4 levels) in <class:Engine>'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/callbacks.rb:127:in `instance_exec'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/callbacks.rb:127:in `block in run_callbacks'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/callbacks.rb:138:in `run_callbacks'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/abstract_controller/callbacks.rb:248:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal/rescue.rb:22:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/notifications.rb:206:in `block in instrument'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/notifications.rb:206:in `instrument'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal/instrumentation.rb:66:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal/params_wrapper.rb:259:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activerecord/lib/active_record/railties/controller_runtime.rb:27:in `process_action'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/abstract_controller/base.rb:156:in `process'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionview/lib/action_view/rendering.rb:39:in `process'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal.rb:204:in `dispatch'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_controller/metal.rb:267:in `dispatch'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/routing/route_set.rb:49:in `dispatch'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/routing/route_set.rb:32:in `serve'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/journey/router.rb:50:in `block in serve'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/journey/router.rb:32:in `each'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/journey/router.rb:32:in `serve'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/routing/route_set.rb:852:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/tempfile_reaper.rb:15:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/etag.rb:27:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/conditional_get.rb:27:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/head.rb:12:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/http/permissions_policy.rb:38:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/http/content_security_policy.rb:36:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/session/abstract/id.rb:266:in `context'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/session/abstract/id.rb:260:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/cookies.rb:698:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activerecord/lib/active_record/migration.rb:612:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/callbacks.rb:99:in `run_callbacks'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/callbacks.rb:26:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/executor.rb:14:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'](http://localhost:3000/posts/#)
[web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'](http://localhost:3000/posts/#)
[web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'](http://localhost:3000/posts/#)
[web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'](http://localhost:3000/posts/#)
[web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) railties/lib/rails/rack/logger.rb:37:in `call_app'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) railties/lib/rails/rack/logger.rb:24:in `block in call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/tagged_logging.rb:114:in `block in tagged'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/tagged_logging.rb:38:in `tagged'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/tagged_logging.rb:114:in `tagged'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) railties/lib/rails/rack/logger.rb:24:in `call'](http://localhost:3000/posts/#)
[sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/remote_ip.rb:92:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/request_id.rb:26:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/method_override.rb:24:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/runtime.rb:22:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) activesupport/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/server_timing.rb:20:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/executor.rb:14:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/static.rb:23:in `call'](http://localhost:3000/posts/#)
[rack (2.2.4) lib/rack/sendfile.rb:110:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) actionpack/lib/action_dispatch/middleware/host_authorization.rb:138:in `call'](http://localhost:3000/posts/#)
[rails (a3475f07ccb0) railties/lib/rails/engine.rb:529:in `call'](http://localhost:3000/posts/#)
[puma (5.6.4) lib/puma/configuration.rb:252:in `call'](http://localhost:3000/posts/#)
[puma (5.6.4) lib/puma/request.rb:77:in `block in handle_request'](http://localhost:3000/posts/#)
[puma (5.6.4) lib/puma/thread_pool.rb:340:in `with_force_shutdown'](http://localhost:3000/posts/#)
[puma (5.6.4) lib/puma/request.rb:76:in `handle_request'](http://localhost:3000/posts/#)
[puma (5.6.4) lib/puma/server.rb:441:in `process_client'](http://localhost:3000/posts/#)
[puma (5.6.4) lib/puma/thread_pool.rb:147:in `block in spawn_thread'](http://localhost:3000/posts/#)

This is my PostsController:

class PostsController < ApplicationController

  def index
    files = Dir.glob(File.join(Rails.root, "posts", "*.md"))
    @posts = files.map do |f|
      parsed = FrontMatterParser::Parser.parse_file(f)
      Post.new(f, parsed.front_matter)
    end
  end

My goal is to iterate over my blog posts, authored in markdown with front matter that contains title and date and render a simple list. My bet is we need to pass some permitted classes to the yaml loader?

This conversation seems relevant: ruby/psych#262

Date parsing fails

I have frontmatter like this:

---
title: 'cool title'
date: 2012-01-11
categories: foo
---

This fails with:

FrontMatterParser::Parser.parse_file(str)
#=> Psych::DisallowedClass: Tried to load unspecified class: Date

I'm pretty sure the root cause is ruby/psych#262 and that the parser is attempting to run Date.new('2012-01-11'), but I haven't nailed it down yet.

I might be able to write a customer parser to overwrite how the frontmatter is being parsed, I guess?

Was wondering if there was a different solution or if anyone had any insight?

License clarification

Is this gem under the MIT license?

I see that there are 3 different license files in the root folders and I don't know why.

Would it make sense to keep only the MIT license and remove the other files if they are not relevant?

Parser can be too greedy sometimes

Hi @waiting-for-dev!

I'm building a Rails app that parses and displays Jekyll-style pages: Markdown files with YAML front matter. I'm using this gem to parse the front matter from the pages into @page.data and I assign the rest of the content to @page.content.

A problem comes up when any of my pages have a sequence of three hyphens in them ---. FrontMatterParser will always read until the last sequence of --- in the file instead of stopping at the --- after the front matter like I expect it to.

For example, if I have this file:

---
title: About email notifications
---

This is the page about email notifications

The parser works as expected; I get @page.data = { title: 'About email notifications' } and @page.content = 'This is the page about email notifications'.

But if the file has a sequence of three hyphens:

---
title: About email notifications
---

In some cases. you might receive a plain-text email like this:

------------- Warning -------------
Your credit card is about to expire!

The parser gives me @page.data = { title: 'About email notifications' } but @page.content = 'Your credit card is about to expire!'

Is there a way to make the parser less greedy, and stop it from gobbling all my page content if the content contains sequences of hyphens?

Bring back .parse

I would love if I could call parse on a string, which doesn't seem to work with the new rewrite. I tried the following three, and all throw exceptions.

FrontMatterParser.parse(body)
prsr = FrontMatterParser::Parser.new(:slim)
fmp = prsr.parse(body)
FrontMatterParser::Parser.parse(body)

Jekyll: undefined method `to_liquid'

Jekyll 3.6.2
Ruby 2.4.1

I'm running into this error when using this with Jekyll. Can't seem to lock down the issue.

Liquid Exception: undefined method to_liquid' for #FrontMatterParser::Parsed:0x007fa26ea88f78...`

Here is the code I'm trying to execute as a Liquid filter in parse_fm.rb

require "front_matter_parser"

module Jekyll
  module ParseFM

    par = ""
    def frontm(string = '')
      par = FrontMatterParser::Parser.new(:md).call(string)
    end
    par
  end
end

Liquid::Template.register_filter(Jekyll::ParseFM)

I'm using it in a liquid template {{yaml | frontm}}

I am simply trying to pass a string like below:

--- blog: https://example.com/page1 background-img: https://example.com/files/image.jpg buttonText: Download download: true---

bin/* creates conflicts

The files in the bin folder should probably not be included in the final gem, as these seem to be intended for development only.

spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }

Since there are other offending gems that have binaries with the same name, when installing either of them, users get this error:

front_matter_parser's executable "console" conflicts with request-log-analyzer
Overwrite the executable? [yN]  n
ERROR:  Error installing eucalypt:
        "console" from front_matter_parser conflicts with installed executable from request-log-analyzer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.