Class: BooticCli::Themes::ThemeSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_cli/themes/theme_selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, prompt:) ⇒ ThemeSelector

Returns a new instance of ThemeSelector.



7
8
9
10
# File 'lib/bootic_cli/themes/theme_selector.rb', line 7

def initialize(root, prompt:)
  @root = root
  @prompt = prompt
end

Instance Method Details

#find_remote_shop(subdomain = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bootic_cli/themes/theme_selector.rb', line 50

def find_remote_shop(subdomain = nil)
  if !subdomain
    return root.shops.first
  end

  if root.has?(:all_shops)
    root.all_shops(subdomains: subdomain).first
  else
    root.shops.find { |s| s.subdomain == subdomain }
  end
end

#pair(subdomain, dir) ⇒ Object



35
36
37
38
39
# File 'lib/bootic_cli/themes/theme_selector.rb', line 35

def pair(subdomain, dir)
  shop = find_remote_shop(subdomain)
  raise "No shop with subdomain #{subdomain}" unless shop
  select_local_theme(dir, subdomain)
end

#select_local_theme(dir, subdomain = nil) ⇒ Object



41
42
43
# File 'lib/bootic_cli/themes/theme_selector.rb', line 41

def select_local_theme(dir, subdomain = nil)
  FSTheme.new(File.expand_path(dir), subdomain: subdomain)
end

#select_remote_theme(shop, production = false) ⇒ Object



45
46
47
48
# File 'lib/bootic_cli/themes/theme_selector.rb', line 45

def select_remote_theme(shop, production = false)
  theme = resolve_remote_theme(shop, production)
  APITheme.new(theme)
end

#select_theme_pair(subdomain, dir, production = false) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/bootic_cli/themes/theme_selector.rb', line 25

def select_theme_pair(subdomain, dir, production = false)
  local_theme = select_local_theme(dir)
  shop = find_remote_shop(local_theme.subdomain)
  raise "No shop with subdomain #{local_theme.subdomain}" unless shop
  remote_theme = select_remote_theme(shop, production)

  prompt.say "Preview this theme at #{remote_theme.path}", :magenta
  [local_theme, remote_theme]
end

#setup_theme_pair(subdomain, dir = nil, production = false) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bootic_cli/themes/theme_selector.rb', line 12

def setup_theme_pair(subdomain, dir = nil, production = false)
  shop = find_remote_shop(subdomain)
  raise "No shop with subdomain #{subdomain}" unless shop

  path = dir || shop.subdomain
  local_theme = select_local_theme(path, shop.subdomain)
  remote_theme = select_remote_theme(shop, production)

  prompt.say "Cloning theme files into #{local_theme.path}"
  prompt.say "Preview this theme at #{remote_theme.path}", :magenta
  [local_theme, remote_theme]
end