Class: LatoCms::TemplateManager
- Inherits:
-
Object
- Object
- LatoCms::TemplateManager
- Defined in:
- app/models/lato_cms/template_manager.rb
Class Method Summary collapse
- .components ⇒ Object
- .components_path ⇒ Object
- .find_component(component_id) ⇒ Object
- .find_template(template_id) ⇒ Object
- .resolve_template_components(template) ⇒ Object
- .template_options ⇒ Object
- .templates ⇒ Object
- .templates_path ⇒ Object
Class Method Details
.components ⇒ Object
16 17 18 |
# File 'app/models/lato_cms/template_manager.rb', line 16 def components load_yaml_files(components_path) end |
.components_path ⇒ Object
8 9 10 |
# File 'app/models/lato_cms/template_manager.rb', line 8 def components_path Rails.root.join(LatoCms.config.templates_path, 'components') end |
.find_component(component_id) ⇒ Object
25 26 27 28 |
# File 'app/models/lato_cms/template_manager.rb', line 25 def find_component(component_id) return nil if component_id.blank? components.find { |c| c['id'] == component_id.to_s } end |
.find_template(template_id) ⇒ Object
20 21 22 23 |
# File 'app/models/lato_cms/template_manager.rb', line 20 def find_template(template_id) return nil if template_id.blank? templates.find { |t| t['id'] == template_id.to_s } end |
.resolve_template_components(template) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/lato_cms/template_manager.rb', line 34 def resolve_template_components(template) return [] unless template && template['components'] template['components'].map do |tc_id, tc_config| component = find_component(tc_config['component_id']) { template_component_id: tc_id.to_s, component_id: tc_config['component_id'].to_s, name: tc_config['name'].presence || component&.dig('name') || tc_config['component_id'].to_s.humanize, required: tc_config['required'] == true, component: component, fields: component ? (component['fields'] || {}) : {} } end end |
.template_options ⇒ Object
30 31 32 |
# File 'app/models/lato_cms/template_manager.rb', line 30 def templates.map { |t| [t['name'], t['id']] } end |
.templates ⇒ Object
12 13 14 |
# File 'app/models/lato_cms/template_manager.rb', line 12 def templates load_yaml_files(templates_path) end |