Sha256: fa6008560329ebebaf005ae654059ab2ae537750b1eb82cdb21641921efe6e53

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'jekyll'
require 'json'
require 'fileutils'
require_relative 'logger'
require_relative 'config'
require_relative 'generators/info'

module CloudCannonJekyll
  # Generates JSON file with build information
  class Generator < Jekyll::Generator
    priority :lowest

    # Override the Jekyll::Plugin spaceship to run at the end
    def self.<=>(*)
      1
    end

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

    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

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

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

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

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cloudcannon-jekyll-4.0.2 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-4.0.1 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-4.0.0 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.2.4 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.2.3 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.2.2 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.2.1 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.2.0 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.1.0 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.0.2 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.0.1 lib/cloudcannon-jekyll/generator.rb
cloudcannon-jekyll-3.0.0 lib/cloudcannon-jekyll/generator.rb