0

I've got a directory called "posts" which is filled with .md files. Right now rdiscount renders only one file (one.md), then puts the product into a variable (@content). Because this is done issuing...

@content = markdown(:one)

...I'm really confused as to how to make ruby 1) find every file in the directory and 2) render everything using rdiscount. Any ideas?

user3094719
  • 297
  • 4
  • 16

2 Answers2

3

You can use Dir.glob to find and iterate all the Markdown files in the directory.

Dir.glob("path/to/folder/*.md") do |file|
  # do what you want with file
end
Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
1

To extend @Simone Carletti's answer, in order to answer part 2 of your question:

@content = ""
Dir.glob("path/to/folder/*.md") do |file|
  @content << markdown(file)
end
ian
  • 12,003
  • 9
  • 51
  • 107