Class: Zui::SourceBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/zui/source_bundle.rb

Constant Summary collapse

REQUIRE_RELATIVE =
/\A\s*require_relative\s*(?:\(\s*)?["']([^"']+)["']\s*\)?\s*(?:#.*)?\z/

Instance Method Summary collapse

Constructor Details

#initialize(entrypoint, root: File.dirname(entrypoint), embedded_frameworks: ["zui"]) ⇒ SourceBundle

Returns a new instance of SourceBundle.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/zui/source_bundle.rb', line 7

def initialize(entrypoint, root: File.dirname(entrypoint), embedded_frameworks: ["zui"])
  @entrypoint = File.expand_path(entrypoint)
  @root = File.expand_path(root)
  frameworks = Array(embedded_frameworks).map(&:to_s)
  raise ArgumentError, "embedded framework names cannot be empty" if frameworks.any?(&:empty?)

  names = frameworks.map { |name| Regexp.escape(name) }.join("|")
  @embedded_framework_require = /\A\s*require\s*(?:\(\s*)?["'](?:#{names})["']\s*\)?\s*(?:#.*)?\z/
  @loaded = {}
  @loading = []
end

Instance Method Details

#callObject



19
20
21
# File 'lib/zui/source_bundle.rb', line 19

def call
  expand(@entrypoint)
end