0

I am trying to create a blog in Rails and using Markdown/Jekyll Converter, but getting an error when my markdown files contain references to variables used in my "parse file method"

The Parse Method does the following:

def parse_file
@markdown = Tilt::ErubisTemplate.new do
  fdata = file_data
  if fdata =~ /\A(---\s*\n.*?\n?)^(---\s*$\n?)/m
    logger.debug 'parsing yaml'
    @data = SafeYAML.load($1)
    logger.debug 'parsing complete'
    logger.debug @data
    logger.debug $POSTMATCH
    $POSTMATCH
  else
    fdata
  end
  logger.debug self
end.render(scope, post: self)

end

My markdown files may have code like the following:

 Show will just display the single Blog Post the user clicks on from the index to     continue reading and these details:

 ```ruby
<% @posts.each do |post| %>
<article>
<div class="summary">
 <header>
    <h1>
        <%= link_to post.title, post.path%> 
    </h1>
 </header>
<%= render partial: "meta", locals: { post: post } %>
<p><%= post.excerpt %></p>
<p><%= link_to "Continue reading →", post.path %></p>
</div>
</article>
<% end %>
```

The error is Receive when I got to here: /blog

ERROR: undefined method `each' for nil:NilClass And it highlights

end.render(scope, post: self)

end

Any ideas? It looks like when its parsing @post, it throws an error as if it doesn't know how to parse this data, but most people must deal with markdown when the code blocks have variables, don't they?

  • @muistooshort It shouldn't. It'just a code snippet to be highlighted. This shouldn't be executed at all. – D-side Sep 02 '14 at 18:30
  • @D-side So you're saying that the ERB is getting through to Erubis when it shouldn't? The Markdown processor should be escaping it which step? Wouldn't that mean that the Markdown and ERB steps are reversed? – mu is too short Sep 02 '14 at 18:42
  • @muistooshort yes, that's what I meant. It should be markdown'ed first, that ERB should end up escaped and inside `pre` tags. I never used a custom parser with Jekyll, so I'm a little lost. – D-side Sep 02 '14 at 18:57
  • D-Side is correct, the @posts is just a code excerpt that I am using in my blog that came from another project. It should be processed and inside pre tags, but for some reason ruby is throwing and error and pointing to end.render() line in parseFile() function. – Farooq Khera Sep 02 '14 at 19:02
  • So were you guys suggesting that i run the markdown first before trying to feed it in to the Erubis? – Farooq Khera Sep 03 '14 at 02:05

0 Answers0