Sha256: ce9825c623f72305a9d1713230e2c3bb111f988b652a2cabb7decb919b0e6198

Contents?: true

Size: 1.3 KB

Versions: 24

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

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

24 entries across 24 versions & 1 rubygems

Version Path
pages_core-3.14.0 lib/pages_core/templates.rb
pages_core-3.13.0 lib/pages_core/templates.rb
pages_core-3.12.7 lib/pages_core/templates.rb
pages_core-3.12.6 lib/pages_core/templates.rb
pages_core-3.12.5 lib/pages_core/templates.rb
pages_core-3.12.4 lib/pages_core/templates.rb
pages_core-3.12.3 lib/pages_core/templates.rb
pages_core-3.12.2 lib/pages_core/templates.rb
pages_core-3.12.1 lib/pages_core/templates.rb
pages_core-3.12.0 lib/pages_core/templates.rb
pages_core-3.11.3 lib/pages_core/templates.rb
pages_core-3.11.2 lib/pages_core/templates.rb
pages_core-3.11.1 lib/pages_core/templates.rb
pages_core-3.11.0 lib/pages_core/templates.rb
pages_core-3.10.2 lib/pages_core/templates.rb
pages_core-3.10.1 lib/pages_core/templates.rb
pages_core-3.9.2 lib/pages_core/templates.rb
pages_core-3.9.1 lib/pages_core/templates.rb
pages_core-3.9.0 lib/pages_core/templates.rb
pages_core-3.8.3 lib/pages_core/templates.rb