Module: Bridgetown::Site::Configurable

Included in:
Bridgetown::Site
Defined in:
bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb

Instance Method Summary collapse

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.

Parameters:

  • strip_slash_only (Boolean) (defaults to: false)

    set to true if you wish “/” to be returned as “”

Returns:

  • (String)


37
38
39
40
41
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 37

def base_path(strip_slash_only: false)
  config[:base_path].then do |path|
    strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path
  end
end

#collections_pathString

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

Returns:

  • (String)

    Returns the full path to the collections directory

See Also:



131
132
133
134
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 131

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

Parameters:



8
9
10
11
12
13
14
15
16
17
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 8

def config=(config)
  @config = config

  configure_cache
  configure_component_paths
  configure_file_read_opts

  # TODO: see if we can just get rid of this. It's only used by GeneratedPage
  self.permalink_style = (config["permalink"] || "pretty").to_sym
end

#defaults_readerObject



43
44
45
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 43

def defaults_reader
  @defaults_reader ||= Bridgetown::DefaultsReader.new(self)
end

#destinationObject Also known as: dest



27
28
29
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 27

def destination
  config["destination"]
end

#frontend_bundling_pathObject



136
137
138
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 136

def frontend_bundling_path
  in_root_dir(".bridgetown-cache", "frontend-bundling")
end

#frontmatter_defaultsFrontMatter::Defaults

Returns the current instance of FrontMatter::Defaults or creates a new instance FrontMatter::Defaults if it doesn’t already exist.

Returns:



52
53
54
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 52

def frontmatter_defaults
  @frontmatter_defaults ||= Bridgetown::FrontMatter::Defaults.new(self)
end

#in_cache_dir(*paths) ⇒ Array<String>

Prefix a path or paths with the Bridgetown::Site#cache_dir directory.

Parameters:

Returns:

  • (Array<String>)

    Return an array of updated paths if multiple paths given.

See Also:



108
109
110
111
112
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 108

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.

Parameters:

  • paths (Array<String>)

    An array of paths to prefix with the destination directory using the Bridgetown.sanitized_path method.

Returns:

  • (Array<String>)

    Return an array of updated paths if multiple paths given.

See Also:



93
94
95
96
97
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 93

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.

Parameters:

  • paths (Array<String>)

    An array of paths to prefix with the root_dir directory using the Bridgetown.sanitized_path method.

Returns:

  • (Array<String>)

    Return an array of updated paths if multiple paths given.

See Also:



64
65
66
67
68
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 64

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.

Parameters:

  • paths (Array<String>)

    An array of paths to prefix with the source directory using the Bridgetown.sanitized_path method.

Returns:

  • (Array<String>)

    Return an array of updated paths if multiple paths given.

See Also:



77
78
79
80
81
82
83
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 77

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_dirObject



19
20
21
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 19

def root_dir
  config["root_dir"]
end

#sourceObject



23
24
25
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/configurable.rb', line 23

def source
  config["source"]
end