Method: Burp::PageModel.find

Defined in:
app/models/burp/page_model.rb

.find(path) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/models/burp/page_model.rb', line 36

def self.find(path)

  fixed_path = path == '/' ? '/#root' : path
  on_disk_path =  Burp.content_directory+"pages/" + fixed_path
  on_disk_path = on_disk_path.gsub('//','/')

  if File.directory?(on_disk_path) && File.exist?("#{on_disk_path}/page.json")
  
    data = {}
    Dir.glob(on_disk_path+"/*.html").each do |snippet_path|
      name = File.basename(snippet_path).split('.').first
      data[name.to_sym] = File.read(snippet_path).html_safe
    end
  
    page_data = File.exist?("#{on_disk_path}/page.json") ? JSON.parse(File.read("#{on_disk_path}/page.json")) : {}
  
    PageModel.new(:snippets => data, :title => page_data['title'], :meta_description => page_data['meta_description'], :path => path, :original_path => path)
  else
    nil
  end
end