Sha256: 689ce660b4774a542cc40ef5bae26da7c5ace3e5424635e259ed62a0e08511fc
Contents?: true
Size: 1.69 KB
Versions: 5
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
5 entries across 5 versions & 1 rubygems