Sha256: eefd6cf0a43d5951f55ae250be51cd7fa6a0a4891e592e8bfaf0537c83f3140d

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# encoding: utf-8

require "pages_core/templates/block_configuration"
require "pages_core/templates/configuration_proxy"
require "pages_core/templates/configuration_handler"
require "pages_core/templates/configuration"
require "pages_core/templates/controller_actions"
require "pages_core/templates/template_configuration"

module PagesCore
  module Templates
    class << self
      def names
        @names ||= find_all_templates
      end

      private

      def template_paths
        [
          PagesCore.plugin_root.join("app", "views", "pages", "templates"),
          Rails.root.join("app", "views", "pages", "templates")
        ]
      end

      def template_files
        template_paths
          .select { |dir| File.exist?(dir) }
          .flat_map { |dir| template_files_in_dir(dir) }
          .uniq
          .compact
          .sort
          .map { |f| f.gsub(/\.[\w\.]+$/, "") }
      end

      def template_files_in_dir(dir)
        Dir.entries(dir).select { |f| template_file?(f, dir) }
      end

      def template_file?(file, dir)
        File.file?(File.join(dir, file)) && !file.match(/^_/)
      end

      def find_all_templates
        if template_files.include?("index")
          ["index"] + (template_files - ["index"])
        else
          template_files
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pages_core-3.5.1 lib/pages_core/templates.rb