Class: BooticCli::Themes::APITheme
- Inherits:
-
Object
- Object
- BooticCli::Themes::APITheme
- Defined in:
- lib/bootic_cli/themes/api_theme.rb
Defined Under Namespace
Classes: EntityErrors
Instance Method Summary collapse
- #add_asset(file_name, file) ⇒ Object
- #add_template(file_name, body) ⇒ Object
- #assets ⇒ Object
- #dev? ⇒ Boolean
-
#initialize(theme) ⇒ APITheme
constructor
A new instance of APITheme.
- #path ⇒ Object
-
#public? ⇒ Boolean
this is unique to API themes.
- #publish(opts = {}) ⇒ Object
-
#reload!(refetch = true) ⇒ Object
Implement generic Theme interface.
- #remove_asset(file_name) ⇒ Object
- #remove_template(file_name) ⇒ Object
- #templates ⇒ Object
Constructor Details
#initialize(theme) ⇒ APITheme
Returns a new instance of APITheme.
69 70 71 72 |
# 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 |
Instance Method Details
#add_asset(file_name, file) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 127 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
110 111 112 113 114 115 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 110 def add_template(file_name, body) check_errors! theme.create_template( file_name: file_name, body: body ) end |
#assets ⇒ Object
106 107 108 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 106 def assets @assets ||= theme.assets.map { |t| APIAsset.new(t) } end |
#dev? ⇒ Boolean
79 80 81 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 79 def dev? theme.can?(:publish_theme) end |
#path ⇒ Object
90 91 92 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 90 def path theme.rels[:theme_preview].href end |
#public? ⇒ Boolean
this is unique to API themes
75 76 77 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 75 def public? !dev? end |
#publish(opts = {}) ⇒ Object
83 84 85 86 87 88 |
# 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) ⇒ Object
Implement generic Theme interface
95 96 97 98 99 100 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 95 def reload!(refetch = true) @templates = nil @assets = nil @theme = theme.self if refetch self end |
#remove_asset(file_name) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 134 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 check_errors!(res) if res.respond_to?(:can?) else puts "Cannot delete asset: #{file_name}" end end |
#remove_template(file_name) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 117 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 check_errors!(res) if res.respond_to?(:can?) else puts "Cannot delete #{file_name}" end end |
#templates ⇒ Object
102 103 104 |
# File 'lib/bootic_cli/themes/api_theme.rb', line 102 def templates @templates ||= theme.templates.map { |t| ItemWithTime.new(t) } end |