8000 Require `runtime_dependencies` of a Gem-based theme from its `.gemspec` file by ashmaroli · Pull Request #5914 · jekyll/jekyll · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Require runtime_dependencies of a Gem-based theme from its .gemspec file #5914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 31, 2017

Conversation

ashmaroli
Copy link
Member

Have Jekyll require the runtime_dependencies of a theme-gem from its .gemspec file so that the theme's consumers need not have to edit their gems array to include plugins required by their theme.

--
/cc @jekyll/ecosystem

@ashmaroli ashmaroli changed the title Theme deps Require runtime_dependencies of a Gem-based theme from its .gemspec file Feb 28, 2017
@ashmaroli
Copy link
Member Author

Requesting a restart of the Travis build for this PR..
Thanks 😃

@parkr
Copy link
Member
parkr commented Mar 1, 2017

I couldn't load the page to trigger a restart... Try pushing another commit?

@ashmaroli
Copy link
Member Author

Try pushing another commit?

okay..

@ashmaroli
Copy link
Member Author

label: themes

Copy link
Member
@parkr parkr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine to me.

end
dependencies.each do |dep|
External.require_with_graceful_fail(dep.name) unless dep.name == "jekyll"
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify this to

site.theme.runtime_dependencies.each do |dep|
  next if dep.name == "jekyll"
  External.require_with_graceful_fail(dep.name) if plugin_allowed?(dep.name)
end

@@ -29,6 +30,15 @@ def require_gems
)
end

def require_theme_deps
if site.theme.runtime_dependencies
site.theme.runtime_dependencies.each do |dep|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to prefer guard block style, which is:

def require_theme_deps
  return false unless site.theme && site.theme.runtime_dependencies
  # ... do the actual work, expecting the above variables to exist
end

You could alternatively use #Array(), which will create an empty array if the value is nil:

def require_theme_deps
  Array(site.theme.runtime_dependencies).each do |dep|
    # ...
  end
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gez I'll go with the explicit return style instead of the alternative wherein a block is called even on an empty array.

@parkr
Copy link
Member
parkr commented Mar 9, 2017

@pathawks Any objections to the idea here?

@parkr parkr added this to the 3.5 milestone Mar 9, 2017
Copy link
Member
@pathawks pathawks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable 👍

From `v3.5`, Jekyll will automatically require all `whitelist`-ed `runtime_dependencies` of your theme-gem even if they're not explicitly included under the `gems` array in the site's config file. (NOTE: `whitelist`-ing is only required when `build`-ing or `serve`-ing with the `--safe` option.)

With this, the end-user need not keep track of the plugins required to be included in their config file for their theme-gem to work as intended.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a piece of documentation for this particular feature.
/cc @DirtyF

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ashmaroli Could we please stick to plain english instead of mixing commands and dashes to ease readability?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.
Something like this: ?

From `v3.5`, Jekyll will automatically require all whitelisted `runtime_dependencies` of
your theme-gem even if they're not explicitly included under the `gems` array in the
site's config file. (NOTE: whitelisting is only required when building or serving with the
`--safe` option.)

With this, the end-user need not keep track of the plugins required to be included in their
config file for their theme-gem to work as intended.

@ashmaroli
Copy link
Member Author
ashmaroli commented Mar 17, 2017

I just realized that this may have an unintended side-effect:
Users won't be able to disable a certain plugin if they wish to.

Scenario:
Say, a theme listed jekyll-feed as a dependency. But the user would like to use another plugin to generate their feeds. There's now no way to do so..


UPDATE:

Two possible solutions:

  1. The user should exclude jekyll-feed from the whitelist: and run the site in safe mode.
  2. We implement a blacklist: to allow the user to explicitly disable jekyll-feed and run the site in normal mode.

@pathawks
Copy link
Member

Themes should only require what they require.

If a user wants something lighter weight, they can either use a lighter theme, or fork a theme and remove the cruft.

@parkr
Copy link
Member
parkr commented Mar 31, 2017

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit 0eb9379 into jekyll:master Mar 31, 2017
jekyllbot added a commit that referenced this pull request Mar 31, 2017
@ashmaroli ashmaroli deleted the theme-deps branch March 31, 2017 19:17
@tlnagy
Copy link
tlnagy commented Jul 20, 2017

I agree with @ashmaroli here.

I just realized that this may have an unintended side-effect:
Users won't be able to disable a certain plugin if they wish to.

Here's my use case. I developed a theme for jekyll (https://github.com/tlnagy/jekyll-lab-notebook) that is more of a theme+engine. It's an electronic lab notebook engine (for biological sciences, mainly) that is a nice theme + a bunch of plugins (https://github.com/tlnagy/jekyll-lab-notebook-plugins) to make everything work well. I wanted it to be easy to set up so the theme requires the plugins gem, but now there is no way to disable the plugins. The blacklist option sounds like it could work for my situation.

@ashmaroli
Copy link
Member Author

Hi @tlnagy the consensus is that a theme should henceforth list only the very essential plugins (i.e. those without which, your theme would simply fail) as runtime_dependencies. The non-essential ones can be brought to the end-user's notice with effective documentation.
They're then free to add the non-essential plugins to their config file as required.

@jekyll jekyll locked and limited conversation to collaborators Jul 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0