# Creating Theme Gems

**URL:** <https://talk.jekyllrb.com/t/creating-theme-gems/8143>\
**Category:** Help\
**Created:** [April 5, 2023, 9:56pm UTC](https://talk.jekyllrb.com/t/creating-theme-gems/8143 "2023-04-05T21:56:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leatheresque](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/leatheresque/32/5269_2.png) [@leatheresque](https://talk.jekyllrb.com/u/leatheresque)\
**Post date:** [April 5, 2023, 9:56pm UTC](https://talk.jekyllrb.com/t/creating-theme-gems/8143/1 "2023-04-05T21:56:11Z")

</div>

I need some help understanding the theme creation process when it comes to gems.

**Hypothetical**

I create a directory `/mytheme` inside here I have all the usual Jekyll stuff. a user can use this as is by using it as a template on gh-pages and it works as expected.

I now want to make this into a “gem” for others to use.

- In `/mytheme` I do `bundle gem jekyll-mytheme` (Now I have a new directory in mytheme named jekyll-mytheme)
- In `/jekyll-mytheme` I have `/lib`, `/bin`, `/sig` and a few other files I expect.
- Following the Rubygems guide “Creating Your First Gem” leads me to suspect the files to places in `/lib` are programmatic files not simple HTML / CSS etc?
- I need to include my basic theme files now that will ship

So do I place all of them in the `/jekyll-mytheme` root along with the README etc or in `lib` or what? I understand I need to include the reference to where they will be in `s.files` but where should I be placing them? Does it matter? As long as I tell `s.files` where to find them? Or is there a proper methodology to this?

**tl;dr** Where do I put files I want to ship with my gem?

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [April 6, 2023, 6:03am UTC](https://talk.jekyllrb.com/t/creating-theme-gems/8143/2 "2023-04-06T06:03:09Z")

</div>

Hello @leatheresque,  
The Rubygems guide is for creating gems composed of Ruby code. Jekyll theme-gems are a different beast altogether.  
Converting an existing Jekyll theme into a theme-gem is actually a simple process but slightly confusing for new authors.  
As of Jekyll 4.3, the `jekyll` executable can be used to **scaffold a theme-gem from scratch**. The executable recognizes a command named `new-theme`, which takes a mandatory argument, the theme-gem-name. For example, when you run `jekyll new-theme foobar`, Jekyll creates the directory `./foobar` that contains everything expected from a theme-gem. The most important file is the `[theme-name].gemspec` (i.e. `foobar.gemspec`).  
This file determines the constitution of the built gem.  
The regex at `spec.files` filters the contents of the theme-gem.

Jekyll loads only specific theme-gem directories and files regardless of configuration. They’re `_layouts`, `_includes`, `_sass` and `assets`. Recent versions of Jekyll also _support_ loading `_data` and a file `_config.yml`. Every other top-level folder / file will be ignored.

There are no restrictions on individual filenames though. Your layouts, sass partials or assets can be named whatever you want.

* * *

Now since you are familiar with setting up a theme-gem from scratch, let’s move on converting an existing theme into a gem.

Assuming that the folder names are as noted above, you need to just add the `[theme-gem-name].gemspec` file, a License file and you should be good to go. Since there is no means to generate just a gemspec file, the workaround would be to run `jekyll new-theme <...>` elsewhere, copy the scaffolded License file and gemspec  
file from that location into your theme project directory and make necessary edits.

---

<div class="post-metadata">

**Author:** ![leatheresque](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/leatheresque/32/5269_2.png) [@leatheresque](https://talk.jekyllrb.com/u/leatheresque)\
**Post date:** [April 6, 2023, 3:51pm UTC](https://talk.jekyllrb.com/t/creating-theme-gems/8143/3 "2023-04-06T15:51:52Z")

</div>

> [@ashmaroli](#):
>
> you need to just add the `[theme-gem-name].gemspec` file, a License file and you should be good to go.

So after I create a theme I don’t need to use the `bundle gem mytheme`? just create a gemspec file and push to rubygems? I will play around with the `jekyll new-theme` command and see how it works. I guess the process of creating a theme outside of a site and then adding it to a site confuses me a bit opposed to creating a site with its theme and then that site is the theme?

I appreciate the response. I just need to understand better and the docs are not really helpful at times.

---

<div class="post-metadata">

**Author:** ![ashmaroli](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ashmaroli](https://talk.jekyllrb.com/u/ashmaroli)\
**Post date:** [April 10, 2023, 3:26pm UTC](https://talk.jekyllrb.com/t/creating-theme-gems/8143/4 "2023-04-10T15:26:09Z")

</div>

> [@leatheresque](#):
>
> So after I create a theme I don’t need to use the `bundle gem mytheme`?

Correct. That procedure is applicable only for gems of Ruby programs.

> [@leatheresque](#):
>
> just create a gemspec file and push to rubygems?

No. First you need to create a gemspec (as generated via `jekyll new-theme ...`), make necessary changes as applicable for your theme, and then when you’re ready to _publish_ your theme (pushing to Rubygems site), you need to first **build** the gem (same process as in the Rubygems tutorial you looked up) and then push the built gem.

---

<div class="post-metadata">

**Author:** ![leatheresque](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/leatheresque/32/5269_2.png) [@leatheresque](https://talk.jekyllrb.com/u/leatheresque)\
**Post date:** [April 10, 2023, 3:27pm UTC](https://talk.jekyllrb.com/t/creating-theme-gems/8143/5 "2023-04-10T15:27:35Z")

</div>

That helps. Thank you
