Class: Cms::DynamicView

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
DefaultAccessible
Defined in:
app/models/cms/dynamic_view.rb

Direct Known Subclasses

PagePartial, PageTemplate

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_pathObject



48
49
50
# File 'app/models/cms/dynamic_view.rb', line 48

def self.base_path
  File.join(Rails.root, "tmp", "views")
end

.default_bodyObject



81
82
83
# File 'app/models/cms/dynamic_view.rb', line 81

def self.default_body
  ""
end

.engineObject

So that route lookup works for these resources. See PathHelper#cms_index_path_for



102
103
104
# File 'app/models/cms/dynamic_view.rb', line 102

def self.engine
  "cms"
end

.find_by_file_name(file_name) ⇒ Object



44
45
46
# File 'app/models/cms/dynamic_view.rb', line 44

def self.find_by_file_name(file_name)
  with_file_name(file_name).first
end

.form_nameObject



52
53
54
# File 'app/models/cms/dynamic_view.rb', line 52

def self.form_name
  ActiveModel::Naming.singular(self)
end

.new_with_defaults(options = {}) ⇒ Object



40
41
42
# File 'app/models/cms/dynamic_view.rb', line 40

def self.new_with_defaults(options={})
  new({:format => "html", :handler => "erb", :body => default_body}.merge(options))
end

.resource_collection_nameObject

Default implementation



96
97
98
# File 'app/models/cms/dynamic_view.rb', line 96

def self.resource_collection_name
  model_name.underscore
end

.resource_nameObject

Get the plural symbol for a particular resource. i.e. Cms::PageTemplate -> :page_templates



91
92
93
# File 'app/models/cms/dynamic_view.rb', line 91

def self.resource_name
  resource_collection_name.pluralize
end

.write_all_to_disk!Object



71
72
73
# File 'app/models/cms/dynamic_view.rb', line 71

def self.write_all_to_disk!
  all(:conditions => {:deleted => false}).each { |v| v.write_file_to_disk }
end

Instance Method Details

#display_nameObject



60
61
62
# File 'app/models/cms/dynamic_view.rb', line 60

def display_name
  self.class.display_name(file_name)
end

#file_nameObject



56
57
58
# File 'app/models/cms/dynamic_view.rb', line 56

def file_name
  "#{name}.#{format}.#{handler}"
end

#remove_file_from_diskObject



75
76
77
78
79
# File 'app/models/cms/dynamic_view.rb', line 75

def remove_file_from_disk
  if respond_to?(:file_path) && File.exists?(file_path)
    File.delete(file_path)
  end
end

#set_publish_on_saveObject



85
86
87
# File 'app/models/cms/dynamic_view.rb', line 85

def set_publish_on_save
  self.publish_on_save = true
end

#write_file_to_diskObject



64
65
66
67
68
69
# File 'app/models/cms/dynamic_view.rb', line 64

def write_file_to_disk
  if respond_to?(:file_path) && !file_path.blank?
    FileUtils.mkpath(File.dirname(file_path))
    open(file_path, 'w') { |f| f << body }
  end
end