Sha256: 2e30410d1d2b847ec875152f06373cf537f25d569e22a2a261055aff85b4435b

Contents?: true

Size: 1.45 KB

Versions: 8

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true
require "pathname"

module ThemeCheck
  class Theme
    DEFAULT_LOCALE_REGEXP = %r{^locales/(.*)\.default$}
    LIQUID_REGEX = /\.liquid$/i
    JSON_REGEX = /\.json$/i

    def initialize(storage)
      @storage = storage
    end

    def assets
      @assets ||= @storage.files
        .select { |path| path.start_with?("assets/") }
        .map { |path| AssetFile.new(path, @storage) }
    end

    def liquid
      @liquid ||= @storage.files
        .select { |path| LIQUID_REGEX.match?(path) }
        .map { |path| Template.new(path, @storage) }
    end

    def json
      @json ||= @storage.files
        .select { |path| JSON_REGEX.match?(path) }
        .map { |path| JsonFile.new(path, @storage) }
    end

    def directories
      @storage.directories
    end

    def default_locale_json
      return @default_locale_json if defined?(@default_locale_json)
      @default_locale_json = json.find do |json_file|
        json_file.name.match?(DEFAULT_LOCALE_REGEXP)
      end
    end

    def default_locale
      if default_locale_json
        default_locale_json.name[DEFAULT_LOCALE_REGEXP, 1]
      else
        "en"
      end
    end

    def all
      @all ||= json + liquid + assets
    end

    def [](name)
      all.find { |t| t.name == name }
    end

    def templates
      liquid.select(&:template?)
    end

    def sections
      liquid.select(&:section?)
    end

    def snippets
      liquid.select(&:snippet?)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
theme-check-0.8.3 lib/theme_check/theme.rb
theme-check-0.8.2 lib/theme_check/theme.rb
theme-check-0.8.1 lib/theme_check/theme.rb
theme-check-0.8.0 lib/theme_check/theme.rb
theme-check-0.7.3 lib/theme_check/theme.rb
theme-check-0.7.2 lib/theme_check/theme.rb
theme-check-0.7.1 lib/theme_check/theme.rb
theme-check-0.7.0 lib/theme_check/theme.rb