Module: Phlex

Defined in:
lib/phlex.rb,
lib/phlex/version.rb

Defined Under Namespace

Modules: Error, Helpers, Kit Classes: ArgumentError, CSV, DoubleRenderError, FIFO, FIFOCacheStore, HTML, NameError, RuntimeError, SGML, SVG

Constant Summary collapse

Loader =
Zeitwerk::Loader.for_gem.tap do |loader|
	loader.inflector.inflect(
		"csv" => "CSV",
		"fifo" => "FIFO",
		"fifo_cache_store" => "FIFOCacheStore",
		"html" => "HTML",
		"sgml" => "SGML",
		"svg" => "SVG",
	)

	loader.collapse("#{__dir__}/phlex/errors")
	loader.setup
end
Escape =
ERB::Escape
DEPLOYED_AT =
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
CACHED_FILES =
Set.new
ATTRIBUTE_CACHE =
FIFO.new
VERSION =
"2.3.0"

Class Method Summary collapse

Class Method Details

.__expand_attribute_cache__(file_path) ⇒ Object



28
29
30
31
32
33
# File 'lib/phlex.rb', line 28

def self.__expand_attribute_cache__(file_path)
	unless CACHED_FILES.include?(file_path)
		CACHED_FILES << file_path
		Phlex::ATTRIBUTE_CACHE.expand(File.size(file_path))
	end
end

.html(&block) ⇒ Object

Generate an HTML string using Phlex’ HTML DSL



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/phlex.rb', line 36

def self.html(&block)
	HTML.call do |component|
		receiver = block.binding.receiver

		receiver.instance_variables.each do |ivar|
			next if component.instance_variable_defined?(ivar)

			value = receiver.instance_variable_get(ivar)
			component.instance_variable_set(ivar, value)
		end

		component.instance_exec(receiver, &block)
	end
end

.svg(&block) ⇒ Object

Generate an SVG string using Phlex’ SVG DSL



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/phlex.rb', line 52

def self.svg(&block)
	SVG.call do |component|
		receiver = block.binding.receiver

		receiver.instance_variables.each do |ivar|
			next if component.instance_variable_defined?(ivar)

			value = receiver.instance_variable_get(ivar)
			component.instance_variable_set(ivar, value)
		end

		component.instance_exec(receiver, &block)
	end
end