Class: GitHubPages::Configuration
- Inherits:
-
Object
- Object
- GitHubPages::Configuration
- Defined in:
- lib/github-pages/configuration.rb
Overview
Sets and manages Jekyll configuration defaults and overrides
Constant Summary collapse
- DEFAULT_PLUGINS =
Backward compatability of constants
GitHubPages::Plugins::DEFAULT_PLUGINS
- PLUGIN_WHITELIST =
GitHubPages::Plugins::PLUGIN_WHITELIST
- DEVELOPMENT_PLUGINS =
GitHubPages::Plugins::DEVELOPMENT_PLUGINS
- THEMES =
GitHubPages::Plugins::THEMES
- DEFAULTS =
Default, user overwritable options
{ "jailed" => false, "plugins" => GitHubPages::Plugins::DEFAULT_PLUGINS, "future" => true, "theme" => "jekyll-theme-primer", "markdown" => "kramdown", "kramdown" => { "input" => "GFM", "hard_wrap" => false, "gfm_quirks" => "paragraph_end", "syntax_highlighter_opts" => { "default_lang" => "plaintext", }, }, "exclude" => ["CNAME"], }.freeze
- PRODUCTION_DEFAULTS =
User-overwritable defaults used only in production for practical reasons
Jekyll::Utils.deep_merge_hashes DEFAULTS, { "sass" => { "style" => "compressed", }, }.freeze
- OVERRIDES =
Options which GitHub Pages sets, regardless of the user-specified value
The following values are also overridden by GitHub Pages, but are not overridden locally, for practical purposes:
-
source
-
destination
-
jailed
-
verbose
-
incremental
-
GH_ENV
-
{ "lsi" => false, "safe" => true, "plugins_dir" => SecureRandom.hex, "whitelist" => GitHubPages::Plugins::PLUGIN_WHITELIST, "highlighter" => "rouge", "kramdown" => { "template" => "", "math_engine" => "mathjax", "syntax_highlighter" => "rouge", }, "gist" => { "noscript" => false, }, }.freeze
- CONFIGS_WITH_METHODS =
These configuration settings have corresponding instance variables on Jekyll::Site and need to be set properly when the config is updated.
%w( safe lsi highlighter baseurl exclude include future unpublished show_drafts limit_posts keep_files ).freeze
Class Method Summary collapse
- .defaults_for_env ⇒ Object
- .development? ⇒ Boolean
- .disable_whitelist? ⇒ Boolean
-
.effective_config(user_config) ⇒ Object
Given a user’s config, determines the effective configuration by building a user configuration sandwhich with our overrides overriding the user’s specified values which themselves override our defaults.
- .processed(site) ⇒ Object
- .processed?(site) ⇒ Boolean
-
.set(site) ⇒ Object
Set the site’s configuration.
-
.set!(site) ⇒ Object
Set the site’s configuration with all the proper defaults and overrides.
Class Method Details
.defaults_for_env ⇒ Object
89 90 91 92 |
# File 'lib/github-pages/configuration.rb', line 89 def defaults_for_env defaults = development? ? DEFAULTS : PRODUCTION_DEFAULTS Jekyll::Utils.deep_merge_hashes Jekyll::Configuration::DEFAULTS, defaults end |
.development? ⇒ Boolean
85 86 87 |
# File 'lib/github-pages/configuration.rb', line 85 def development? Jekyll.env == "development" end |
.disable_whitelist? ⇒ Boolean
81 82 83 |
# File 'lib/github-pages/configuration.rb', line 81 def disable_whitelist? development? && !ENV["DISABLE_WHITELIST"].to_s.empty? end |
.effective_config(user_config) ⇒ Object
Given a user’s config, determines the effective configuration by building a user configuration sandwhich with our overrides overriding the user’s specified values which themselves override our defaults.
Returns the effective Configuration
Note: this is a highly modified version of Jekyll#configuration
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/github-pages/configuration.rb', line 101 def effective_config(user_config) # Merge user config into defaults config = Jekyll::Utils.deep_merge_hashes(defaults_for_env, user_config) .fix_common_issues .add_default_collections # Allow theme to be explicitly disabled via "theme: null" config["theme"] = user_config["theme"] if user_config.key?("theme") migrate_theme_to_remote_theme(config) exclude_cname(config) # Merge overwrites into user config config = Jekyll::Utils.deep_merge_hashes config, OVERRIDES restrict_and_config_markdown_processor(config) configure_plugins(config) config end |
.processed(site) ⇒ Object
77 78 79 |
# File 'lib/github-pages/configuration.rb', line 77 def processed(site) site.instance_variable_set :@_github_pages_processed, true end |
.processed?(site) ⇒ Boolean
73 74 75 |
# File 'lib/github-pages/configuration.rb', line 73 def processed?(site) site.instance_variable_get(:@_github_pages_processed) == true end |
.set(site) ⇒ Object
Set the site’s configuration. Implemented as an after_reset hook. Equivalent #set! function contains the code of interest. This function guards against double-processing via the value in #processed.
126 127 128 129 130 131 132 |
# File 'lib/github-pages/configuration.rb', line 126 def set(site) return if processed? site debug_print_versions set!(site) processed(site) end |
.set!(site) ⇒ Object
Set the site’s configuration with all the proper defaults and overrides. Should be called by #set to protect against multiple processings.
136 137 138 |
# File 'lib/github-pages/configuration.rb', line 136 def set!(site) site.config = effective_config(site.config) end |