Class: Locomotive::Steam::Middlewares::EntrySubmission
- Inherits:
-
ThreadSafe
- Object
- ThreadSafe
- Locomotive::Steam::Middlewares::EntrySubmission
- Includes:
- Helpers
- Defined in:
- lib/locomotive/steam/middlewares/entry_submission.rb
Overview
Submit a content entry and persist it
Constant Summary collapse
- HTTP_REGEXP =
/^https?:\/\//o- ENTRY_SUBMISSION_REGEXP =
/^\/entry_submissions\/(\w+)/o- SUBMITTED_TYPE_PARAM =
'submitted_type_slug'- SUBMITTED_PARAM =
'submitted_entry_slug'- CONTENT_TYPE_PARAM =
'content_type_slug'
Instance Attribute Summary
Attributes inherited from ThreadSafe
Instance Method Summary collapse
- #_call ⇒ Object
-
#navigation_behavior(entry) ⇒ Object
Render or redirect depending on: - the status of the content entry (valid or not) - the presence of a callback or not - the type of response asked by the browser (html or json).
- #navigation_error(entry) ⇒ Object
- #navigation_html_error(entry) ⇒ Object
- #navigation_success(entry) ⇒ Object
Methods included from Helpers
#html?, #json?, #log, #make_local_path, #modify_path, #mounted_on, #redirect_to, #render_response
Methods inherited from ThreadSafe
#call, #default_locale, #liquid_assigns, #live_editing?, #locale, #next, #page, #params, #path, #request, #services, #site
Instance Method Details
#_call ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/locomotive/steam/middlewares/entry_submission.rb', line 16 def _call # we didn't go through the locale middleware yet, # so set the locale manually. Needed to build a localized # version of the entry + error messages (if present). with_locale do if slug = get_content_type_slug entry = create_entry(slug) (entry) else fetch_entry end end end |
#navigation_behavior(entry) ⇒ Object
Render or redirect depending on:
-
the status of the content entry (valid or not)
-
the presence of a callback or not
-
the type of response asked by the browser (html or json)
35 36 37 38 39 40 41 42 43 |
# File 'lib/locomotive/steam/middlewares/entry_submission.rb', line 35 def (entry) if entry.nil? raise 'TODO' elsif entry.errors.empty? (entry) else (entry) end end |
#navigation_error(entry) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/locomotive/steam/middlewares/entry_submission.rb', line 53 def (entry) if html? (entry) elsif json? json_response(entry, 422) end end |
#navigation_html_error(entry) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/locomotive/steam/middlewares/entry_submission.rb', line 61 def (entry) if error_location =~ HTTP_REGEXP redirect_to error_location else env['PATH_INFO'] = make_local_path(error_location) store_in_liquid(entry) self.next end end |
#navigation_success(entry) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/locomotive/steam/middlewares/entry_submission.rb', line 45 def (entry) if html? redirect_to success_location(entry_to_query_string(entry)) elsif json? json_response(entry) end end |