Class: CloudCannonJekyll::Generator

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

Overview

Generates JSON file with build information

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.<=>Object

Override the Jekyll::Plugin spaceship to run at the end



17
18
19
# File 'lib/cloudcannon-jekyll/generator.rb', line 17

def self.<=>(*)
  1
end

Instance Method Details

#destination_path(filename) ⇒ Object



46
47
48
# File 'lib/cloudcannon-jekyll/generator.rb', line 46

def destination_path(filename)
  Jekyll.sanitized_path(@site.dest, path(filename))
end

#file_content(data) ⇒ Object



50
51
52
# File 'lib/cloudcannon-jekyll/generator.rb', line 50

def file_content(data)
  JSON.pretty_generate(data)
end

#generate(site) ⇒ Object



21
22
23
24
25
26
# File 'lib/cloudcannon-jekyll/generator.rb', line 21

def generate(site)
  Logger.info "⭐️ Starting #{'cloudcannon-jekyll'.blue} v#{VERSION}"
  @site = site
  config = Config.new(site)
  generate_file('info', Info.new.generate_info(site, config.read))
end

#generate_file(filename, data) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/cloudcannon-jekyll/generator.rb', line 28

def generate_file(filename, data)
  dest = destination_path(filename)
  FileUtils.mkdir_p(File.dirname(dest))
  File.open(dest, 'w') { |file| file.write(file_content(data)) }
  @site.keep_files ||= []
  @site.keep_files << path(filename)
  Logger.info "🏁 Generated #{path(filename).bold} #{'successfully'.green}"
end

#path(filename) ⇒ Object



37
38
39
# File 'lib/cloudcannon-jekyll/generator.rb', line 37

def path(filename)
  "_cloudcannon/#{filename}.json"
end

#source_path(filename) ⇒ Object



41
42
43
44
# File 'lib/cloudcannon-jekyll/generator.rb', line 41

def source_path(filename)
  file_path = path(filename)
  File.expand_path(file_path, File.dirname(__FILE__))
end