Skip to content

create pl-nursing recipe #402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* Create recipe for Polish Nursing book
* Reapply changes to `BakeIframes`
* Create `v2` `BakeFolio` that uses existing titles/numbers
* Make numbers optional in `v2` `BackFolio`
Expand Down
6 changes: 4 additions & 2 deletions lib/kitchen/directions/bake_chapter_introductions/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def self.v2(
strategy: :default, bake_chapter_outline: false, introduction_order: :v1,
block_target_label: false,
cases: false,
numbering_options: { mode: :chapter_page, separator: '.' }
numbering_options: { mode: :chapter_page, separator: '.' },
authors: false
}
)
options.reverse_merge!(
Expand All @@ -25,7 +26,8 @@ def self.v2(
introduction_order: :v1,
block_target_label: false,
cases: false,
numbering_options: { mode: :chapter_page, separator: '.' }
numbering_options: { mode: :chapter_page, separator: '.' },
authors: false
)
V2.new.bake(
book: book,
Expand Down
13 changes: 13 additions & 0 deletions lib/kitchen/directions/bake_chapter_introductions/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def bake(book:, chapters:, options:)
chapter_intro_html: chapter_intro_html,
title: title
)

bake_authors(introduction_page: introduction_page) if options[:authors]
end

Kitchen::Directions::BakeChapterIntroductions.v1_update_selectors(book)
Expand Down Expand Up @@ -158,5 +160,16 @@ def bake_title(introduction_page:)
title.id = "#{introduction_page.id}_titlecreatedbycookbook"
Kitchen::Directions::MoveTitleChildrenIntoSpan.v1(title: title)
end

def bake_authors(introduction_page:)
splash = introduction_page.search('.splash').first
author = introduction_page.search('p.autor').cut

splash.prepend(sibling:
<<~HTML
#{author.paste}
HTML
)
end
end
end
1 change: 1 addition & 0 deletions lib/recipes/bake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ book_recipes = \
when 'philosophy' then [PHILOSOPHY_RECIPE]
when 'pl-economics' then [PL_ECONOMICS_RECIPE]
when 'pl-marketing' then [PL_MARKETING_RECIPE]
when 'pl-nursing' then [PL_NURSING_RECIPE]
when 'pl-psychology' then [PL_PSYCHOLOGY_RECIPE]
when 'pl-u-physics' then [PL_U_PHYSICS_RECIPE]
when 'political-science' then [POLITICAL_SCIENCE_RECIPE]
Expand Down
8 changes: 8 additions & 0 deletions lib/recipes/pl-nursing/locales/pl.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pl:
notes:
unfolding-casestudy: Jak postąpisz w tym przypadku?
clinical-tip: Z praktyki klinicznej
eoc:
chapter-summary: Podsumowanie rozdziału
review-questions: Sprawdź się!
suggested-reading: Chcesz wiedzieć więcej?
122 changes: 122 additions & 0 deletions lib/recipes/pl-nursing/recipe.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# frozen_string_literal: true

PL_NURSING_RECIPE = Kitchen::BookRecipe.new(book_short_name: :plnursing) do |doc, _resources|
include Kitchen::Directions

doc.selectors.override(
reference: 'section.references'
)
book = doc.book
metadata = book.metadata

book.search('cnx-pi').trash

BakeListsWithPara.v1(book: book)
BakeUnnumberedFigure.v1(book: book)
BakePreface.v1(book: book, cases: true)

BakeChapterIntroductions.v2(
book: book, options: {
strategy: :add_objectives,
bake_chapter_outline: true,
introduction_order: :v3,
cases: true,
authors: true
}
)
BakeChapterTitle.v1(book: book, cases: true)

answer_key = BookAnswerKeyContainer.v1(book: book)

book.chapters.each do |chapter|
BakeNonIntroductionPages.v1(chapter: chapter, options: { cases: true })
BakeLearningObjectives.v2(chapter: chapter, add_title: false)

chapter.figures(only: :figure_to_number?).each do |figure|
BakeFigure.v1(figure: figure,
number: "#{chapter.count_in(:book)}.#{figure.count_in(:chapter)}",
cases: true)
end

chapter.tables('$:not(.unnumbered)').each do |table|
BakeNumberedTable.v1(table: table,
number: "#{chapter.count_in(:book)}.#{table.count_in(:chapter)}",
cases: true)
end

# EOC
MoveCustomSectionToEocContainer.v1(
chapter: chapter,
metadata_source: metadata,
container_key: 'chapter-summary',
uuid_key: '.chapter-summary',
section_selector: 'section.chapter-summary'
) do |section|
RemoveSectionTitle.v1(section: section)
end

BakeChapterGlossary.v1(chapter: chapter, metadata_source: metadata, has_para: true)

MoveCustomSectionToEocContainer.v1(
chapter: chapter,
metadata_source: metadata,
container_key: 'review-questions',
uuid_key: '.review-questions',
section_selector: 'section.review-questions'
) do |section|
RemoveSectionTitle.v1(section: section)
end

BakeAllNumberedExerciseTypes.v1(
within: chapter.search('section.review-questions'),
exercise_options: { cases: true }
)

BakeAllNumberedExerciseTypes.v1(
within: chapter.pages.notes('$.unfolding-casestudy'),
exercise_options: { cases: true }
)

BakeSortableSection.v1(
chapter: chapter,
metadata_source: metadata,
klass: 'suggested-reading'
)

answer_key_inner_container = AnswerKeyInnerContainer.v1(
chapter: chapter, metadata_source: metadata, append_to: answer_key, options: { cases: true }
)

Kitchen::Directions::MoveSolutionsFromNumberedNote.v1(
chapter: chapter, append_to: answer_key_inner_container, note_class: 'unfolding-casestudy'
)

Kitchen::Directions::MoveSolutionsFromExerciseSection.v1(
within: chapter, append_to: answer_key_inner_container, section_class: 'review-questions'
)

chapter.exercises.each do |exercise|
BakeFirstElements.v1(within: exercise)
end
end

note_classes = %w[special-considerations clinical-tip safety-alert
unfolding-casestudy trending-today]

BakeAutotitledNotes.v1(book: book, classes: note_classes, options: { cases: true })
BakeCustomTitledNotes.v1(book: book, classes: %w[media-feature])
BakeUnclassifiedNotes.v1(book: book)
BakeUnnumberedTables.v1(book: book)
BakeTableColumns.v1(book: book)
BakeIframes.v1(book: book)
BakeUnitTitle.v1(book: book)
BakeReferences.v4(book: book, metadata_source: metadata, cases: true)
BakeIndex.v1(book: book, types: %w[name term foreign], uuid_prefix: '.')
BakeCompositePages.v1(book: book)
BakeCompositeChapters.v1(book: book)
BakeToc.v1(book: book, options: { cases: true })
BakeFolio.v1(book: book)
BakeRexWrappers.v1(book: book)
BakeLinks.v1(book: book)
BakeLinkPlaceholders.v1(book: book, cases: true)
end
33 changes: 33 additions & 0 deletions spec/kitchen_spec/directions/bake_chapter_introductions/v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@
)
end

let(:book_with_authors) do
book_containing(html:
<<~HTML
<div data-type="chapter">
<h1 data-type="document-title">Chapter 1 Title</h1>
<div class="introduction" data-type="page" id="ipId">
<div data-type="document-title">Introduction</div>
<figure class="splash">can't touch this (stop! hammer time)</figure>
<figure>move this</figure>
<div>content</div>
<p>Some paragraph text.</p>
<p>Another paragraph text.</p>
<p class="autor">Some author</p>
</div>
</div>
HTML
)
end

context 'when v2 called on book with chapter objectives' do
it 'with chapter outline' do
described_class.v2(
Expand Down Expand Up @@ -285,6 +304,20 @@
end
end

context 'when v2 is called on book with authors' do
it 'bakes' do
described_class.v2(
book: book_with_authors, options: {
strategy: :add_objectives,
bake_chapter_outline: true,
introduction_order: :v1,
authors: true
}
)
expect(book_with_authors).to match_snapshot_auto
end
end

context 'when book has added targt labels for introduction pages and does not use gramatical cases' do
it 'stores link text' do
pantry = book_v1.pantry(name: :link_text)
Expand Down
Loading