From 0e5b8db6bf46f85971480bfdd6ec5bc4a0812b49 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Tue, 13 Aug 2024 16:59:59 -0300 Subject: [PATCH] Group locals onto 'context' --- Rules | 3 ++- nanoc/rules/random.rules | 4 ++-- nanoc/rules/surah-index.rules | 4 ++-- nanoc/rules/surah-stream.rules | 16 +++------------- src/html/main/random.html.erb | 10 +++++----- src/html/main/surah-index.html.erb | 12 ++++++------ src/html/main/surah-stream.html.erb | 16 ++++++++-------- src/json/surahs.json | 2 +- 8 files changed, 29 insertions(+), 38 deletions(-) diff --git a/Rules b/Rules index 3b5d968..6894b8d 100644 --- a/Rules +++ b/Rules @@ -21,6 +21,7 @@ Nanoc::RuleDSL::CompilerDSL.prepend(Nanoc::Extension::RequireRules) locales = %w[ar fa en] name_by_id = Ryo.from_json(path: File.join(dirs.content, "json", "nameById.json")) tdata = Ryo.from_json(path: File.join(dirs.content, "json", "t.json")) +surahs = Ryo.from_json(path: File.join(dirs.content, "json", "surahs.json")) tidy = `which tidy || which tidy5`.chomp buildenv = ENV["buildenv"] || "development" @@ -62,7 +63,7 @@ passthrough "/json/durations/*.json" require_rules "nanoc/rules/assets" require_rules "nanoc/rules/redirect", {locales:, tidy:} require_rules "nanoc/rules/random", {locales:, tdata:, tidy:} -require_rules "nanoc/rules/surah-stream", {locales:, tdata:, name_by_id:, tidy:} +require_rules "nanoc/rules/surah-stream", {locales:, tdata:, surahs:, name_by_id:, tidy:} require_rules "nanoc/rules/surah-index", {locales:, tdata:, tidy:} ## diff --git a/nanoc/rules/random.rules b/nanoc/rules/random.rules index 32240e9..5d7d447 100644 --- a/nanoc/rules/random.rules +++ b/nanoc/rules/random.rules @@ -7,8 +7,8 @@ locales.each do |locale| compile "/html/main/random.html.erb", rep: "random/#{locale}" do - context = Ryo.from({filename: "random.html.erb", dir: tdata[locale].dir, locale:, locales:}) - filter(:erb, locals: {locale:, locales:, dir: context.dir, context:}) + context = Ryo.from({dir: tdata[locale].dir, locale:, locales:}) + filter(:erb, locals: {context:}) filter(:tidy, exe: tidy) write("/#{locale}/random/index.html") end diff --git a/nanoc/rules/surah-index.rules b/nanoc/rules/surah-index.rules index d453e5f..c1d7138 100644 --- a/nanoc/rules/surah-index.rules +++ b/nanoc/rules/surah-index.rules @@ -7,8 +7,8 @@ locales.each do |locale| compile "/html/main/surah-index.html.erb", rep: "/#{locale}/surah/index" do - context = Ryo.from(filename: "surah-index.html.erb", dir: tdata[locale].dir, locale:, locales:) - filter(:erb, {locals: {locale:, locales:, dir: context.dir, context:}}) + context = Ryo.from(dir: tdata[locale].dir, locale:, locales:) + filter(:erb, {locals: {context:}}) filter(:tidy, exe: tidy) write "/#{locale}/index.html" end diff --git a/nanoc/rules/surah-stream.rules b/nanoc/rules/surah-stream.rules index 2c4d51f..dccc225 100644 --- a/nanoc/rules/surah-stream.rules +++ b/nanoc/rules/surah-stream.rules @@ -15,19 +15,9 @@ end Ryo.each(name_by_id) do |id, slug| write_file = ->(locale, pathname:) do - name = tdata[locale].surahs.names[id.to_i - 1] - context = Ryo.from( - filename: "surah-stream.html.erb", - locale:, - locales:, - surah: {id:, name:, slug:}, - dir: tdata[locale].dir - ) - locals = { - locale: context.locale, locales: context.locales, - surah: context.surah, dir: context.dir, context: - } - filter(:erb, locals:) + surah = surahs[locale][id.to_i - 1] + context = Ryo.from(locale:, locales:, surah:, dir: tdata[locale].dir) + filter(:erb, locals: {context:}) filter(:tidy, exe: tidy) write "/#{locale}/#{pathname}/index.html" end diff --git a/src/html/main/random.html.erb b/src/html/main/random.html.erb index 51836c8..171f8fb 100644 --- a/src/html/main/random.html.erb +++ b/src/html/main/random.html.erb @@ -1,15 +1,15 @@ - + - <%= t(locale, "TheNobleQuran") %> - + <%= t(context.locale, "TheNobleQuran") %> + <%= erb("_version.html.erb") %> <%= erb("_opengraph.html.erb", {file: "random.html.erb", context:}) %> - <% locales.each do |locale| %> + <% context.locales.each do |locale| %> - + - <%= t(locale, "TheNobleQuran") %> + <%= t(context.locale, "TheNobleQuran") %> <%= inline_css('/css/vendor/postman.css') %> - + <%= erb("_version.html.erb") %> <%= erb("_opengraph.html.erb", {file: "surah-index.html.erb", context:}) %> - <% locales.each do |locale| %> + <% context.locales.each do |locale| %> @@ -20,7 +20,7 @@ <%= erb("_favicon.html.erb") %> - <%= erb("_postman.html.erb", {locale:, dir:}) %> + <%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
diff --git a/src/html/main/surah-stream.html.erb b/src/html/main/surah-stream.html.erb index ae9193d..ecf1ca2 100644 --- a/src/html/main/surah-stream.html.erb +++ b/src/html/main/surah-stream.html.erb @@ -1,28 +1,28 @@ - + - <%= surah.name %> + <%= context.surah.name %> <%= inline_css('/css/vendor/postman.css') %> - + <%= erb("_version.html.erb") %> <%= erb("_opengraph.html.erb", {file: "stream-stream.html.erb", context:}) %> - <% locales.each do |locale| %> + <% context.locales.each do |locale| %> <% end %> <%= erb("_favicon.html.erb") %> - <%= erb("_postman.html.erb", {locale:, dir:}) %> + <%= erb("_postman.html.erb", {locale: context.locale, dir: context.dir}) %>
diff --git a/src/json/surahs.json b/src/json/surahs.json index 4f2b746..cc5370c 100644 --- a/src/json/surahs.json +++ b/src/json/surahs.json @@ -2741,4 +2741,4 @@ "translitName": "An-Nas" } ] -} \ No newline at end of file +}