Class: ThemeCheck::Theme
- Inherits:
-
Object
- Object
- ThemeCheck::Theme
- 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
- #[](name) ⇒ Object
- #all ⇒ Object
- #assets ⇒ Object
- #default_locale ⇒ Object
- #default_locale_json ⇒ Object
- #directories ⇒ Object
-
#initialize(storage) ⇒ Theme
constructor
A new instance of Theme.
- #json ⇒ Object
- #liquid ⇒ Object
- #sections ⇒ Object
- #snippets ⇒ Object
- #templates ⇒ Object
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
55 56 57 |
# File 'lib/theme_check/theme.rb', line 55 def [](name) all.find { |t| t.name == name } end |
#all ⇒ Object
51 52 53 |
# File 'lib/theme_check/theme.rb', line 51 def all @all ||= json + liquid + assets end |
#assets ⇒ Object
14 15 16 17 18 |
# File 'lib/theme_check/theme.rb', line 14 def assets @assets ||= @storage.files .select { |path| path.start_with?("assets/") } .map { |path| AssetFile.new(path, @storage) } end |
#default_locale ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/theme_check/theme.rb', line 43 def default_locale if default_locale_json default_locale_json.name[DEFAULT_LOCALE_REGEXP, 1] else "en" end end |
#default_locale_json ⇒ Object
36 37 38 39 40 41 |
# File 'lib/theme_check/theme.rb', line 36 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 |
#directories ⇒ Object
32 33 34 |
# File 'lib/theme_check/theme.rb', line 32 def directories @storage.directories end |
#json ⇒ Object
26 27 28 29 30 |
# File 'lib/theme_check/theme.rb', line 26 def json @json ||= @storage.files .select { |path| JSON_REGEX.match?(path) } .map { |path| JsonFile.new(path, @storage) } end |
#liquid ⇒ Object
20 21 22 23 24 |
# File 'lib/theme_check/theme.rb', line 20 def liquid @liquid ||= @storage.files .select { |path| LIQUID_REGEX.match?(path) } .map { |path| Template.new(path, @storage) } end |
#sections ⇒ Object
63 64 65 |
# File 'lib/theme_check/theme.rb', line 63 def sections liquid.select(&:section?) end |
#snippets ⇒ Object
67 68 69 |
# File 'lib/theme_check/theme.rb', line 67 def snippets liquid.select(&:snippet?) end |
#templates ⇒ Object
59 60 61 |
# File 'lib/theme_check/theme.rb', line 59 def templates liquid.select(&:template?) end |