Sha256: 3143d1677602e26618a73827d8cd54078c7ce97bace2bc5d2d45f6e1c0ff6225

Contents?: true

Size: 1.94 KB

Versions: 34

Compression:

Stored size: 1.94 KB

Contents

require "bullet_train/themes/version"
require "bullet_train/themes/engine"
# require "bullet_train/themes/base/theme"
require "nice_partials"
require "bullet_train/fields"

module BulletTrain
  module Themes
    mattr_accessor :themes, default: {}
    mattr_accessor :logo_height, default: 54

    mattr_reader :partial_paths, default: {}

    INVOCATION_PATTERNS = [
      # ❌ This path is included for legacy purposes, but you shouldn't reference partials like this in new code.
      /^account\/shared\//,

      # ✅ This is the correct path to generically reference theme component partials with.
      /^shared\//,
    ]

    def self.theme_invocation_path_for(path)
      # Themes only support `<%= render 'shared/box' ... %>` style calls to `render`, so check `path` is a string first.
      if path.is_a?(String) && (pattern = INVOCATION_PATTERNS.find { _1.match? path })
        path.remove(pattern)
      end
    end

    module Base
      class Theme
        def directory_order
          ["base"]
        end

        def resolved_partial_path_for(lookup_context, path, locals)
          # We disable partial path caching in development so new templates are taken into account without restarting the server.
          partial_paths = {}

          BulletTrain::Themes.partial_paths.fetch(path) do
            if (theme_path = BulletTrain::Themes.theme_invocation_path_for(path))
              # TODO directory_order should probably come from the `Current` model.
              if (partial = lookup_context.find_all(theme_path, directory_order.map { "themes/#{_1}" }, true, locals.keys).first)
                resolved_partial = partial.virtual_path.gsub("/_", "/")
                if Rails.env.development?
                  partial_paths[path] = resolved_partial
                else
                  BulletTrain::Themes.partial_paths[path] = resolved_partial
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
bullet_train-themes-1.10.0 lib/bullet_train/themes.rb
bullet_train-themes-1.9.0 lib/bullet_train/themes.rb
bullet_train-themes-1.8.5 lib/bullet_train/themes.rb
bullet_train-themes-1.8.4 lib/bullet_train/themes.rb
bullet_train-themes-1.8.3 lib/bullet_train/themes.rb
bullet_train-themes-1.8.2 lib/bullet_train/themes.rb
bullet_train-themes-1.8.1 lib/bullet_train/themes.rb
bullet_train-themes-1.8.0 lib/bullet_train/themes.rb
bullet_train-themes-1.7.23 lib/bullet_train/themes.rb
bullet_train-themes-1.7.22 lib/bullet_train/themes.rb
bullet_train-themes-1.7.21 lib/bullet_train/themes.rb
bullet_train-themes-1.7.20 lib/bullet_train/themes.rb
bullet_train-themes-1.7.19 lib/bullet_train/themes.rb
bullet_train-themes-1.7.18 lib/bullet_train/themes.rb
bullet_train-themes-1.7.17 lib/bullet_train/themes.rb
bullet_train-themes-1.7.16 lib/bullet_train/themes.rb
bullet_train-themes-1.7.15 lib/bullet_train/themes.rb
bullet_train-themes-1.7.14 lib/bullet_train/themes.rb
bullet_train-themes-1.7.13 lib/bullet_train/themes.rb
bullet_train-themes-1.7.12 lib/bullet_train/themes.rb