Class: Liquidbook::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/liquidbook/config.rb

Overview

Loads .liquid-preview/config.yml from the theme root

head entries can be:

- Raw HTML:  <script src="https://cdn.tailwindcss.com"></script>
- File path: ../src-lit/styles/main.css
- File path: ./src/components.js

File paths are resolved relative to the theme root and served via /__imports__/

Constant Summary collapse

DEFAULT_CONFIG =
{
  "head" => [],
  "port" => 4567,
  "host" => "127.0.0.1"
}.freeze
IMPORT_PATH_PREFIX =
"/__imports__"

Instance Method Summary collapse

Constructor Details

#initialize(theme_root: nil) ⇒ Config

Returns a new instance of Config.



23
24
25
26
# File 'lib/liquidbook/config.rb', line 23

def initialize(theme_root: nil)
  @theme_root = theme_root || Liquidbook.root
  @data = load_config
end

Instance Method Details

#[](key) ⇒ Object



46
47
48
# File 'lib/liquidbook/config.rb', line 46

def [](key)
  @data[key.to_s]
end

#head_tags_htmlObject

Returns HTML strings ready to inject into <head>



29
30
31
# File 'lib/liquidbook/config.rb', line 29

def head_tags_html
  Array(@data["head"]).map { |entry| entry_to_html(entry) }
end

#hostObject



42
43
44
# File 'lib/liquidbook/config.rb', line 42

def host
  @data["host"] || "127.0.0.1"
end

#import_filesObject

Returns a map of serve_path => absolute_file_path for file imports



34
35
36
# File 'lib/liquidbook/config.rb', line 34

def import_files
  @import_files ||= build_import_map
end

#portObject



38
39
40
# File 'lib/liquidbook/config.rb', line 38

def port
  @data["port"] || 4567
end