Class: Optimacms::PageServices::TemplateService

Inherits:
Object
  • Object
show all
Defined in:
lib/optimacms/page_services/template_service.rb

Class Method Summary collapse

Class Method Details

.get_by_name(name) ⇒ Object



5
6
7
8
9
# File 'lib/optimacms/page_services/template_service.rb', line 5

def self.get_by_name(name)
  row = Template.where(basepath: name).first

  row
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/optimacms/page_services/template_service.rb', line 12

def self.get_links_edit(tpl)

  f_meta = File.join(File.dirname(tpl.fullpath), tpl.basename+".meta.yml")

  return [] unless File.exists?(f_meta)

  data = YAML.load(File.read(f_meta))

  links = data['links'] || []


  links

end

.get_tpl_data_relations(tpl) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/optimacms/page_services/template_service.rb', line 27

def self.get_tpl_data_relations(tpl)

  # data relations
  tpl_data_relations = {}
  if row_tpl
    tpl_data_relations = row_tpl.data_relations.all.index_by { |t| t.var_name }
  end


  # map locals and edit links
  links_data = []

  opts.each do |_var_name, v|
    var_name = _var_name.to_s

    next unless tpl_data_relations[var_name]
    data = tpl_data_relations[var_name]

    #if class exists $modelDecorator
    #klass = Object.const_get "#{p['model']}CmsDecorator"
    #objDecorator = klass.new(v)
    #classify.
    modelEditDecorator = "#{data.data_model_name}CmsDecorator".safe_constantize.new(v)

    next unless modelEditDecorator

    link_edit = modelEditDecorator.edit_path

    next unless link_edit

    #p = tpl_data_relations[var_name]
    #id = v.send(:id)
    #links_edit << {link: send(p["root_edit"]+"_path", id)}
    link_html = link_to("edit #{data.title}", link_edit, target: "_blank")
    links_data << {link: link_edit, link_html: link_html}
  end



end