Module: J1
- Defined in:
- lib/j1/utils/ansi.rb,
lib/j1.rb,
lib/j1/utils.rb,
lib/j1/command.rb,
lib/j1/version.rb,
lib/j1/external.rb,
lib/j1/log_helper.rb,
lib/j1/log_adapter.rb,
lib/j1/utils/exec1.rb,
lib/j1/utils/exec2.rb,
lib/j1/commands/app.rb,
lib/j1/commands/nbi.rb,
lib/j1/utils/win_tz.rb,
lib/j1/commands/help.rb,
lib/j1/commands/site.rb,
lib/j1/commands/patch.rb,
lib/j1/commands/reset.rb,
lib/j1/commands/setup.rb,
lib/j1/utils/platforms.rb,
lib/j1/commands/rebuild.rb,
lib/j1/commands/generate.rb
Overview
require “futils”
Defined Under Namespace
Modules: Commands, External, Utils Classes: Command, LogAdapter, LogHelper
Constant Summary collapse
- VERSION =
'2024.3.15'
Class Method Summary collapse
-
.configuration(override = {}) ⇒ Object
Public: Generate a J1 configuration Hash by merging the default options with anything in _config.yml, and adding the given options on top.
-
.env ⇒ Object
Public: Tells you which J1 environment you are building in so you can skip tasks if you need to.
-
.logger ⇒ Object
Public: Fetch the logger instance for this J1 process.
-
.logger=(writer) ⇒ Object
Public: Set the log writer.
-
.sanitized_path(base_directory, questionable_path) ⇒ Object
Public: Ensures the questionable path is prefixed with the base directory and prepends the questionable path with the base directory if false.
-
.set_timezone(timezone) ⇒ Object
Public: Set the TZ environment variable to use the timezone specified.
-
.sites ⇒ Object
Public: An array of sites.
Class Method Details
.configuration(override = {}) ⇒ Object
Public: Generate a J1 configuration Hash by merging the default options with anything in _config.yml, and adding the given options on top.
override - A Hash of config directives that override any options in both
the defaults and the config file.
See J1::Configuration::DEFAULTS for a
list of option names and their defaults.
Returns the final configuration Hash.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/j1.rb', line 57 def configuration(override = {}) config = Configuration.new override = Configuration[override].stringify_keys unless override.delete('skip_config_files') config = config.read_config_files(config.config_files(override)) end # Merge DEFAULTS < _config.yml < override Configuration.from(Utils.deep_merge_hashes(config, override)).tap do |obj| set_timezone(obj['timezone']) if obj['timezone'] end end |
.env ⇒ Object
Public: Tells you which J1 environment you are building in so you can skip tasks if you need to. This is useful when doing expensive compression tasks on css and images and allows you to skip that when working in development.
43 44 45 |
# File 'lib/j1.rb', line 43 def env ENV['JEKYLL_ENV'] || 'development' end |
.logger ⇒ Object
Public: Fetch the logger instance for this J1 process.
Returns the LogAdapter instance
86 87 88 |
# File 'lib/j1.rb', line 86 def logger @logger ||= LogAdapter.new(LogHelper.new, (ENV['J1_LOG_LEVEL'] || :info).to_sym) end |
.logger=(writer) ⇒ Object
Public: Set the log writer.
New log writer must respond to the same methods
as Ruby's interal Logger.
writer - the new Logger-compatible log transport
Returns the new logger
98 99 100 |
# File 'lib/j1.rb', line 98 def logger=(writer) @logger = LogAdapter.new(writer, (ENV['J1_LOG_LEVEL'] || :info).to_sym) end |
.sanitized_path(base_directory, questionable_path) ⇒ Object
Public: Ensures the questionable path is prefixed with the base directory
and prepends the questionable path with the base directory if false.
base_directory - the directory with which to prefix the questionable path questionable_path - the path we’re unsure about, and want prefixed
Returns the sanitized path
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/j1.rb', line 118 def sanitized_path(base_directory, questionable_path) return base_directory if base_directory.eql?(questionable_path) questionable_path.insert(0, '/') if questionable_path.start_with?('~') clean_path = File.(questionable_path, '/') return clean_path if clean_path.eql?(base_directory) if clean_path.start_with?(base_directory.sub(/\z/, '/')) clean_path else clean_path.sub!(%r{\A\w:/}, '/') File.join(base_directory, clean_path) end end |
.set_timezone(timezone) ⇒ Object
Public: Set the TZ environment variable to use the timezone specified
timezone - the IANA Time Zone
Returns nothing rubocop:disable Style/AccessorMethodName
77 78 79 |
# File 'lib/j1.rb', line 77 def set_timezone(timezone) ENV['TZ'] = timezone end |
.sites ⇒ Object
Public: An array of sites
Returns the J1 sites created
106 107 108 |
# File 'lib/j1.rb', line 106 def sites @sites ||= [] end |