module Bridgetown
Public: Methods that generate a URL
for a resource such as a Post or a Page
.
Examples
URL.new({ :template => /:categories/:title.html", :placeholders => {:categories => "ruby", :title => "something"} }).to_s
Constants
- CODE_NAME
- VERSION
Public Class Methods
Generate a Bridgetown
configuration hash by merging the default
options with anything in bridgetown.config.yml, and adding the given options on top.
@param override [Hash] - A an optional hash of config directives that override
any options in both the defaults and the config file. See {Bridgetown::Configuration::DEFAULTS} for a list of option names and their defaults.
@return [Hash] The final configuration hash.
# File lib/bridgetown-core.rb, line 156 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 < bridgetown.config.yml < override Configuration.from(Utils.deep_merge_hashes(config, override)).tap do |obj| set_timezone(obj["timezone"]) if obj["timezone"] end end
Tells you which Bridgetown
environment you are building in so
you can skip tasks if you need to.
# File lib/bridgetown-core.rb, line 141 def environment (ENV["BRIDGETOWN_ENV"] || "development").inquiry end
Fetch the logger instance for this Bridgetown
process.
@return [LogAdapter]
# File lib/bridgetown-core.rb, line 202 def logger @logger ||= LogAdapter.new(LogWriter.new, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym) end
Set the log writer. New log writer must respond to the same methods as Ruby's
internal Logger.
@param writer [Object] the new Logger-compatible log transport
@return [LogAdapter]
# File lib/bridgetown-core.rb, line 212 def logger=(writer) @logger = LogAdapter.new(writer, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym) end
Conveinence method to register a new Thor command
@see Bridgetown::Commands::Registrations.register
# File lib/bridgetown-core.rb, line 172 def register_command(&block) Bridgetown::Commands::Registrations.register(&block) end
Ensures the questionable path is prefixed with the base directory
and prepends the questionable path with the base directory if false.
@param base_directory [String] the directory with which to prefix the
questionable path
@param questionable_path [String] the path we're unsure about, and want
prefixed
@return [String] the sanitized path
# File lib/bridgetown-core.rb, line 232 def sanitized_path(base_directory, questionable_path) return base_directory if base_directory.eql?(questionable_path) clean_path = questionable_path.dup clean_path.insert(0, "/") if clean_path.start_with?("~") clean_path = File.expand_path(clean_path, "/") return clean_path if clean_path.eql?(base_directory) # remove any remaining extra leading slashes not stripped away by calling # `File.expand_path` above. clean_path.squeeze!("/") if clean_path.start_with?(base_directory.sub(%r!\z!, "/")) clean_path else clean_path.sub!(%r!\A\w:/!, "/") File.join(base_directory, clean_path) end end
Set the TZ environment variable to use the timezone specified
@param timezone [String] the IANA Time Zone
@return [void] rubocop:disable Naming/AccessorMethodName
# File lib/bridgetown-core.rb, line 194 def set_timezone(timezone) ENV["TZ"] = timezone end
Deprecated. Now using the Current
site.
@return [Array<Bridgetown::Site>] the Bridgetown
sites created.
# File lib/bridgetown-core.rb, line 219 def sites [Bridgetown::Current.site].compact end
Determines the correct Bundler environment block method to use and passes the block on to it.
@return [void]
# File lib/bridgetown-core.rb, line 180 def with_unbundled_env(&block) if Bundler.bundler_major_version >= 2 Bundler.method(:with_unbundled_env).call(&block) else Bundler.method(:with_clean_env).call(&block) end end