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 Method Summary collapse

Constructor Details

#initialize(storage) ⇒ Theme

Returns a new instance of Theme.



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

def initialize(storage)
  @storage = storage
end

Instance Method Details

#[](name) ⇒ Object



49
50
51
# File 'lib/theme_check/theme.rb', line 49

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

#allObject



45
46
47
# File 'lib/theme_check/theme.rb', line 45

def all
  @all ||= json + liquid
end

#default_localeObject



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

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

#default_locale_jsonObject



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

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

#directoriesObject



26
27
28
# File 'lib/theme_check/theme.rb', line 26

def directories
  @storage.directories
end

#jsonObject



20
21
22
23
24
# File 'lib/theme_check/theme.rb', line 20

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

#liquidObject



14
15
16
17
18
# File 'lib/theme_check/theme.rb', line 14

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

#sectionsObject



57
58
59
# File 'lib/theme_check/theme.rb', line 57

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

#snippetsObject



61
62
63
# File 'lib/theme_check/theme.rb', line 61

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

#templatesObject



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

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