tailwindcss.rb 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. module Docs
  2. class NoopFilter < Filter
  3. def call
  4. return html
  5. end
  6. end
  7. end
  8. module Docs
  9. class Tailwindcss < UrlScraper
  10. self.name = 'Tailwind CSS'
  11. self.type = 'tailwindcss'
  12. self.slug = 'tailwindcss'
  13. self.base_url = 'https://tailwindcss.com/docs'
  14. self.root_path = '/'
  15. self.release = '2.0.3'
  16. html_filters.push 'tailwindcss/entries', 'tailwindcss/clean_html'
  17. # Disable the clean text filter which removes empty nodes - we'll do it ourselves more selectively
  18. text_filters.replace("clean_text", "noop")
  19. # Fix redirects from older tailwind 2 docs
  20. options[:fix_urls] = lambda do |url|
  21. if url.include? "installation/"
  22. break "/docs/installation"
  23. end
  24. if url.end_with? "/breakpoints"
  25. break "/docs/screens#{/#.*$/.match(url)}"
  26. end
  27. if url.end_with? "/adding-base-styles"
  28. break "/docs/adding-custom-styles#adding-base-styles"
  29. end
  30. if url.end_with? "/ring-opacity"
  31. break "/docs/ring-color#changing-the-opacity"
  32. end
  33. if url.match(/\/colors#?/)
  34. break "/docs/customizing-colors#{/#.*$/.match(url)}"
  35. end
  36. end
  37. options[:skip_patterns] = [
  38. # Skip setup instructions
  39. /\/browser-support$/,
  40. /\/editor-setup$/,
  41. /\/installation$/,
  42. /\/optimizing-for-production$/,
  43. /\/upgrade-guide/,
  44. /\/using-with-preprocessors/
  45. ]
  46. #Obtainable from https://github.com/tailwindlabs/tailwindcss/blob/master/LICENSE
  47. options[:attribution] = <<-HTML
  48. &copy; Adam Wathan, Jonathan Reinink
  49. Licensed under the MIT License.
  50. HTML
  51. def get_latest_version(opts)
  52. doc = fetch_doc('https://tailwindcss.com/docs/installation', opts)
  53. doc.at_css('select option[value=v2]').inner_text[1..]
  54. end
  55. end
  56. end