Module: Grat::System

Included in:
Application
Defined in:
lib/grat/system.rb

Instance Method Summary collapse

Instance Method Details

#contentObject



31
32
33
# File 'lib/grat/system.rb', line 31

def content
  @content ||= model.find_by_url(url) || new_content
end

#focus_paramsObject



57
58
59
# File 'lib/grat/system.rb', line 57

def focus_params
  params[:content].reject {|k,v| k == 'submit'}
end

#missing_pageObject



61
62
63
# File 'lib/grat/system.rb', line 61

def missing_page
  haml :missing
end

#modelObject



47
48
49
50
51
52
53
54
55
# File 'lib/grat/system.rb', line 47

def model
  return @model if @model
  
  # Sinatra reloads are slow when mongoid has to re-require
  # This avoids requiring mongoid when it isn't needed
  Grat.database_load
  
  @model = Grat::Content
end

#new_contentObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/grat/system.rb', line 35

def new_content
  content = model.new(:url => url)
  if params[:template]
    template = model.find_by_url params[:template]
    if template
      content.template_url = template.url
      content.suggested_fields = template.default_content_vars.keys
    end
  end
  content
end

#request_typeObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/grat/system.rb', line 12

def request_type
  case env['HTTP_ACCEPT']
  when /html/
    'html'
  when /json/
    'json'
  when /xml/ #?
    'xml'
  end
end

#template_chainObject



2
3
4
5
6
7
8
9
10
# File 'lib/grat/system.rb', line 2

def template_chain
  current = content
  collection = [content]
  while current.template
    current = current.template
    collection << current
  end
  collection
end

#urlObject



27
28
29
# File 'lib/grat/system.rb', line 27

def url
  '/' + params[:splat].join('/')
end