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.

83 lines
2.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. # frozen_string_literal: true
  2. require 'singleton'
  3. require 'yaml'
  4. class Themes
  5. include Singleton
  6. def initialize
  7. core = YAML.load_file(Rails.root.join('app', 'javascript', 'core', 'theme.yml'))
  8. core['pack'] = Hash.new unless core['pack']
  9. result = Hash.new
  10. Dir.glob(Rails.root.join('app', 'javascript', 'flavours', '*', 'theme.yml')) do |path|
  11. data = YAML.load_file(path)
  12. dir = File.dirname(path)
  13. name = File.basename(dir)
  14. locales = []
  15. screenshots = []
  16. if data['locales']
  17. Dir.glob(File.join(dir, data['locales'], '*.{js,json}')) do |locale|
  18. localeName = File.basename(locale, File.extname(locale))
  19. locales.push(localeName) unless localeName.match(/defaultMessages|whitelist|index/)
  20. end
  21. end
  22. if data['screenshot']
  23. if data['screenshot'].is_a? Array
  24. screenshots = data['screenshot']
  25. else
  26. screenshots.push(data['screenshot'])
  27. end
  28. end
  29. if data['pack']
  30. data['name'] = name
  31. data['locales'] = locales
  32. data['screenshot'] = screenshots
  33. data['skin'] = { 'default' => [] }
  34. result[name] = data
  35. end
  36. end
  37. Dir.glob(Rails.root.join('app', 'javascript', 'skins', '*', '*')) do |path|
  38. ext = File.extname(path)
  39. skin = File.basename(path)
  40. name = File.basename(File.dirname(path))
  41. if result[name]
  42. if File.directory?(path)
  43. pack = []
  44. Dir.glob(File.join(path, '*.{css,scss}')) do |sheet|
  45. pack.push(File.basename(sheet, File.extname(sheet)))
  46. end
  47. elsif ext.match(/^\.s?css$/i)
  48. skin = File.basename(path, ext)
  49. pack = ['common']
  50. end
  51. if skin != 'default'
  52. result[name]['skin'][skin] = pack
  53. end
  54. end
  55. end
  56. @core = core
  57. @conf = result
  58. end
  59. def core
  60. @core
  61. end
  62. def flavour(name)
  63. @conf[name]
  64. end
  65. def flavours
  66. @conf.keys
  67. end
  68. def skins_for(name)
  69. @conf[name]['skin'].keys
  70. end
  71. end