Skip to content

Commit a78047c

Browse files
committed
Defer computing processing pipeline.
1 parent 6f3ee4b commit a78047c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/pith/input.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ class Input
1414
def initialize(project, path)
1515
@project = project
1616
@path = path
17-
determine_pipeline
1817
end
1918

2019
attr_reader :project, :path
2120

22-
attr_reader :output_path
23-
attr_reader :pipeline
24-
2521
# Public: Get the file-system location of this input.
2622
#
2723
# Returns a fully-qualified Pathname.
@@ -42,6 +38,20 @@ def ignorable?
4238
end
4339
end
4440

41+
# Return the processing steps for this input.
42+
#
43+
def pipeline
44+
determine_pipeline
45+
@pipeline
46+
end
47+
48+
# Return the output file path.
49+
#
50+
def output_path
51+
determine_pipeline
52+
@output_path
53+
end
54+
4555
# Determine whether this input is a template, requiring evaluation.
4656
#
4757
# Returns true if it is.
@@ -52,7 +62,7 @@ def template?
5262

5363
def output
5464
unless ignorable?
55-
@output ||= Output.for(self, @output_path)
65+
@output ||= Output.for(self, output_path)
5666
end
5767
end
5868

@@ -61,7 +71,7 @@ def output
6171
def render(context, locals = {}, &block)
6272
return file.read if !template?
6373
ensure_loaded
64-
@pipeline.inject(@template_text) do |text, processor|
74+
pipeline.inject(@template_text) do |text, processor|
6575
template = processor.new(file.to_s, @template_start_line) { text }
6676
template.render(context, locals, &block)
6777
end
@@ -153,7 +163,6 @@ def determine_pipeline
153163
while remaining_path =~ /^(.+)(\..+)$/
154164
extension = $2
155165
break if extension == ".html" # ignore Tilt::PlainTemplate
156-
break if extension == ".rb" # ignore Opal::Processor
157166
if handler = Tilt[extension]
158167
remaining_path = $1
159168
@pipeline << handler

0 commit comments

Comments
 (0)