Sha256: dc4203a77c17f46820a45eb702ecf4e38cc0260421864e368f8cf0398bb8bb3f

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'opal'

module Jekyll
  module Generators
    class Opal < Generator

      def generate(site)
        write_file(output_location(site)) unless File.file?(output_location(site))
        keep_the_file(site)
        save_lib_file_location_to_config(site)
      end

      def write_file(location)
        ensure_directory(location)
        File.open(location, 'wb') do |f|
          f.puts(opal_stdlib)
        end
        location
      end

      def opal_stdlib
        ::Opal::Builder.build('opal')
      end

      def ensure_directory(location)
        dir = File.dirname(location)
        unless File.directory?(dir)
          require 'fileutils'
          FileUtils.mkdir_p(dir)
        end
      end

      def output_location(site)
        File.expand_path(opal_lib_relative_path, site.dest)
      end

      def keep_the_file(site)
        (site.keep_files ||= []) << opal_lib_relative_path
      end

      def save_lib_file_location_to_config(site)
        site.config["opal"] = {
          "version" => ::Opal::VERSION,

          # must start with a forward slash!
          "url"     => File.join("", opal_lib_relative_path)
        }
      end

      def opal_lib_relative_path
        Jekyll::Opal::OPAL_LIB_LOCATION
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jekyll-opal-0.3.0 lib/jekyll/generators/opal.rb
jekyll-opal-0.2.0 lib/jekyll/generators/opal.rb
jekyll-opal-0.1.0 lib/jekyll/generators/opal.rb