Class: BooticCli::Themes::APITheme

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

Defined Under Namespace

Classes: EntityErrors

Instance Method Summary collapse

Constructor Details

#initialize(theme) ⇒ APITheme

Returns a new instance of APITheme.



66
67
68
69
# File 'lib/bootic_cli/themes/api_theme.rb', line 66

def initialize(theme)
  @theme = theme
  puts "Entity has errors: #{theme.errors.map(&:messages).join(', ')}" if theme.has?(:errors)
end

Instance Method Details

#add_asset(file_name, file) ⇒ Object



119
120
121
122
123
124
# File 'lib/bootic_cli/themes/api_theme.rb', line 119

def add_asset(file_name, file)
  check_errors! theme.create_theme_asset(
    file_name: file_name,
    data: file
  )
end

#add_template(file_name, body) ⇒ Object



107
108
109
110
111
112
# File 'lib/bootic_cli/themes/api_theme.rb', line 107

def add_template(file_name, body)
  check_errors! theme.create_template(
    file_name: file_name,
    body: body
  )
end

#assetsObject



103
104
105
# File 'lib/bootic_cli/themes/api_theme.rb', line 103

def assets
  @assets ||= theme.assets.map { |t| APIAsset.new(t) }
end

#dev?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/bootic_cli/themes/api_theme.rb', line 76

def dev?
  theme.can?(:publish_theme)
end

#pathObject



87
88
89
# File 'lib/bootic_cli/themes/api_theme.rb', line 87

def path
  theme.rels[:theme_preview].href
end

#public?Boolean

this is unique to API themes

Returns:

  • (Boolean)


72
73
74
# File 'lib/bootic_cli/themes/api_theme.rb', line 72

def public?
  !dev?
end

#publish(opts = {}) ⇒ Object



80
81
82
83
84
85
# File 'lib/bootic_cli/themes/api_theme.rb', line 80

def publish(opts = {})
  if theme.can?(:publish_theme)
    @theme = theme.publish_theme(opts)
    reload!(false)
  end
end

#reload!(refetch = true) ⇒ Object

Implement generic Theme interface



92
93
94
95
96
97
# File 'lib/bootic_cli/themes/api_theme.rb', line 92

def reload!(refetch = true)
  @templates = nil
  @assets = nil
  @theme = theme.self if refetch
  self
end

#remove_asset(file_name) ⇒ Object



126
127
128
129
# File 'lib/bootic_cli/themes/api_theme.rb', line 126

def remove_asset(file_name)
  asset = theme.assets.find{|t| t.file_name == file_name }
  check_errors!(asset.delete_theme_asset) if asset
end

#remove_template(file_name) ⇒ Object



114
115
116
117
# File 'lib/bootic_cli/themes/api_theme.rb', line 114

def remove_template(file_name)
  tpl = theme.templates.find { |t| t.file_name == file_name }
  check_errors!(tpl.delete_template) if tpl && tpl.can?(:delete_template)
end

#templatesObject



99
100
101
# File 'lib/bootic_cli/themes/api_theme.rb', line 99

def templates
  @templates ||= theme.templates.map { |t| ItemWithTime.new(t) }
end