Class: Middleman::Cli::Spellcheck
- Inherits:
-
Thor
- Object
- Thor
- Middleman::Cli::Spellcheck
- Includes:
- Thor::Actions
- Defined in:
- lib/middleman-spellcheck/cli.rb
Overview
This class provides a “spellcheck” command for the middleman CLI.
Instance Method Summary collapse
Instance Method Details
#spellcheck(*paths) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/middleman-spellcheck/cli.rb', line 73 def spellcheck(*paths) app = ::Middleman::Application.server.inst resources = app.sitemap.resources.select{|resource| paths.any? {|path| resource.source_file.sub(Dir.pwd,'').sub(%r{^/},'')[/^#{Regexp.escape(path)}/] } } if resources.empty? $stderr.puts "File / Directory #{paths} not exist" exit 1 end ext = app.extensions[:spellcheck] allow_file = app.config.defines_setting?(:spellcheck_allow_file) ? app.config[:spellcheck_allow_file] : nil if [:fix] then print "Spellchecker fix mode on! Will attempt to white-list some words\n" end resources.each do |resource| say_status :spellcheck, "Running spell checker for #{resource.source_file}", :blue current_misspelled = ext.spellcheck_resource(resource) words_allow_frontmatter = [] words_allow_global = [] current_misspelled.each do |misspell| fix = misspell_ask(misspell, allow_file) was_fixed = true if fix == 'g' then words_allow_global << misspell[:word] elsif fix == 'f' then words_allow_frontmatter << misspell[:word] else was_fixed = false end if was_fixed say_status :spellcheck, "Fixed word #{misspell[:word]}" else say_status :misspell, ext.(misspell), :red end end misspell_fixes_global(resource, words_allow_global, allow_file) unless words_allow_global.empty? misspell_fixes_frontmatter(resource, words_allow_frontmatter) unless words_allow_frontmatter.empty? end end |