lib/dionysus/redcarpet/includes.rb in dionysus-2.1.0 vs lib/dionysus/redcarpet/includes.rb in dionysus-2.2.0.0.pre1
- old
+ new
@@ -1,44 +1,34 @@
require "pathname"
-require "active_support/concern"
-require "active_support/core_ext/object/blank"
require "dionysus/redcarpet"
+require "active_support/core_ext/object/blank"
module Dionysus
module Redcarpet
+ # This is an extension to Redcarpet that allows you to include a file, preprocessor.
+ #
+ # @example README.md
+ # = This is my README
+ # <<< LICENSE.txt
module Includes
extend ActiveSupport::Concern
included do
- if method_defined?(:preprocess)
- alias_method_chain :preprocess, :includes
- else
- alias_method :preprocess, :preprocess_with_includes
- end
- end
-
- def preprocess_with_includes(full_document)
- lines = full_document.split($/)
- lines.each_with_index do |ln, i|
- if m = ln.match(LINE_DIRECTIVE_REGEXP)
+ preprocess_line do |renderer, line|
+ if m = line.match(LINE_DIRECTIVE_REGEXP)
path = Pathname.new(m[1])
if path.file?
newlines = path.readlines
newlines.collect! {|ln| ln.chomp}
newlines.shift while(newlines.first.blank?)
newlines.pop while(newlines.last.blank?)
- lines[i] = newlines
+ line = newlines.join("\n")
+ line = renderer.preprocess(line)
else
warn "[WARNING] Cannot find path %s to include"%[path.to_s]
end
end
- end
- full_document = lines.flatten.join("\n")
-
- if respond_to? :preprocess_without_includes
- preprocess_without_includes(full_document)
- else
- full_document
+ line
end
end
end
end
end