aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dev-cmd/aspell-dictionaries.rb
blob: ab0e66d2bf931f56cbf9a20f8bfc795140236e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#: @hide_from_man_page
#:  * `aspell_dictionaries`:
#:    Generates the new dictionaries for the `aspell` formula.

require "open-uri"
require "resource"
require "formula"

module Homebrew
  module_function

  def aspell_dictionaries
    dict_url    = "https://ftpmirror.gnu.org/aspell/dict"
    dict_mirror = "https://ftp.gnu.org/gnu/aspell/dict"
    languages   = {}

    open("#{dict_url}/0index.html") do |content|
      content.each_line do |line|
        break if %r{^</table} =~ line
        next unless /^<tr><td><a/ =~ line

        fields = line.split('"')
        lang = fields[1]
        path = fields[3]
        lang.tr!("-", "_")
        languages[lang] = path
      end
    end

    languages.each do |lang, path|
      r = Resource.new(lang)
      r.owner = Formulary.factory("aspell")
      r.url "#{dict_url}/#{path}"
      r.mirror "#{dict_mirror}/#{path}"
      r.fetch
      puts <<-EOS
        option "with-lang-#{r.name}", "Install #{r.name} dictionary"
        resource "#{r.name}" do
          url "#{r.url}"
          mirror "#{r.mirrors.first}"
          sha256 "#{r.cached_download.sha256}"
        end

      EOS
    end
  end
end