Class: Optimacms::PageServices::PageData

Inherits:
Object
  • Object
show all
Includes:
PageProcessService
Defined in:
lib/optimacms/page_services/page_data.rb

Overview

data used for processing page

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PageProcessService

#compile_content, #generate_view_name, #save_text_to_compiled_view

Instance Attribute Details

#actionObject

Returns the value of attribute action.



9
10
11
# File 'lib/optimacms/page_services/page_data.rb', line 9

def action
  @action
end

#compiled_view_pathObject (readonly)

Returns the value of attribute compiled_view_path.



14
15
16
# File 'lib/optimacms/page_services/page_data.rb', line 14

def compiled_view_path
  @compiled_view_path
end

#controllerObject

Returns the value of attribute controller.



9
10
11
# File 'lib/optimacms/page_services/page_data.rb', line 9

def controller
  @controller
end

#langObject

Returns the value of attribute lang.



8
9
10
# File 'lib/optimacms/page_services/page_data.rb', line 8

def lang
  @lang
end

#layoutObject

Returns the value of attribute layout.



10
11
12
# File 'lib/optimacms/page_services/page_data.rb', line 10

def layout
  @layout
end

#pageObject

page object



5
6
7
# File 'lib/optimacms/page_services/page_data.rb', line 5

def page
  @page
end

#templateObject

Returns the value of attribute template.



11
12
13
# File 'lib/optimacms/page_services/page_data.rb', line 11

def template
  @template
end

#urlObject

, :params



7
8
9
# File 'lib/optimacms/page_services/page_data.rb', line 7

def url
  @url
end

#url_varsObject

, :params



7
8
9
# File 'lib/optimacms/page_services/page_data.rb', line 7

def url_vars
  @url_vars
end

Instance Method Details

#compiled_view_filenameObject



68
69
70
# File 'lib/optimacms/page_services/page_data.rb', line 68

def compiled_view_filename
  dir_cache+'/'+@compiled_view_basename
end

#controller_classObject



18
19
20
# File 'lib/optimacms/page_services/page_data.rb', line 18

def controller_class
  Object.const_get controller.to_s.camelize+'Controller'
end

#dir_cacheObject



81
82
83
84
# File 'lib/optimacms/page_services/page_data.rb', line 81

def dir_cache
  # TODO: get from settings

  Rails.root.to_s+'/app/views/'+dirname_views
end

#dirname_viewsObject



77
78
79
# File 'lib/optimacms/page_services/page_data.rb', line 77

def dirname_views
  'optimacms/cache'
end

#generate_contentObject



87
88
89
90
91
92
93
# File 'lib/optimacms/page_services/page_data.rb', line 87

def generate_content
  @compiled_view_basename = generate_view_name
  Optimacms::Fileutils::Fileutils::create_dir_if_not_exists compiled_view_filename

  text = compile_content view_content
  save_text_to_compiled_view text
end

#metaObject



46
47
48
49
50
51
52
53
# File 'lib/optimacms/page_services/page_data.rb', line 46

def meta
  page_lang = page.is_translated ? lang : ''
  row = page.translations.where(:lang=>page_lang).first

  return nil if row.nil?

  {:title=>row.meta_title, :keywords=>row.meta_keywords, :description=>row.meta_description}
end

#view_contentObject



55
56
57
58
59
60
61
# File 'lib/optimacms/page_services/page_data.rb', line 55

def view_content
  return '' if template.basepath.nil?

  f = template.fullpath
  return '' if !File.exists? f
  File.read(f)
end

#view_filenameObject



63
64
65
66
# File 'lib/optimacms/page_services/page_data.rb', line 63

def view_filename
  #Rails.root.to_s + '/app/views/'+view_path

  page.template.fullpath
end