spud_blog 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -26,7 +26,8 @@ class BlogController < ApplicationController
26
26
  if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
27
27
  @posts = @post_category.posts_with_children.public_blog_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
28
28
  else
29
- @posts = []
29
+ redirect_to blog_path
30
+ return
30
31
  end
31
32
  respond_with @posts do |format|
32
33
  format.html { render 'index' }
@@ -25,7 +25,8 @@ class NewsController < ApplicationController
25
25
  if @post_category = SpudPostCategory.find_by_url_name(params[:category_url_name])
26
26
  @posts = @post_category.posts_with_children.public_news_posts(params[:page], Spud::Blog.config.posts_per_page).from_archive(params[:archive_date])
27
27
  else
28
- @posts = []
28
+ redirect_to news_path
29
+ return
29
30
  end
30
31
  respond_with @posts do |format|
31
32
  format.html { render 'index' }
@@ -12,9 +12,7 @@ class SpudPost < ActiveRecord::Base
12
12
  before_validation :set_url_name
13
13
 
14
14
  def self.public_posts(page, per_page)
15
-
16
15
  return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').includes(:comments, :categories).paginate(:page => page, :per_page => per_page)
17
-
18
16
  end
19
17
 
20
18
  def self.public_blog_posts(page, per_page)
@@ -10,7 +10,7 @@ xml.urlset :xmlns => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
10
10
  else
11
11
  xml.loc blog_post_url(post.url_name)
12
12
  end
13
- xml.lastmod post.published_at.strftime('%Y-%m-%d')
13
+ xml.lastmod post.published_at.xmlschema
14
14
  end
15
15
  end
16
16
  end
data/config/routes.rb CHANGED
@@ -10,7 +10,7 @@ Rails.application.routes.draw do
10
10
  resources :post_categories
11
11
  end
12
12
  namespace :blog do
13
- resource :sitemap,:only => "show"
13
+ resource :sitemap,:only => "show"
14
14
  end
15
15
  end
16
16
 
@@ -0,0 +1,60 @@
1
+ require 'rails/generators/migration'
2
+
3
+ class Spud::Blog::RandomPostsGenerator < ::Rails::Generators::Base
4
+
5
+ def generate
6
+ if Spud::Blog.config.blog_enabled
7
+ puts 'Generating random blog posts...'
8
+ random_posts(false)
9
+ end
10
+ if Spud::Blog.config.news_enabled
11
+ puts 'Generating random news posts...'
12
+ random_posts(true)
13
+ end
14
+ puts 'Assigning categories...'
15
+ category_ids = SpudPostCategory.all.collect{ |c| c.id }
16
+ SpudPost.all.each do |p|
17
+ p.category_ids = [category_ids[rand(category_ids.length)]]
18
+ p.save
19
+ end
20
+ puts 'Done!'
21
+ end
22
+
23
+ private
24
+
25
+ def random_posts(is_news)
26
+ 100.times do
27
+ post = SpudPost.create({
28
+ :title => random_title,
29
+ :content => random_content,
30
+ :published_at => random_time,
31
+ :visible => 1,
32
+ :spud_user_id => 1,
33
+ :is_news => is_news
34
+ })
35
+ end
36
+ end
37
+
38
+ def random_word
39
+ chars = 'abcdefghjkmnpqrstuvwxyz'
40
+ length = rand(8) + 1
41
+ return (1..length).collect{ chars[rand(chars.length)] }.join('')
42
+ end
43
+
44
+ def random_title
45
+ return (1..4).collect{ random_word.capitalize }.join(' ')
46
+ end
47
+
48
+ def random_content
49
+ content = ''
50
+ 3.times do |i|
51
+ content += '<p>' + (1..30).collect{ random_word }.join(' ').capitalize + '.</p>'
52
+ end
53
+ return content
54
+ end
55
+
56
+ def random_time
57
+ return Time.at(1.year.ago + rand * (Time.now.to_f - 1.year.ago.to_f))
58
+ end
59
+
60
+ end
@@ -11,7 +11,7 @@ module Spud
11
11
  :order => 3
12
12
  }]
13
13
  if Spud::Blog.enable_sitemap == true
14
- Spud::Core.config.sitemap_urls += [:spud_blog_sitemap_url]
14
+ Spud::Core.config.sitemap_urls += [:spud_blog_sitemap_url]
15
15
  end
16
16
  if Spud::Blog.config.blog_enabled
17
17
  Spud::Core.config.admin_applications += [{
@@ -29,7 +29,6 @@ module Spud
29
29
  :order => 2
30
30
  }]
31
31
  end
32
-
33
32
  end
34
33
  initializer :assets do
35
34
  Rails.application.config.assets.precompile += ['spud/admin/posts.css']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spud_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-22 00:00:00.000000000 Z
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spud_core
16
- requirement: &70247516879720 !ruby/object:Gem::Requirement
16
+ requirement: &70274549294540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.5.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70247516879720
24
+ version_requirements: *70274549294540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: will_paginate
27
- requirement: &70247516879240 !ruby/object:Gem::Requirement
27
+ requirement: &70274549294060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70247516879240
35
+ version_requirements: *70274549294060
36
36
  description:
37
37
  email: greg@westlakedesign.com
38
38
  executables: []
@@ -92,8 +92,8 @@ files:
92
92
  - config/application.rb
93
93
  - config/boot.rb
94
94
  - config/routes.rb
95
+ - lib/generators/spud/blog/random_posts_generator.rb
95
96
  - lib/generators/spud/blog/views_generator.rb
96
- - lib/scripts/random_data.rb
97
97
  - lib/spud_blog.rb
98
98
  - lib/spud_blog/configuration.rb
99
99
  - lib/spud_blog/engine.rb
@@ -1,31 +0,0 @@
1
- # Quick script for faking up some data
2
-
3
- def random_word
4
- chars = 'abcdefghjkmnpqrstuvwxyz'
5
- return (1..6).collect{ chars[rand(chars.length)] }.join('').capitalize
6
- end
7
-
8
- def random_title
9
- return (1..4).collect{ random_word }.join(' ')
10
- end
11
-
12
- def random_time
13
- return Time.at(1.year.ago + rand * (Time.now.to_f - 1.year.ago.to_f))
14
- end
15
-
16
- 100.times do
17
- post = SpudPost.create({
18
- :title => random_title,
19
- :content => 'Hello, World!',
20
- :published_at => random_time,
21
- :visible => 1,
22
- :spud_user_id => 1
23
- })
24
- end
25
-
26
- category_ids = SpudPostCategory.all.collect{ |c| c.id }
27
-
28
- SpudPost.all.each do |p|
29
- p.category_ids = [category_ids[rand(category_ids.length)]]
30
- p.save
31
- end