Class: ThemeCheck::Theme

Inherits:
Object
  • Object
show all
Defined in:
lib/theme_check/theme.rb

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(storage) ⇒ Theme

Returns a new instance of Theme.



13
14
15
# File 'lib/theme_check/theme.rb', line 13

def initialize(storage)
  @storage = storage
end

Instance Attribute Details

#default_locale_jsonObject



39
40
41
42
43
44
# File 'lib/theme_check/theme.rb', line 39

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

#storageObject (readonly)

Returns the value of attribute storage.



10
11
12
# File 'lib/theme_check/theme.rb', line 10

def storage
  @storage
end

Instance Method Details

#[](name_or_relative_path) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/theme_check/theme.rb', line 58

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

#allObject



54
55
56
# File 'lib/theme_check/theme.rb', line 54

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

#assetsObject



17
18
19
20
21
# File 'lib/theme_check/theme.rb', line 17

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

#default_localeObject



46
47
48
49
50
51
52
# File 'lib/theme_check/theme.rb', line 46

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

#directoriesObject



35
36
37
# File 'lib/theme_check/theme.rb', line 35

def directories
  @storage.directories
end

#jsonObject



29
30
31
32
33
# File 'lib/theme_check/theme.rb', line 29

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

#liquidObject



23
24
25
26
27
# File 'lib/theme_check/theme.rb', line 23

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

#sectionsObject



71
72
73
# File 'lib/theme_check/theme.rb', line 71

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

#snippetsObject



75
76
77
# File 'lib/theme_check/theme.rb', line 75

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

#templatesObject



67
68
69
# File 'lib/theme_check/theme.rb', line 67

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