63 lines
1.5 KiB
Markdown
63 lines
1.5 KiB
Markdown
---
|
|
title: Commands
|
|
permalink: /docs/plugins/commands/
|
|
---
|
|
As of version 2.5.0, Jekyll can be extended with plugins which provide
|
|
subcommands for the `jekyll` executable. This is possible by including the
|
|
relevant plugins in a `Gemfile` group called `:jekyll_plugins`:
|
|
|
|
```ruby
|
|
group :jekyll_plugins do
|
|
gem "my_fancy_jekyll_plugin"
|
|
end
|
|
```
|
|
|
|
Each `Command` must be a subclass of the `Jekyll::Command` class and must
|
|
contain one class method: `init_with_program`. An example:
|
|
|
|
```ruby
|
|
class MyNewCommand < Jekyll::Command
|
|
class << self
|
|
def init_with_program(prog)
|
|
prog.command(:new) do |c|
|
|
c.syntax "new [options]"
|
|
c.description 'Create a new Jekyll site.'
|
|
|
|
c.option 'dest', '-d DEST', 'Where the site should go.'
|
|
|
|
c.action do |args, options|
|
|
Jekyll::Site.new_site_at(options['dest'])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
```
|
|
|
|
Commands should implement this single class method:
|
|
|
|
<div class="mobile-side-scroller">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Method</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td>
|
|
<p><code>init_with_program</code></p>
|
|
</td>
|
|
<td><p>
|
|
This method accepts one parameter, the
|
|
<code><a href="https://github.com/jekyll/mercenary#readme">Mercenary::Program</a></code>
|
|
instance, which is the Jekyll program itself. Upon the program,
|
|
commands may be created using the above syntax. For more details,
|
|
visit the Mercenary repository on GitHub.com.
|
|
</p></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|