orange 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -128,6 +128,8 @@ module Orange
128
128
  # Returns the content ready to be used by Rack (wrapped in an array)
129
129
  # @return [Array] array of strings to be rendered
130
130
  def content
131
+ # Stringify content if it isn't a string for some weird reason.
132
+ packet[:content] = packet[:content].to_s unless packet[:content].is_a? String
131
133
  return [packet[:content]] if packet[:content]
132
134
  return ['']
133
135
  end
@@ -172,6 +172,7 @@ module Orange
172
172
  end
173
173
  end
174
174
  packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
175
+ m || false
175
176
  end
176
177
 
177
178
  def beforeSave(packet, obj, opts = {})
@@ -24,14 +24,21 @@ class OrangeBlogPost < Orange::Carton
24
24
  self.attribute_set('slug', t.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "_"))
25
25
  end
26
26
 
27
+ def published=(val)
28
+ if val == '1' || val === true
29
+ self.publish
30
+ else
31
+ self.attribute_set('published', false)
32
+ end
33
+ end
34
+
27
35
  def publish
28
- self.published_at = Time.now
29
- self.published = true
36
+ self.published_at = Time.now if self.published_at.blank?
37
+ self.attribute_set('published', true)
30
38
  end
31
39
 
32
40
  def publish!
33
- self.published_at = Time.now
34
- self.published = true
41
+ self.publish
35
42
  self.save
36
43
  end
37
44
 
@@ -11,22 +11,26 @@ module Orange
11
11
  if packet.request.post?
12
12
  m = model_class.get(packet['route.resource_id'])
13
13
  if m
14
- # orange[:cloud, true].microblog(packet, "I just posted a test blog post.")
15
14
  m.publish!
15
+ cloud_publish(packet, m)
16
16
  end
17
17
  end
18
18
  packet.reroute(@my_orange_name, :orange)
19
19
  end
20
20
 
21
+ def cloud_publish(packet, post)
22
+ 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?
23
+ end
24
+
21
25
  # Creates a new model object and saves it (if a post), then reroutes to the main page
22
26
  # @param [Orange::Packet] packet the packet being routed
23
27
  def onNew(packet, params)
24
- params[:published] = false
25
- params[:author] = packet['user', false] ? packet['user'].name : "Author"
28
+ params[:published] = false unless params.has_key?(:published) || params.has_key?("published")
29
+ params[:author] = packet['user', false] ? packet['user'].name : "Author" unless params.has_key?(:author) || params.has_key?("author")
26
30
 
27
31
  blog = orange[:blog].blog_for_site(packet)
28
- blog.posts.new(params)
29
- blog
32
+ post = blog.posts.new(params)
33
+ post
30
34
  end
31
35
 
32
36
  # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
@@ -34,7 +38,10 @@ module Orange
34
38
  def onSave(packet, m, params = {})
35
39
  m.update(params)
36
40
  m.blog = orange[:blog].blog_for_site(packet) unless m.blog #ensure blog exists
41
+
37
42
  m.save
43
+ cloud_publish(packet, m)
44
+ m
38
45
  end
39
46
 
40
47
  def find_list(packet, mode, id =false)
@@ -29,7 +29,7 @@ module Orange
29
29
  opts.merge!( :blog_url => blog_url_for(packet))
30
30
  parts = resource_path.split('/')
31
31
  if parts.size == 2
32
- post = blog.posts.all(:id => parts[1].to_i)
32
+ post = blog.posts.first(:id => parts[1].to_i)
33
33
  elsif parts.size == 4
34
34
  post = blog.posts.year_and_month(parts[1].to_i, parts[2].to_i).slug(parts[3])
35
35
  end
@@ -3,4 +3,4 @@
3
3
  .blog_post
4
4
  %h2
5
5
  %span #{post.created_at.strftime("%B %d, %Y")}
6
- %a{:href => "#{blog_url}/#{post.created_at.year}/#{post.created_at.month}/#{post.slug}"}= post.title
6
+ %a{:href => "#{blog_url}/#{post.published_at.year}/#{post.published_at.month}/#{post.slug}"}= post.title
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 5
9
- version: 0.3.5
8
+ - 6
9
+ version: 0.3.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Haslem
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-01 00:00:00 -04:00
17
+ date: 2010-06-02 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency