al-quran.reflectslight.io/nanoc/lib/utils/erb.rb

20 lines
495 B
Ruby
Raw Normal View History

2023-10-08 00:16:37 +02:00
# frozen_string_literal: true
2024-06-22 02:47:20 +02:00
##
2024-06-22 04:43:31 +02:00
# The {Utils::ERB Utils::ERB} module provides a method
2024-06-22 02:47:20 +02:00
# that can render an ERB template
2024-06-22 04:43:31 +02:00
module Utils::ERB
2024-06-22 02:47:20 +02:00
##
# @param [String] file
# The path to an ERB template
# @param [Hash] local_assigns
# Template variables
# @return [String]
2024-06-22 00:04:17 +02:00
def erb(file, local_assigns = {})
erb = File.binread File.join(dirs.content, "html", file)
ctx = binding
local_assigns.each { ctx.local_variable_set(_1, _2) }
::ERB.new(erb).result(ctx)
2023-10-07 08:21:48 +02:00
end
end