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", }, "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
86 87 88 89 |
# File 'lib/github-pages/configuration.rb', line 86 def defaults_for_env defaults = development? ? DEFAULTS : PRODUCTION_DEFAULTS Jekyll::Utils.deep_merge_hashes Jekyll::Configuration::DEFAULTS, defaults end |
.development? ⇒ Boolean
82 83 84 |
# File 'lib/github-pages/configuration.rb', line 82 def development? Jekyll.env == "development" end |
.disable_whitelist? ⇒ Boolean
78 79 80 |
# File 'lib/github-pages/configuration.rb', line 78 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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/github-pages/configuration.rb', line 98 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") 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
74 75 76 |
# File 'lib/github-pages/configuration.rb', line 74 def processed(site) site.instance_variable_set :@_github_pages_processed, true end |
.processed?(site) ⇒ Boolean
70 71 72 |
# File 'lib/github-pages/configuration.rb', line 70 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.
122 123 124 125 126 127 |
# File 'lib/github-pages/configuration.rb', line 122 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.
131 132 133 |
# File 'lib/github-pages/configuration.rb', line 131 def set!(site) site.config = effective_config(site.config) end |