Class: Layout

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/layout.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_default(sid, user_id) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/layout.rb', line 61

def self.create_default(sid, user_id)
  layout = Layout.new(:path=>"layouts/#{sid}/application", :handler=>"haml", :format=>"html", :locale=>"en", :system_id=>sid, :user_id=>user_id, :name=>"application", :body=><<eos
!!!
%html
/ Layout: application [#{sid}]
%head
  = render :partial=>"layouts/kit_header"
  %style(type="text/css")
    div#edit_link { top:30px; }
%body
  = yield
eos
)

  layout.save!
end

.default(sid) ⇒ Object



57
58
59
# File 'app/models/layout.rb', line 57

def self.default(sid) 
  Layout.sys(sid).order(:id).first
end

.name_exists?(sid, name) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'app/models/layout.rb', line 53

def self.name_exists?(sid, name)
  Layout.sys(sid).where("name = '#{name}'").count > 0
end

.preference(sid, name) ⇒ Object



94
95
96
97
98
# File 'app/models/layout.rb', line 94

def self.preference(sid, name)
  l = Layout.sys(sid).where(:id=>Preference.get_cached(sid, name)).first rescue nil
  return l if l
  Layout.sys(sid).order("created_at").first
end

Instance Method Details

#display_nameObject



23
24
25
# File 'app/models/layout.rb', line 23

def display_name
  "Layout"
end

#handler_enumObject



49
50
51
# File 'app/models/layout.rb', line 49

def handler_enum
  ['haml', 'erb', 'builder']
end

#historyObject



33
34
35
# File 'app/models/layout.rb', line 33

def history
  DesignHistory.sys(self.system_id).where(:model=>"Layout").where(:model_id=>self.id).order("id desc")
end

#javascriptsObject



78
79
80
# File 'app/models/layout.rb', line 78

def javascripts
  self.html_assets.where(:file_type=>"js").all
end

#locale_enumObject



45
46
47
# File 'app/models/layout.rb', line 45

def locale_enum
  ['en']
end

#make_pathObject



37
38
39
# File 'app/models/layout.rb', line 37

def make_path
  self.path = "layouts/#{self.system_id}/#{self.name.urlise}"
end

#old_javascriptsObject



90
91
92
# File 'app/models/layout.rb', line 90

def old_javascripts
  self.read_attribute(:javascripts)
end

#old_stylesheetsObject



86
87
88
# File 'app/models/layout.rb', line 86

def old_stylesheets
  self.read_attribute(:stylesheets)
end

#record_historyObject



27
28
29
30
31
# File 'app/models/layout.rb', line 27

def record_history
  if self.changed.include?('body')
    DesignHistory.record(self)
  end
end

#set_formatObject



41
42
43
# File 'app/models/layout.rb', line 41

def set_format
  self.format = 'html'
end

#stylesheetsObject



82
83
84
# File 'app/models/layout.rb', line 82

def stylesheets
  self.html_assets.where(:file_type=>"css").all
end