Skip to content

Commit d2d9f4b

Browse files
committed
feat: support processor chain
1 parent 0ffdc6d commit d2d9f4b

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/jekyll-spaceship/cores/manager.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def self.add(processor)
1414
container = _register.first
1515
events = _register.last.uniq
1616
events = events.select do |event|
17+
next true if event.match(/^after/)
1718
next true if event.match(/^post/)
1819
next events.index(event.to_s.gsub(/^pre/, 'post').to_sym).nil?
1920
end
@@ -59,21 +60,25 @@ def self.is_hooked?(container, event)
5960
def self.dispatch(page, container, event)
6061
@@_processors.each do |processor|
6162
processor.dispatch page, container, event
63+
break unless processor.next?
6264
end
6365
if event.to_s.start_with?('post') and Type.html? output_ext(page)
6466
self.dispatch_html_block(page)
6567
end
6668
@@_processors.each do |processor|
6769
processor.on_handled if processor.handled
70+
break unless processor.next?
6871
end
6972
end
7073

7174
def self.ext(page)
75+
return unless page.respond_to? :path
7276
ext = page.path.match(/\.[^.]+$/)
7377
ext.to_s.rstrip
7478
end
7579

7680
def self.output_ext(page)
81+
return unless page.respond_to? :url_placeholders
7782
page.url_placeholders[:output_ext]
7883
end
7984

lib/jekyll-spaceship/cores/processor.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def self.exclude(*types)
9090
def self.config
9191
end
9292

93+
def next?
94+
true
95+
end
96+
9397
def process?
9498
Type.html?(output_ext) or Type.markdown?(ext)
9599
end

0 commit comments

Comments
 (0)