From 5ac5d3a3cb80bf57efb84b6e48ab0dab7ce68bc1 Mon Sep 17 00:00:00 2001 From: Kendra Swanson Date: Wed, 29 May 2024 20:03:46 +0000 Subject: [PATCH 1/2] prepare web content for interactive show/hide solutions --- .../directions/bake_hidden_solutions_web.rb | 22 ++++++++++++++++++ lib/locales/en.yml | 1 + lib/recipes/web-generic/recipe.rb | 1 + .../bake_hidden_solutions_web_spec.rb | 23 +++++++++++++++++++ ...rections_BakeHiddenSolutionsWeb_works.snap | 13 +++++++++++ 5 files changed, 60 insertions(+) create mode 100644 lib/kitchen/directions/bake_hidden_solutions_web.rb create mode 100644 spec/kitchen_spec/directions/bake_hidden_solutions_web_spec.rb create mode 100644 spec/snapshots/Kitchen_Directions_BakeHiddenSolutionsWeb_works.snap diff --git a/lib/kitchen/directions/bake_hidden_solutions_web.rb b/lib/kitchen/directions/bake_hidden_solutions_web.rb new file mode 100644 index 000000000..40c00b4c6 --- /dev/null +++ b/lib/kitchen/directions/bake_hidden_solutions_web.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module Kitchen::Directions + module BakeHiddenSolutionsWeb + def self.v1(book_pages:) + book_pages.exercises('$.unnumbered').each do |exercise| + # wrap content, add [Show/Hide Solution] element + show_hide_translated = 'Show/Hide Solution' # TODO: I18n.t(:problem) - why is this broken? + solution = exercise.solutions.first + solution[:'aria-label'] = show_hide_translated + children = solution.element_children.cut + solution.append(child: + <<~HTML + [#{show_hide_translated}] + + HTML + ) + solution.name = 'details' + end + end + end +end diff --git a/lib/locales/en.yml b/lib/locales/en.yml index 7c160ed53..1c0028fe7 100644 --- a/lib/locales/en.yml +++ b/lib/locales/en.yml @@ -32,6 +32,7 @@ en: handbook_outline_title: Outline context_lead_text: 'Refer to ' lo_label_text: 'LO ' + show_hide_solution: 'Show/Hide Solution' eoc: glossary: Key Terms key-equations: Key Equations diff --git a/lib/recipes/web-generic/recipe.rb b/lib/recipes/web-generic/recipe.rb index 4df4d0a3c..91d47240e 100644 --- a/lib/recipes/web-generic/recipe.rb +++ b/lib/recipes/web-generic/recipe.rb @@ -19,6 +19,7 @@ BakeExerciseWithTitle.v1(within: example) end end + BakeHiddenSolutionsWeb.v1(book_pages: book_pages) # Restore WebPostBakeRestore.v1(book_pages: book_pages) diff --git a/spec/kitchen_spec/directions/bake_hidden_solutions_web_spec.rb b/spec/kitchen_spec/directions/bake_hidden_solutions_web_spec.rb new file mode 100644 index 000000000..0b528459a --- /dev/null +++ b/spec/kitchen_spec/directions/bake_hidden_solutions_web_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Kitchen::Directions::BakeHiddenSolutionsWeb do + let(:content) do + book_containing(html: + <<~HTML +
+
+
+ solution content +
+
+ HTML + ) + end + + it 'works' do + described_class.v1(book_pages: content) + expect(content).to match_snapshot_auto + end +end diff --git a/spec/snapshots/Kitchen_Directions_BakeHiddenSolutionsWeb_works.snap b/spec/snapshots/Kitchen_Directions_BakeHiddenSolutionsWeb_works.snap new file mode 100644 index 000000000..e588677be --- /dev/null +++ b/spec/snapshots/Kitchen_Directions_BakeHiddenSolutionsWeb_works.snap @@ -0,0 +1,13 @@ + + +
+
+
+ + [Show/Hide Solution] + +
+
+ + + \ No newline at end of file From a74c6f1d1309f7a76f9b7e7d4ff211e8cdf88f3b Mon Sep 17 00:00:00 2001 From: Kendra Swanson Date: Wed, 29 May 2024 20:08:13 +0000 Subject: [PATCH 2/2] update expected output --- .../directions/bake_hidden_solutions_web.rb | 4 ++- .../books/web-test/expected_output.xhtml | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/kitchen/directions/bake_hidden_solutions_web.rb b/lib/kitchen/directions/bake_hidden_solutions_web.rb index 40c00b4c6..2f6eabeb7 100644 --- a/lib/kitchen/directions/bake_hidden_solutions_web.rb +++ b/lib/kitchen/directions/bake_hidden_solutions_web.rb @@ -5,8 +5,10 @@ module BakeHiddenSolutionsWeb def self.v1(book_pages:) book_pages.exercises('$.unnumbered').each do |exercise| # wrap content, add [Show/Hide Solution] element + solution = exercise.solutions&.first + next unless solution + show_hide_translated = 'Show/Hide Solution' # TODO: I18n.t(:problem) - why is this broken? - solution = exercise.solutions.first solution[:'aria-label'] = show_hide_translated children = solution.element_children.cut solution.append(child: diff --git a/spec/recipes_spec/books/web-test/expected_output.xhtml b/spec/recipes_spec/books/web-test/expected_output.xhtml index 3687e59ce..d8738efa2 100644 --- a/spec/recipes_spec/books/web-test/expected_output.xhtml +++ b/spec/recipes_spec/books/web-test/expected_output.xhtml @@ -1146,19 +1146,22 @@ Dr. William Moebs earned a BS and PhD (1959 and 1965) from the University of Mic

Determine what the key terms refer to in the following study. We want to know the average (mean) amount of money first year college students spend at ABC College on school supplies that do not include books. We randomly surveyed 100 first year students at the college. Three of those students spent $150, $200, and $225, respectively.

-
-

- Solution -

-
-

The population is all first year students attending ABC College this term.

-

The sample could be all students enrolled in one section of a beginning statistics course at ABC College (although this sample may not represent the entire population).

-

The parameter is the average (mean) amount of money spent (excluding books) by first year college students at ABC College this term.

-

The statistic is the average (mean) amount of money spent (excluding books) by first year college students in the sample.

-

The variable could be the amount of money spent (excluding books) by one first year student. Let X = the amount of money spent (excluding books) by one first year student attending ABC College.

-

The data are the dollar amounts spent by the first year students. Examples of the data are $150, $200, and $225.

-
-
+
+ [Show/Hide Solution] + +

Using Metric Prefixes

Restate the mass 1.93×1013kg1.93×1013kg using a metric prefix such that the resulting numerical value is bigger than one but less than 1000.