Class: CloudCannonJekyll::Generator
- Inherits:
-
Jekyll::Generator
- Object
- Jekyll::Generator
- CloudCannonJekyll::Generator
- Defined in:
- lib/cloudcannon-jekyll/generator.rb
Overview
Generates JSON file with build information
Class Method Summary collapse
-
.<=> ⇒ Object
Override the Jekyll::Plugin spaceship to run at the end.
Instance Method Summary collapse
- #destination_path(filename) ⇒ Object
- #file_content(data) ⇒ Object
- #generate(site) ⇒ Object
- #generate_file(filename, data) ⇒ Object
- #path(filename) ⇒ Object
- #source_path(filename) ⇒ Object
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.(file_path, File.dirname(__FILE__)) end |