Module: Exo::ViewGenerator

Defined in:
app/services/exo/view_generator.rb

Overview

Help to generate views

  • application layout

  • route page views

Class Method Summary collapse

Class Method Details

.ensure_page_view(page, &content_delegate) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/exo/view_generator.rb', line 5

def self.ensure_page_view page, &content_delegate
  file_path = join_views_path page.site.theme_path, "#{page.view_path}.html.haml"

  ensure_folder_chain file_path
  
  file_path = nil if File.exists? file_path

  if file_path
    content = nil
    if content_delegate
      content = content_delegate.call
    else
      content = template_content 'page.html.haml'
      content = content.gsub 'SLUG_ID', page.slug_id if content
    end
    File.open(file_path, 'w') {|f| f.write content}
  end
  file_path
end

.ensure_site_layout(site, &content_delegate) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/exo/view_generator.rb', line 25

def self.ensure_site_layout site, &content_delegate
  folder_path = join_views_path 'layouts', site.theme_path
  Dir.mkdir folder_path unless File.exists? folder_path

  file_path = File.join folder_path, "application.html.haml"

  file_path = nil if File.exists? file_path

  if file_path
    content = nil
    if content_delegate
      content = content_delegate.call
    else
      content = template_content 'application.html.haml'
    end
    File.open(file_path, 'w') {|f| f.write content}
  end
  file_path
end