1
0

haskell.rb 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module Docs
  2. class Haskell < UrlScraper
  3. self.name = 'Haskell'
  4. self.type = 'haskell'
  5. self.root_path = 'users_guide/index.html'
  6. self.initial_paths = %w(libraries/index.html)
  7. self.links = {
  8. home: 'https://www.haskell.org/'
  9. }
  10. html_filters.push 'haskell/entries', 'haskell/clean_html'
  11. options[:container] = ->(filter) {filter.subpath.start_with?('users_guide') ? '.body' : '#content'}
  12. options[:only_patterns] = [/\Alibraries\//, /\Ausers_guide\//]
  13. options[:skip_patterns] = [
  14. /-notes/,
  15. /editing-guide/,
  16. /src\//,
  17. /doc-index/,
  18. /haskell2010/,
  19. /ghc-/,
  20. /Cabal-/,
  21. /Compiler-Hoopl-Internals\.html\z/i,
  22. /Control-Exception-Base\.html\z/i,
  23. /Data-Binary-Get-Internal\.html\z/i,
  24. /Language-Haskell-TH-Lib\.html\z/i,
  25. /Text-PrettyPrint\.html\z/i,
  26. /Data-OldTypeable-Internal\.html\z/i,
  27. /Data-Typeable-Internal\.html\z/i,
  28. /GHC-IO-Encoding-Types\.html\z/i,
  29. /System-Posix-Process-Internals\.html\z/i,
  30. /Data-Map-Strict-Internal\.html\z/i,
  31. /Data-IntMap-Internal\.html\z/i,
  32. /Data-Set-Internal\.html\z/i,
  33. /Data-Map-Internal\.html\z/i,
  34. /Data-Sequence-Internal\.html\z/i
  35. ]
  36. options[:skip] = %w(
  37. users_guide/license.html
  38. users_guide/genindex.html
  39. users_guide/search.html
  40. )
  41. options[:attribution] = ->(filter) do
  42. if filter.subpath.start_with?('users_guide')
  43. <<-HTML
  44. &copy; 2002&ndash;2007 The University Court of the University of Glasgow. All rights reserved.<br>
  45. Licensed under the Glasgow Haskell Compiler License.
  46. HTML
  47. else
  48. <<-HTML
  49. &copy; The University of Glasgow and others<br>
  50. Licensed under a BSD-style license (see top of the page).
  51. HTML
  52. end
  53. end
  54. version '9' do
  55. self.release = '9.2.1'
  56. self.base_url = "https://downloads.haskell.org/~ghc/#{release}/docs/html/"
  57. options[:container] = ->(filter) {filter.subpath.start_with?('users_guide') ? '.document' : '#content'}
  58. end
  59. version '8' do
  60. self.release = '8.10.2'
  61. self.base_url = "https://downloads.haskell.org/~ghc/#{release}/docs/html/"
  62. end
  63. version '7' do
  64. self.release = '7.10.3'
  65. self.base_url = "https://downloads.haskell.org/~ghc/#{release}/docs/html/"
  66. self.root_path = 'libraries/index.html'
  67. options[:only_patterns] = [/\Alibraries\//]
  68. end
  69. def get_latest_version(opts)
  70. doc = fetch_doc('https://downloads.haskell.org/~ghc/latest/docs/html/', opts)
  71. links = doc.css('a').to_a
  72. versions = links.map {|link| link['href'].scan(/ghc-([0-9.]+)/)}
  73. versions.find {|version| !version.empty?}[0][0]
  74. end
  75. end
  76. end