Sha256: f81fa3bababaa9467f01d139e1c24ee908fd6fb0eb079d5bb4a6c4c9e379b569
Contents?: true
Size: 1.69 KB
Versions: 13
Compression:
Stored size: 1.69 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 attr_reader :storage attr_writer :default_locale_json 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| LiquidFile.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_or_relative_path) case name_or_relative_path when Pathname all.find { |t| t.relative_path == name_or_relative_path } else all.find { |t| t.name == name_or_relative_path } end end def templates liquid.select(&:template?) end def sections liquid.select(&:section?) end def snippets liquid.select(&:snippet?) end end end
Version data entries
13 entries across 13 versions & 1 rubygems