lib/pakyow/presenter/processor.rb in pakyow-presenter-1.0.0.rc2 vs lib/pakyow/presenter/processor.rb in pakyow-presenter-1.0.0.rc3
- old
+ new
@@ -2,48 +2,10 @@
require "pakyow/support/class_state"
module Pakyow
module Presenter
- class ProcessorCaller
- def initialize(instances)
- @processors = normalize(instances)
- end
-
- def process(content, extension)
- processors_for_extension(extension).each do |processor|
- content = processor.call(content)
- end
-
- unless extension == :html
- processors_for_extension(:html).each do |processor|
- content = processor.call(content)
- end
- end
-
- content
- end
-
- def process?(extension)
- @processors.key?(extension.tr(".", "").to_sym)
- end
-
- protected
-
- def processors_for_extension(extension)
- @processors[extension] || []
- end
-
- def normalize(instances)
- instances.each_with_object({}) { |instance, processors|
- instance.class.extensions.each do |extension|
- (processors[extension] ||= []) << instance
- end
- }
- end
- end
-
class Processor
extend Support::ClassState
class_state :name
class_state :block
class_state :extensions, default: [], getter: false
@@ -57,10 +19,11 @@
def call(content)
self.class.process(content)
end
class << self
+ # @api private
def make(name, *extensions, **kwargs, &block)
# Name is expected to also be an extension.
#
extensions.unshift(name).map!(&:to_sym)
@@ -77,9 +40,50 @@
@extensions.concat(extensions.map(&:to_sym)).uniq
else
@extensions
end
end
+ end
+ end
+
+ # @api private
+ class ProcessorCaller
+ def initialize(instances)
+ @processors = normalize(instances)
+ end
+
+ def process(content, extension)
+ content = content.to_s
+
+ processors_for_extension(extension).each do |processor|
+ content = processor.call(content)
+ end
+
+ unless extension == :html
+ processors_for_extension(:html).each do |processor|
+ content = processor.call(content)
+ end
+ end
+
+ content
+ end
+
+ def process?(extension)
+ @processors.key?(extension.tr(".", "").to_sym)
+ end
+
+ private
+
+ def processors_for_extension(extension)
+ @processors[extension] || []
+ end
+
+ def normalize(instances)
+ instances.each_with_object({}) { |instance, processors|
+ instance.class.extensions.each do |extension|
+ (processors[extension] ||= []) << instance
+ end
+ }
end
end
end
end