Class: ShopifyCLI::Theme::Root
- Inherits:
-
Object
- Object
- ShopifyCLI::Theme::Root
- Defined in:
- lib/shopify_cli/theme/root.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #[](file) ⇒ Object
- #file?(path, raise_on_dir = false) ⇒ Boolean
- #glob(pattern, raise_on_dir: false) ⇒ Object
-
#initialize(ctx, root:) ⇒ Root
constructor
A new instance of Root.
- #json_files ⇒ Object
- #liquid_files ⇒ Object
- #static_asset_file?(file) ⇒ Boolean
- #static_asset_files ⇒ Object
- #static_asset_paths ⇒ Object
Constructor Details
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
8 9 10 |
# File 'lib/shopify_cli/theme/root.rb', line 8 def ctx @ctx end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
8 9 10 |
# File 'lib/shopify_cli/theme/root.rb', line 8 def root @root end |
Instance Method Details
#[](file) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/shopify_cli/theme/root.rb', line 42 def [](file) case file when File file when Pathname File.new(file, root) when String File.new(root.join(file), root) end end |
#file?(path, raise_on_dir = false) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/shopify_cli/theme/root.rb', line 53 def file?(path, raise_on_dir = false) if raise_on_dir && ::File.directory?(path) @ctx.abort(@ctx.("theme.serve.error.invalid_subdirectory", path.to_s)) end ::File.file?(path) end |
#glob(pattern, raise_on_dir: false) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/shopify_cli/theme/root.rb', line 27 def glob(pattern, raise_on_dir: false) root .glob(pattern) .select { |path| file?(path, raise_on_dir) } .map { |path| File.new(path, root) } end |
#json_files ⇒ Object
23 24 25 |
# File 'lib/shopify_cli/theme/root.rb', line 23 def json_files glob("**/*.json") end |
#liquid_files ⇒ Object
19 20 21 |
# File 'lib/shopify_cli/theme/root.rb', line 19 def liquid_files glob("**/*.liquid") end |
#static_asset_file?(file) ⇒ Boolean
34 35 36 |
# File 'lib/shopify_cli/theme/root.rb', line 34 def static_asset_file?(file) static_asset_files.include?(self[file]) end |
#static_asset_files ⇒ Object
15 16 17 |
# File 'lib/shopify_cli/theme/root.rb', line 15 def static_asset_files glob("assets/*", raise_on_dir: true).reject(&:liquid?) end |
#static_asset_paths ⇒ Object
38 39 40 |
# File 'lib/shopify_cli/theme/root.rb', line 38 def static_asset_paths static_asset_files.map(&:relative_path) end |