Class: MarkdownProofer
- Inherits:
-
Object
- Object
- MarkdownProofer
- Defined in:
- lib/markdown_proofer.rb,
lib/markdown_proofer/version.rb,
lib/markdown_proofer/rake_task.rb
Defined Under Namespace
Modules: RakeTask
Constant Summary collapse
- VERSION =
'0.1.1'
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#excludes ⇒ Object
readonly
Returns the value of attribute excludes.
-
#html_proofer ⇒ Object
readonly
Returns the value of attribute html_proofer.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
Instance Method Summary collapse
- #files ⇒ Object
- #included_files ⇒ Object
-
#initialize(path: '.', excludes: [], html_proofer: {}) ⇒ MarkdownProofer
constructor
A new instance of MarkdownProofer.
- #run ⇒ Object
Constructor Details
#initialize(path: '.', excludes: [], html_proofer: {}) ⇒ MarkdownProofer
Returns a new instance of MarkdownProofer.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/markdown_proofer.rb', line 15 def initialize(path: '.', excludes: [], html_proofer: {}) @path = path @excludes = excludes @html_proofer = html_proofer self.reset_errors @pipeline = HTML::Pipeline.new [ HTML::Pipeline::MarkdownFilter, HTML::Pipeline::TableOfContentsFilter ], gfm: true end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
13 14 15 |
# File 'lib/markdown_proofer.rb', line 13 def errors @errors end |
#excludes ⇒ Object (readonly)
Returns the value of attribute excludes.
13 14 15 |
# File 'lib/markdown_proofer.rb', line 13 def excludes @excludes end |
#html_proofer ⇒ Object (readonly)
Returns the value of attribute html_proofer.
13 14 15 |
# File 'lib/markdown_proofer.rb', line 13 def html_proofer @html_proofer end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/markdown_proofer.rb', line 13 def path @path end |
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
13 14 15 |
# File 'lib/markdown_proofer.rb', line 13 def pipeline @pipeline end |
Instance Method Details
#files ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/markdown_proofer.rb', line 27 def files if File.file?(self.path) [self.path] else # directory pattern = File.join(self.path, '**', '*.md') Dir.glob(pattern) end end |
#included_files ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/markdown_proofer.rb', line 36 def included_files self.files.reject do |file| self.excludes.any? do |exclude| file =~ exclude end end end |
#run ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/markdown_proofer.rb', line 44 def run self.reset_errors # iterate over files, and generate HTML from Markdown self.included_files.each do |file| # convert the Markdown to HTML contents = File.read(file) result = self.pipeline.call(contents) # save the HTML file next to the Markdown one output_file = file.sub(/\.md$/, '.html') begin File.open(output_file, 'w') do |file| file.write(result[:output].to_s) end # do validation on the file html_proofer = HTML::Proofer.new(output_file, self.html_proofer) self.capture_stderr { html_proofer.run } # TODO add getter in HTML::Proofer errors = html_proofer.instance_variable_get(:@failed_tests) self.errors.concat(errors) ensure # clean up the file FileUtils.rm(output_file) end end self.errors.empty? end |