diff --git a/nanoc/lib/mixin/erb.rb b/nanoc/lib/mixin/erb.rb index efbbdf4..f39b4e4 100644 --- a/nanoc/lib/mixin/erb.rb +++ b/nanoc/lib/mixin/erb.rb @@ -1,6 +1,15 @@ # frozen_string_literal: true +## +# The {Mixin::ERB Mixin::ERB} module provides a method +# that can render an ERB template module Mixin::ERB + ## + # @param [String] file + # The path to an ERB template + # @param [Hash] local_assigns + # Template variables + # @return [String] def erb(file, local_assigns = {}) erb = File.binread File.join(dirs.content, "html", file) ctx = binding diff --git a/nanoc/lib/mixin/t.rb b/nanoc/lib/mixin/t.rb index 4559a2c..e5437d4 100644 --- a/nanoc/lib/mixin/t.rb +++ b/nanoc/lib/mixin/t.rb @@ -1,11 +1,25 @@ # frozen_string_literal: true +## +# The {Mixin::T Mixin::T} module provides a method that +# can render user-facing text strings in different +# locales / languages module Mixin::T + ## + # @param [String] locale + # Locale (eg "en") + # @param [String] key + # Translation key (eg "TheNobleQuran") + # @param [Hash] local_assigns + # Template variables + # @return [String] def t(locale, key, local_assigns = {}) str = [locale, *key.split(".")].inject(tdata) { _1[_2] } format(str, local_assigns) end + private + def tdata @tdata ||= Ryo.from_json(path: File.join(dirs.content, "json", "t.json")) end