You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.2KB

  1. require 'rake'
  2. require 'color'
  3. require_relative 'controls'
  4. require_relative 'page-color'
  5. module DHE
  6. SOURCE_DIR = '/panels'
  7. class PageWithoutAFile < Jekyll::Page
  8. def read_yaml(*)
  9. @data ||= {}
  10. end
  11. end
  12. class Generator < Jekyll::Generator
  13. include DHE::PageColor
  14. def generate(site)
  15. module_pages = site.pages.select {|page| page.url.start_with? SOURCE_DIR}
  16. module_pages.each do |module_page|
  17. site.pages += control_pages(module_page)
  18. site.pages << image_page(module_page)
  19. end
  20. end
  21. def control_page(module_page, control)
  22. page = PageWithoutAFile.new(module_page.site, __dir__, module_page.url.pathmap("%{^#{SOURCE_DIR},controls}X"), control.name.ext('svg'))
  23. page.data['layout'] = 'control'
  24. page.data['width'] = control.width
  25. page.data['height'] = control.height
  26. page.content = control.svg
  27. page
  28. end
  29. def control_pages(module_page)
  30. controls(module_page).map {|control| control_page(module_page, control)}
  31. end
  32. def controls(page)
  33. page.data['controls'].flat_map {|type, variants| send(type, page, variants)}
  34. end
  35. def image_page(module_page)
  36. page = PageWithoutAFile.new(module_page.site, __dir__, module_page.url.pathmap("%{^#{SOURCE_DIR},images}d"), module_page.name)
  37. page.data.merge!(module_page.data)
  38. page.data['draw_controls'] = true
  39. page.data['dark'] = dark(page)
  40. page.data['light'] = light(page)
  41. page.content = module_page.content
  42. page
  43. end
  44. def buttons(page, variants)
  45. variants.flat_map do |style|
  46. [:off, :on].map do |state|
  47. ButtonControl.new(style: style, state: state, dark: dark(page), light: light(page))
  48. end
  49. end
  50. end
  51. def ports(page, _)
  52. PortControl.new(metal_color: light(page), shadow_color: dark(page))
  53. end
  54. def knobs(page, _)
  55. KnobControl.new(knob_color: dark(page), pointer_color: light(page))
  56. end
  57. def switches(page, variants)
  58. variants.flat_map do |positions|
  59. states = [:high, :low]
  60. states << :mid if positions == 3
  61. states.map do |state|
  62. SwitchControl.new(positions: positions, state: state, dark: dark(page), light: light(page))
  63. end
  64. end
  65. end
  66. end
  67. end