Module: Bridgetown::Site::Configurable
- Included in:
- Bridgetown::Site
- Defined in:
- lib/bridgetown-core/concerns/site/configurable.rb
Instance Method Summary collapse
-
#base_path(strip_slash_only: false) ⇒ String
Returns a base path from which the site is served (aka
/cool-site
) or/
if served from root. - #baseurl ⇒ Object
-
#collections_path ⇒ String
The full path to the directory that houses all the registered collections for the current site.
-
#config=(config) ⇒ Object
Set the site's configuration object.
- #defaults_reader ⇒ Object
- #destination ⇒ Object (also: #dest)
- #frontend_bundling_path ⇒ Object
-
#frontmatter_defaults ⇒ FrontmatterDefaults
Returns the current instance of FrontmatterDefaults or creates a new instance FrontmatterDefaults if it doesn't already exist.
-
#in_cache_dir(*paths) ⇒ Array<String>
Prefix a path or paths with the #cache_dir directory.
-
#in_destination_dir(*paths) ⇒ Array<String>
(also: #in_dest_dir)
Prefix a path or paths with the #dest directory.
-
#in_root_dir(*paths) ⇒ Array<String>
Prefix a path or paths with the #root_dir directory.
-
#in_source_dir(*paths) ⇒ Array<String>
Prefix a path or paths with the #source directory.
- #root_dir ⇒ Object
- #source ⇒ Object
- #uses_resource? ⇒ Boolean
Instance Method Details
#base_path(strip_slash_only: false) ⇒ String
Returns a base path from which the site is served (aka /cool-site
) or
/
if served from root.
43 44 45 46 47 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 43 def base_path(strip_slash_only: false) (config[:base_path] || config[:baseurl]).then do |path| strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path end end |
#baseurl ⇒ Object
49 50 51 52 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 49 def baseurl Bridgetown::Deprecator. "Site#baseurl is now Site#base_path" base_path(strip_slash_only: true).presence end |
#collections_path ⇒ String
The full path to the directory that houses all the registered collections for the current site.
If @collections_path
is specified use its value.
If @collections
is not specified and config["collections_dir"]
is
specified, prepend it with #source and assign it to
#collections_path.
If @collections
is not specified and config["collections_dir"]
is not
specified, assign #source to @collections_path
142 143 144 145 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 142 def collections_path dir_str = config["collections_dir"] @collections_path ||= dir_str.empty? ? source : in_source_dir(dir_str) end |
#config=(config) ⇒ Object
Set the site's configuration object
8 9 10 11 12 13 14 15 16 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 8 def config=(config) @config = config configure_cache configure_component_paths configure_file_read_opts self.permalink_style = (config["permalink"] || "pretty").to_sym end |
#defaults_reader ⇒ Object
54 55 56 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 54 def defaults_reader @defaults_reader ||= Bridgetown::DefaultsReader.new(self) end |
#destination ⇒ Object Also known as: dest
26 27 28 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 26 def destination config["destination"] end |
#frontend_bundling_path ⇒ Object
147 148 149 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 147 def frontend_bundling_path in_root_dir(".bridgetown-cache", "frontend-bundling") end |
#frontmatter_defaults ⇒ FrontmatterDefaults
Returns the current instance of FrontmatterDefaults or creates a new instance FrontmatterDefaults if it doesn't already exist.
63 64 65 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 63 def frontmatter_defaults @frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self) end |
#in_cache_dir(*paths) ⇒ Array<String>
Prefix a path or paths with the Bridgetown::Site#cache_dir directory.
119 120 121 122 123 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 119 def in_cache_dir(*paths) paths.reduce(cache_dir) do |base, path| Bridgetown.sanitized_path(base, path) end end |
#in_destination_dir(*paths) ⇒ Array<String> Also known as: in_dest_dir
Prefix a path or paths with the #dest directory.
104 105 106 107 108 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 104 def in_destination_dir(*paths) paths.reduce(destination) do |base, path| Bridgetown.sanitized_path(base, path) end end |
#in_root_dir(*paths) ⇒ Array<String>
Prefix a path or paths with the #root_dir directory.
75 76 77 78 79 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 75 def in_root_dir(*paths) paths.reduce(root_dir) do |base, path| Bridgetown.sanitized_path(base, path.to_s) end end |
#in_source_dir(*paths) ⇒ Array<String>
Prefix a path or paths with the #source directory.
88 89 90 91 92 93 94 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 88 def in_source_dir(*paths) # TODO: this operation is expensive across thousands of iterations. Look for ways # to workaround use of this wherever possible... paths.reduce(source) do |base, path| Bridgetown.sanitized_path(base, path.to_s) end end |
#root_dir ⇒ Object
18 19 20 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 18 def root_dir config["root_dir"] end |
#source ⇒ Object
22 23 24 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 22 def source config["source"] end |
#uses_resource? ⇒ Boolean
31 32 33 34 35 36 |
# File 'lib/bridgetown-core/concerns/site/configurable.rb', line 31 def uses_resource? Bridgetown::Deprecator.( "The Site#uses_resource? method will be removed in the next version" ) true end |