class BooticCli::Themes::APITheme
Attributes
theme[R]
Public Class Methods
new(theme)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 69 def initialize(theme) @theme = theme puts "Entity has errors: #{theme.errors.map(&:messages).join(', ')}" if theme.has?(:errors) end
Public Instance Methods
add_asset(file_name, file)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 143 def add_asset(file_name, file) check_errors! theme.create_theme_asset( file_name: file_name, data: file ) end
add_template(file_name, body)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 118 def add_template(file_name, body) params = { file_name: file_name, body: body } if ts = get_updated_on(file_name) params.merge!(last_updated_on: ts.to_i) end check_errors!(theme.create_template(params)).tap do |entity| template_updated(file_name, entity) end end
assets()
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 114 def assets @assets ||= theme.assets.map { |t| APIAsset.new(t) } end
delete!()
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 90 def delete! if theme.can?(:delete_theme) res = theme.delete_theme return res.status <= 204 end false end
dev?()
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 79 def dev? theme.can?(:publish_theme) end
path()
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 98 def path theme.rels[:theme_preview].href end
public?()
click to toggle source
this is unique to API themes
# File lib/bootic_cli/themes/api_theme.rb, line 75 def public? !dev? end
publish(opts = {})
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 83 def publish(opts = {}) if theme.can?(:publish_theme) @theme = theme.publish_theme(opts) reload!(false) end end
reload!(refetch = true)
click to toggle source
Implement generic Theme interface
# File lib/bootic_cli/themes/api_theme.rb, line 103 def reload!(refetch = true) @templates = nil @assets = nil @theme = theme.self if refetch self end
remove_asset(file_name)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 150 def remove_asset(file_name) asset = theme.assets.find { |t| t.file_name == file_name } if asset and asset.can?(:delete_theme_asset) res = asset.delete_theme_asset res.status.to_i < 300 else puts "Cannot delete asset: #{file_name}" end end
remove_template(file_name)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 133 def remove_template(file_name) tpl = theme.templates.find { |t| t.file_name == file_name } if tpl && tpl.can?(:delete_template) res = tpl.delete_template res.status.to_i < 300 else puts "Cannot delete #{file_name}" end end
templates()
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 110 def templates @templates ||= theme.templates.map { |t| ItemWithTime.new(t) } end
Private Instance Methods
check_errors!(entity)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 175 def check_errors!(entity) if entity.has?(:errors) raise EntityErrors.new(entity.errors) end entity end
get_updated_on(file_name)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 163 def get_updated_on(file_name) if tpl = templates.find { |t| t.file_name == file_name } tpl.updated_on end end
template_updated(file_name, new_template)
click to toggle source
# File lib/bootic_cli/themes/api_theme.rb, line 169 def template_updated(file_name, new_template) if index = templates.index { |t| t.file_name == file_name } templates[index] = ItemWithTime.new(new_template) end end