Module: Grat::System
- Included in:
- Application
- Defined in:
- lib/grat/system.rb
Instance Method Summary collapse
- #content ⇒ Object
- #focus_params ⇒ Object
- #missing_page ⇒ Object
- #model ⇒ Object
- #new_content ⇒ Object
- #request_type ⇒ Object
- #template_chain ⇒ Object
- #url ⇒ Object
Instance Method Details
#content ⇒ Object
31 32 33 |
# File 'lib/grat/system.rb', line 31 def content @content ||= model.find_by_url(url) || new_content end |
#focus_params ⇒ Object
57 58 59 |
# File 'lib/grat/system.rb', line 57 def focus_params params[:content].reject {|k,v| k == 'submit'} end |
#missing_page ⇒ Object
61 62 63 |
# File 'lib/grat/system.rb', line 61 def missing_page haml :missing end |
#model ⇒ Object
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_content ⇒ Object
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_type ⇒ Object
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_chain ⇒ Object
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 |
#url ⇒ Object
27 28 29 |
# File 'lib/grat/system.rb', line 27 def url '/' + params[:splat].join('/') end |