Merge pull request #7927 from AninditaBasu/patch-2

Update generators.md
This commit is contained in:
Frank Taillandier 2019-12-05 16:03:34 +01:00 committed by GitHub
commit c8b6b806e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -20,11 +20,11 @@ and are available via `site.pages`. Static files become instances of
and are available via `site.static_files`. See and are available via `site.static_files`. See
[the Variables documentation page](/docs/variables/) and [the Variables documentation page](/docs/variables/) and
[`Jekyll::Site`]({{ site.repository }}/blob/master/lib/jekyll/site.rb) [`Jekyll::Site`]({{ site.repository }}/blob/master/lib/jekyll/site.rb)
for more details. for details.
For instance, a generator can inject values computed at build time for template For instance, a generator can inject values computed at build time for template
variables. In the following example the template `reading.html` has two variables. In the following example, the template `reading.html` has two
variables `ongoing` and `done` that we fill in the generator: variables `ongoing` and `done` that are filled in the generator:
```ruby ```ruby
module Reading module Reading
@ -40,7 +40,7 @@ module Reading
end end
``` ```
This is a more complex generator that generates new pages: The following example is a more complex generator that generates new pages. In this example, the generator will create a series of files under the `categories` directory for each category, listing the posts in each category using the `category_index.html` layout.
```ruby ```ruby
module Jekyll module Jekyll
@ -76,11 +76,7 @@ module Jekyll
end end
``` ```
In this example, our generator will create a series of files under the Generators need to implement only one method:
`categories` directory for each category, listing the posts in each category
using the `category_index.html` layout.
Generators are only required to implement one method:
<div class="mobile-side-scroller"> <div class="mobile-side-scroller">
<table> <table>
@ -102,3 +98,7 @@ Generators are only required to implement one method:
</tbody> </tbody>
</table> </table>
</div> </div>
If your generator is contained within a single file, it can be named whatever you want but it should have an `.rb` extension. If your generator is split across multiple files, it should be packaged as a Rubygem to be published at https://rubygems.org/. In this case, the name of the gem depends on the availability of teh name at that site because no two gems can have the same name.
By default, Jekyll looks for generators in the `_plugins` directory. However, you can change the default directory by assigning the desired name to the key `plugins_dir` in the config file.