Help Building A Basic Gem


#1

:grinning: Hello! I am seeking #Ruby help so I can make my own Jekyll themes.

stages-MacBook:ciao stage$ irb

irb(main):001:0> require ‘ciao’

Traceback (most recent call last):

4: from /Users/stage/.rbenv/versions/2.5.3/bin/irb:11:in `<main>’

3: from (irb):1

2: from /Users/stage/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require’

1: from /Users/stage/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require’

LoadError ( cannot load such file – ciao )

Why can irb not find this poor little gem? :gem:


#2

@hopranch First of all, I’d like to inform you that Jekyll’s theme-gems are actually pseudo-gems — they do not contain Ruby code!!
Jekyll theme-gems are just a regular site (minus the “content”) packaged into a gem.
Since they do not contain Ruby Code, you can “load” them in irb

Jekyll provides you with a sub-command to bootstrap a theme-gem: new-theme
It is run as:

bundle exec jekyll new-theme mytheme

Running the above command will provide you with the necessary files and folders to create a theme-gem named “mytheme”
Once you’re done developing the gem, edit the generated mytheme.gemspec as necessary and build the gem like documented in the Rubygems Guide:

gem build mytheme.gemspec

#3

@DavidDarnes has a cool blog post on how to create a theme for Jekyll

you can create a theme with jekyll new-theme and it will create a default gemspec file for you to modify.

When your theme is ready, gem build and gem push should to the trick.

This is all documented here: https://jekyllrb.com/docs/themes/#creating-a-gem-based-theme

You can also use default gem tasks by adding this in your Rakefile

require "bundler/gem_tasks"

And then run bundler exec rake release to release a new version of your gem, when you’ve commited your changes. It’ll create a tag based on the version and push your gem to rubygems.