Class: JekyllChatgpt::StyleGenerator

Inherits:
Jekyll::Generator
  • Object
show all
Defined in:
lib/jekyll-chatgpt.rb

Overview

Renders needed styles and JS

Instance Method Summary collapse

Instance Method Details

#add_js(site) ⇒ Object



80
81
82
83
# File 'lib/jekyll-chatgpt.rb', line 80

def add_js(site)
  message_label_js = Jekyll::StaticFile.new(site, __dir__, "", "chatgpt_message_label.js")
  site.static_files << message_label_js
end

#colors_exists?(site) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/jekyll-chatgpt.rb', line 72

def colors_exists?(site)
  sass_exists(site, "_colors.sass")
end

#generate(site) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jekyll-chatgpt.rb', line 85

def generate(site)
  chatgpt_style = Jekyll::PageWithoutAFile.new(site, __dir__, "", "chatgpt.sass")
  chatgpt_style.tap do |file|
    file.content = ""
    file.content += "@import \"colors\"\n\n" if colors_exists?(site)
    file.content += "@layer chatgpt-default, chatgpt-custom\n\n"
    file.content += "@layer chatgpt-custom\n  @import \"chatgpt_custom\"\n\n" if style_exists?(site)
    file.content += File.read(File.expand_path("chatgpt.sass", __dir__))
  end
  site.pages << chatgpt_style

  add_js(site)
end

#sass_converter(site) ⇒ Object



61
62
63
# File 'lib/jekyll-chatgpt.rb', line 61

def sass_converter(site)
  @sass_converter ||= Jekyll::Converters::Sass.new(site.config)
end

#sass_exists(site, file) ⇒ Object



65
66
67
68
69
70
# File 'lib/jekyll-chatgpt.rb', line 65

def sass_exists(site, file)
  sass_converter(site).sass_load_paths.each do |dir|
    return true unless Dir.new(dir).children.index(file).nil?
  end
  false
end

#style_exists?(site) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/jekyll-chatgpt.rb', line 76

def style_exists?(site)
  sass_exists(site, "_chatgpt_custom.sass")
end