From 48b9cba95fd19d0a8757cdaa8e14533b8eff59ee Mon Sep 17 00:00:00 2001 From: Tyler Nullmeier Date: Tue, 25 Mar 2025 12:59:44 -0500 Subject: [PATCH 1/3] Remove rex_link and slugify Add a formatted anchor that will be updated in postbake --- lib/kitchen/directions/bake_iframes/v1.rb | 11 +++----- lib/kitchen/element_base.rb | 33 ----------------------- lib/kitchen/patches/string.rb | 14 ---------- 3 files changed, 3 insertions(+), 55 deletions(-) diff --git a/lib/kitchen/directions/bake_iframes/v1.rb b/lib/kitchen/directions/bake_iframes/v1.rb index d24b92b08..26916165c 100644 --- a/lib/kitchen/directions/bake_iframes/v1.rb +++ b/lib/kitchen/directions/bake_iframes/v1.rb @@ -10,13 +10,8 @@ def bake(book:) iframes.each do |iframe| next if iframe.has_class?('os-is-iframe') # don't double-bake - iframe_link = \ - begin - iframe.rex_link - rescue StandardError - warn "Unable to find rex link for iframe #{iframe}" - iframe[:src] - end + iframe_link = '/404-this-link-should-be-replaced' + iframe.wrap('
') iframe.add_class('os-is-iframe') @@ -25,7 +20,7 @@ def bake(book:) iframe.prepend(child: <<~HTML - #{I18n.t(:iframe_link_text)} + #{I18n.t(:iframe_link_text)} HTML ) diff --git a/lib/kitchen/element_base.rb b/lib/kitchen/element_base.rb index ad5280283..3f2cbf75a 100644 --- a/lib/kitchen/element_base.rb +++ b/lib/kitchen/element_base.rb @@ -915,39 +915,6 @@ def as_enumerator enumerator_class.new(search_query: search_query_that_found_me) { |block| block.yield(self) } end - def rex_link - self[:'data-is-for-rex-linking'] = 'true' - - element_with_ancestors = document.book.chapters.search_with( - Kitchen::PageElementEnumerator, Kitchen::CompositePageElementEnumerator - ).search('[data-is-for-rex-linking="true"]').first - - remove_attribute('data-is-for-rex-linking') - - unless element_with_ancestors - raise("Cannot create rex link to element #{self} - needs ancestors of both types chapter & page/composite_page" \ - "#{say_source_or_nil}" - ) - end - - book_slug = document.slug - chapter_count = element_with_ancestors.ancestor(:chapter).count_in(:book) - page_string = '' - page_title = '' - page = element_with_ancestors.ancestor(:page) if element_with_ancestors.has_ancestor?(:page) - if page&.is_introduction? - page_title = page.first('[data-type="document-title"]').text.slugify - elsif page - page_string = "#{page.count_in(:chapter) - 1}-" - page_title = page.title_text.slugify - else - page = element_with_ancestors.ancestor(:composite_page) - page_title = page.title.text.slugify - end - - "https://openstax.org/books/#{book_slug}/pages/#{chapter_count}-#{page_string}#{page_title}" - end - def add_platform_media(format) valid_formats = %w[screen print screenreader] raise "Media format invalid; valid formats are #{valid_formats}" unless valid_formats.include?(format) diff --git a/lib/kitchen/patches/string.rb b/lib/kitchen/patches/string.rb index a08a878e8..b95277228 100644 --- a/lib/kitchen/patches/string.rb +++ b/lib/kitchen/patches/string.rb @@ -10,18 +10,4 @@ class String def uncapitalize sub(/^[A-Z]/, &:downcase) end - - # Transform self to kebab case, returning a new string - # Example: "Star Wars: The Empire Strikes Back" -> "star-wars-the-empire-strikes-back" - # - # @return [String] - # - def slugify - I18n.transliterate( - strip.downcase - .gsub(/'/, '') - .gsub(/®/, ' r') - .gsub(/\u2014+/, '-') - ).gsub(/[^(\w\s)-]/, '').gsub(/[\s-]+/, '-') - end end From 3851ab041d234c4785c48fdd96a5286ffbe6efc8 Mon Sep 17 00:00:00 2001 From: Tyler Nullmeier Date: Tue, 25 Mar 2025 13:01:46 -0500 Subject: [PATCH 2/3] Update tests and snapshots --- .../directions/bake_iframes/v1_spec.rb | 44 ----- spec/kitchen_spec/element_base_spec.rb | 85 --------- .../books/ap-history/expected_output.xhtml | 8 +- .../books/ap-physics-2e/expected_output.xhtml | 10 +- .../books/ap-physics/expected_output.xhtml | 4 +- .../books/biology/expected_output.xhtml | 8 +- .../college-physics-2e/expected_output.xhtml | 10 +- .../college-physics/expected_output.xhtml | 4 +- .../english-composition/expected_output.xhtml | 2 +- .../books/finance/expected_output.xhtml | 8 +- .../books/hs-physics/expected_output.xhtml | 2 +- .../expected_output.xhtml | 6 +- .../books/marketing/expected_output.xhtml | 36 ++-- .../books/neuroscience/expected_output.xhtml | 6 +- .../nursing-external/expected_output.xhtml | 4 +- .../books/philosophy/expected_output.xhtml | 2 +- .../books/pl-marketing/expected_output.xhtml | 166 +++++++++--------- .../political-science/expected_output.xhtml | 6 +- .../books/python/expected_output.xhtml | 42 ++--- .../books/u-physics/expected_output.xhtml | 2 +- ...rections_BakeIframes_V1_bakes_iframes.snap | 6 +- 21 files changed, 166 insertions(+), 295 deletions(-) diff --git a/spec/kitchen_spec/directions/bake_iframes/v1_spec.rb b/spec/kitchen_spec/directions/bake_iframes/v1_spec.rb index 511a3d36c..0ff49545c 100644 --- a/spec/kitchen_spec/directions/bake_iframes/v1_spec.rb +++ b/spec/kitchen_spec/directions/bake_iframes/v1_spec.rb @@ -63,48 +63,4 @@ described_class.new.bake(book: book_with_baked_iframes) expect(book_with_baked_iframes).to match_normalized_html(book_with_baked_iframes_snapshot) end - - context 'with exceptions' do - let(:book_with_iframe_no_slug) do - book_containing(html: - <<~HTML -
-
-
-

The Document: Title!

-
- -
-
-
- HTML - ) - end - - let(:book_with_iframe_no_id_on_media) do - book_containing(html: - <<~HTML - -
-
-
-

The Document: Title!

-
- -
-
-
- HTML - ) - end - - it 'warns when rex link can\'t be made - no slug' do - expect(Warning).to receive(:warn).with( - /Unable to find rex link for iframe @@ -2786,7 +2786,7 @@ Europeans believed they discovered an entirely new place when they encountered t

Watch this BRI Homework Help video on the Columbian Exchange for a review of the main ideas in this essay.