Class: Orange::BlogResource
- Inherits:
-
ModelResource
- Object
- Resource
- RoutableResource
- ModelResource
- Orange::BlogResource
- Defined in:
- lib/orange-more/blog/resources/blog_post_resource.rb
Instance Attribute Summary
Attributes inherited from ModelResource
Instance Method Summary collapse
- #cloud_publish(packet, post) ⇒ Object
- #find_list(packet, mode, id = false) ⇒ Object
-
#onNew(packet, params) ⇒ Object
Creates a new model object and saves it (if a post), then reroutes to the main page.
-
#onSave(packet, m, params = {}) ⇒ Object
Saves updates to an object specified by packet, then reroutes to main.
- #publish(packet, *opts) ⇒ Object
- #stack_init ⇒ Object
Methods inherited from ModelResource
#afterDelete, #afterNew, #afterSave, #beforeDelete, #beforeNew, #beforeSave, #create, #delete, #do_list_view, #do_view, #edit, #find_one, #index, #list, #new, new, #onDelete, #save, #show, #table_row, use, #view, #view_opts
Methods inherited from RoutableResource
Methods inherited from Resource
#afterLoad, call_me, #do_view, #find_extras, #init, #initialize, #options, #orange, #orange_name, #routable, #set_orange, set_orange, #view, #view_opts
Methods included from ClassInheritableAttributes
#cattr_accessor, #cattr_reader, #cattr_writer, eval_in_accessor_module, fetch_value, store_value
Constructor Details
This class inherits a constructor from Orange::Resource
Instance Method Details
#cloud_publish(packet, post) ⇒ Object
21 22 23 |
# File 'lib/orange-more/blog/resources/blog_post_resource.rb', line 21 def cloud_publish(packet, post) orange[:cloud].microblog(packet, "New post on our blog: #{post.title} - http://#{packet['site'].url}#{orange[:blog].blog_url_for(packet)}/#{post.published_at.year}/#{post.published_at.month}/#{post.slug}") if post.published && !post.published_at.blank? end |
#find_list(packet, mode, id = false) ⇒ Object
47 48 49 50 |
# File 'lib/orange-more/blog/resources/blog_post_resource.rb', line 47 def find_list(packet, mode, id =false) blog = orange[:blog].blog_for_site(packet) blog ? blog.posts.all(:order => [:updated_at.desc]) : [] end |
#onNew(packet, params) ⇒ Object
Creates a new model object and saves it (if a post), then reroutes to the main page
27 28 29 30 31 32 33 34 |
# File 'lib/orange-more/blog/resources/blog_post_resource.rb', line 27 def onNew(packet, params) params[:published] = false unless params.has_key?(:published) || params.has_key?("published") params[:author] = packet['user', false] ? packet['user'].name : "Author" unless params.has_key?(:author) || params.has_key?("author") blog = orange[:blog].blog_for_site(packet) post = blog.posts.new(params) post end |
#onSave(packet, m, params = {}) ⇒ Object
Saves updates to an object specified by packet, then reroutes to main
38 39 40 41 42 43 44 45 |
# File 'lib/orange-more/blog/resources/blog_post_resource.rb', line 38 def onSave(packet, m, params = {}) m.update(params) m.blog = orange[:blog].blog_for_site(packet) unless m.blog #ensure blog exists m.save cloud_publish(packet, m) m end |
#publish(packet, *opts) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/orange-more/blog/resources/blog_post_resource.rb', line 10 def publish(packet, *opts) if packet.request.post? m = model_class.get(packet['route.resource_id']) if m m.publish! cloud_publish(packet, m) end end packet.reroute(@my_orange_name, :orange) end |
#stack_init ⇒ Object
5 6 7 |
# File 'lib/orange-more/blog/resources/blog_post_resource.rb', line 5 def stack_init orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Blog') end |