Class: ShopifyCLI::Theme::Root

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

Direct Known Subclasses

Theme

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, root:) ⇒ Root

Returns a new instance of Root.



10
11
12
13
# File 'lib/shopify_cli/theme/root.rb', line 10

def initialize(ctx, root:)
  @ctx = ctx
  @root = Pathname.new(root) if root
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



8
9
10
# File 'lib/shopify_cli/theme/root.rb', line 8

def ctx
  @ctx
end

#rootObject (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

Returns:

  • (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.message("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_filesObject



23
24
25
# File 'lib/shopify_cli/theme/root.rb', line 23

def json_files
  glob("**/*.json")
end

#liquid_filesObject



19
20
21
# File 'lib/shopify_cli/theme/root.rb', line 19

def liquid_files
  glob("**/*.liquid")
end

#static_asset_file?(file) ⇒ Boolean

Returns:

  • (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_filesObject



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_pathsObject



38
39
40
# File 'lib/shopify_cli/theme/root.rb', line 38

def static_asset_paths
  static_asset_files.map(&:relative_path)
end