openstax_kitchen 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a6855dd0e84e96799a57645b9023db15a07400c5b6971a0ebb29edf5c87074f0
4
- data.tar.gz: e7106c5faa811f73e25a829258a4aadfccad20c32dc2a0623ec8a2526e44d274
3
+ metadata.gz: dacc1aae587e492dc42e693e46195c0ed10ba749f62929e322b0744f2f82e94c
4
+ data.tar.gz: 67b4f9691c4431fc172d48381527c1fd75c62dc866ea056ff6666205e73b0e22
5
5
  SHA512:
6
- metadata.gz: 792c85c2b914719e38cca37b798160353425a6f80074926ead34c03e5fd97e47167dbc7d3efcef30d43a459a3ad917fd2e2e354fe490053e4345775cb7eac4df
7
- data.tar.gz: 95d4ec07de107850a81cec9a714e5dbe83835dd1536005587109292f503d8afa9a1bdc896dc43f3198d59f18769ef7ab4c9ae2ee312d047ab8bee9997cc4c0a6
6
+ metadata.gz: 4a788770e4176617a260d8b2ce265303a59490dd1e95727bd38102732ce6459e3600a9eca807e6c80d364b3fb710c2dbce4ec71b66dbec6570b2d61ed8e00e40
7
+ data.tar.gz: 6df9ea776c2718b1d7fdc8508210774c29f407391e0802ac6e39a94b98aadfbdb6d47447f0f2a164a66413e122ba7b46e7669fd4af5caeeda26ac0cc591919ff
data/CHANGELOG.md CHANGED
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [4.1.0] - 2021-05-18
10
+
11
+ * Fixed performance problem with element class detection (patch)
12
+ * Added `BakeChapterReferences` Directions (minor)
13
+
9
14
  ## [4.0.0] - 2021-05-18
10
15
 
11
16
  * Changes `default_css_or_xpath` to optionally be a proc to be evaluated w.r.t. a document's config (minor)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openstax_kitchen (4.0.0)
4
+ openstax_kitchen (4.1.0)
5
5
  activesupport
6
6
  i18n
7
7
  nokogiri
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen
4
+ module Directions
5
+ module BakeChapterReferences
6
+ def self.v1(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references')
7
+ V1.new.bake(
8
+ chapter: chapter,
9
+ metadata_source: metadata_source,
10
+ uuid_prefix: uuid_prefix,
11
+ klass: klass
12
+ )
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kitchen::Directions::BakeChapterReferences
4
+ class V1
5
+ renderable
6
+
7
+ def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references')
8
+ @metadata = metadata_source.children_to_keep.copy
9
+ @klass = klass
10
+ @title = I18n.t(:references)
11
+ @uuid_prefix = uuid_prefix
12
+
13
+ chapter.references.search('h3').trash
14
+
15
+ chapter.non_introduction_pages.each do |page|
16
+ references = page.references
17
+ next if references.none?
18
+
19
+ references.search('h3').trash
20
+ title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
21
+
22
+ references.each do |reference|
23
+ reference.prepend(child: title)
24
+ end
25
+ end
26
+
27
+ @content = chapter.pages.references.cut.paste
28
+
29
+ @in_composite_chapter = false
30
+
31
+ chapter.append(child: render(file:
32
+ '../../templates/eoc_section_title_template.xhtml.erb'))
33
+ end
34
+ end
35
+ end
@@ -43,6 +43,46 @@ module Nokogiri
43
43
  def inspect
44
44
  to_s
45
45
  end
46
+
47
+ def quick_matches?(selector)
48
+ self.class.selector_to_css_nodes(selector).any? { |css_node| matches_css_node?(css_node) }
49
+ end
50
+
51
+ def classes
52
+ self[:class]&.split || []
53
+ end
54
+
55
+ def self.selector_to_css_nodes(selector)
56
+ # No need to parse the same selector more than once.
57
+ @parsed_selectors ||= {}
58
+ @parsed_selectors[selector] ||= Nokogiri::CSS::Parser.new.parse(selector)
59
+ end
60
+
61
+ protected
62
+
63
+ # rubocop:disable Metrics/CyclomaticComplexity
64
+ def matches_css_node?(css_node)
65
+ case css_node.type
66
+ when :CONDITIONAL_SELECTOR
67
+ css_node.value.all? { |inner_css_node| matches_css_node?(inner_css_node) }
68
+ when :ELEMENT_NAME
69
+ css_node.value == ['*'] || css_node.value.include?(name)
70
+ when :CLASS_CONDITION
71
+ (css_node.value & classes).any?
72
+ when :ATTRIBUTE_CONDITION
73
+ attribute, operator, value = css_node.value
74
+
75
+ raise "Unknown attribute condition operator in #{css_node}" if operator != :equal
76
+
77
+ attribute_name = attribute.value
78
+ raise "More attribute names than expected, #{attribute_name}" if attribute_name.many?
79
+
80
+ self[attribute_name.first] == value.gsub('"', '').gsub("'", '')
81
+ else
82
+ raise "Unknown Nokogiri::CSS:Node type in #{css_node}"
83
+ end
84
+ end
85
+ # rubocop:enable Metrics/CyclomaticComplexity
46
86
  end
47
87
  end
48
88
  end
@@ -18,7 +18,7 @@ module Kitchen
18
18
  def matches?(node, config:)
19
19
  # This may not be incredibly efficient as it does a search of this node's
20
20
  # ancestors to see if the node is in the results. Watch the performance.
21
- node.matches?(call(config))
21
+ node.quick_matches?(call(config))
22
22
  end
23
23
  end
24
24
  end
@@ -3,5 +3,5 @@
3
3
  # A library for modifying the structure of OpenStax book XML.
4
4
  #
5
5
  module Kitchen
6
- VERSION = '4.0.0'
6
+ VERSION = '4.1.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstax_kitchen
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JP Slavinsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-19 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -233,6 +233,8 @@ files:
233
233
  - lib/kitchen/directions/bake_chapter_key_concepts/main.rb
234
234
  - lib/kitchen/directions/bake_chapter_key_concepts/v1.rb
235
235
  - lib/kitchen/directions/bake_chapter_key_equations.rb
236
+ - lib/kitchen/directions/bake_chapter_references/main.rb
237
+ - lib/kitchen/directions/bake_chapter_references/v1.rb
236
238
  - lib/kitchen/directions/bake_chapter_section_exercises/main.rb
237
239
  - lib/kitchen/directions/bake_chapter_section_exercises/v1.rb
238
240
  - lib/kitchen/directions/bake_chapter_summary.rb