Sha256: 5619be1df51357204cd533e745e273d08836e509ff01c61da199003e78abcce9

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'delegate'

module JekyllDictionaries
  module Generators
    class Theme
      attr_reader :site, :theme
      def initialize(site)
        @site = site
      end

      def generate
        add_includes
        add_layouts
      end

      protected

      def theme
        @theme ||= Jekyll::Theme.new("jekyll-dictionaries")
      end

      def add_includes
        @site.includes_load_paths << theme.includes_path
      end

      def add_layouts
        layouts_path = theme.layouts_path
        wrap_custom_theme do
          entries_in(layouts_path).each do |layout_file|
            @site.layouts[theme_file_name(layout_file)] ||= Jekyll::Layout.new(@site, layouts_path, layout_file)
          end
        end
      end

      def wrap_custom_theme
        site_theme = @site.theme
        @site.theme = theme
        yield
        @site.theme = site_theme
      end

      def entries_in(dir)
        entries = []
        within(dir) do
          entries = Jekyll::EntryFilter.new(@site).filter(Dir["**/*.*"])
        end
        entries
      end

      def within(directory)
        return unless File.exist?(directory)

        Dir.chdir(directory) { yield }
      end

      def theme_file_name(file)
        file.split(".")[0..-2].join(".")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jekyll-dictionaries-1.0.3 lib/jekyll-dictionaries/generators/theme.rb