2

So I have this idea for a RubyGem that I think would be an awesome experience to learn more about Ruby and Rails but...I have no idea where to start.

My idea is to generate a folder "articles" where you can put markdown files. From this folder the main blog page displays only the titles as links to the articles themselves.

It sounds simple but I honestly have no idea where to start. What articles do you recommend I read if I want to insert lines into routes.rb, generate a folder and display markdown in Rails?

Tamachan87
  • 277
  • 5
  • 11

4 Answers4

3

I would recommend one of these tutorials for gem creation:

To modify the routes.rb file, you'll just need File.open to read lines in. Use regular expressions to determine where you want to insert your line, and write the file back out.

To create a folder, look at the documentation for Dir.new

For Markdown in Ruby/Rails, I like the rdiscount gem: https://github.com/rtomayko/rdiscount

Railties provide a nice way to do certain things like this. You'll probably use http://api.rubyonrails.org quite a bit. There is some Railtie documentation on that site here: http://api.rubyonrails.org/classes/Rails/Railtie.html.

dontangg
  • 4,729
  • 1
  • 26
  • 38
3

I recommend reading the RubyGems guides – especially What is a gem?, Make your own gem and Patterns.

Since you're likely already using Bundler, you can run bundle gem <name> to generate a gem project with stuff already in place. It does save work, but refer to the guides if there's something you don't understand.

Also, watch some open source projects on GitHub – observing other developers and taking note of how they do things certainly helps.

Matheus Moreira
  • 17,106
  • 3
  • 68
  • 107
1

The simplest way is probably to read other gems that do anything similar to what you want to accomplish. Start with their .gemspec files that will list all the other files which are needed for the gem to work, and a list of gem dependencies.

Anil
  • 3,899
  • 1
  • 20
  • 28
1

Responding more to how to get started with creating gems, the following are 2 popular, documented gems that can help you.

  1. https://github.com/seattlerb/hoe
  2. https://github.com/technicalpickles/jeweler

Also, though it does more than you're trying to do with your gem (it's a static site generator), https://github.com/mojombo/jekyll is a very popular gem which you place .markdown files into a posts/ directory which are converted to static HTML pages via rake. I would imagine you could find at least some functionality you're after there.

deefour
  • 34,974
  • 7
  • 97
  • 90