blog_logic 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -29,4 +29,5 @@ group :test do
29
29
  gem 'mocha'
30
30
  gem 'rcov'
31
31
  gem 'rspec-rails'
32
+ gem 'yard'
32
33
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -11,8 +11,8 @@ class Admin::PostsController < ApplicationController
11
11
  :state => 'Status',
12
12
  :updated_at => 'Last Modified'
13
13
  }
14
- params[:by] ||= 'slug'
15
- params[:dir] ||= 'asc'
14
+ params[:by] ||= 'publication_date'
15
+ params[:dir] ||= 'desc'
16
16
  @posts = @blog.posts.sort_by{ |p| p[params[:by]] || p[params[:by]].to_s }
17
17
  @posts.reverse! if params[:dir] == 'desc'
18
18
  end
data/app/models/blog.rb CHANGED
@@ -24,6 +24,8 @@ class Blog
24
24
  validates_uniqueness_of :slug
25
25
 
26
26
  # Instance methods ===============================================================================
27
+
28
+ # Migrates this blog's embedded posts to referenced ones.
27
29
  def copy_posts
28
30
  self.posts.each do |post|
29
31
  p = Post2.create :slug => post.slug, :content => post.content, :tags => post.tags, :author => post.author, :published_at => post.published_at, :state => post.state, :publication_date => post.publication_date, :summary => post.summary
@@ -60,6 +62,9 @@ class Blog
60
62
  "/#{self.slug}"
61
63
  end
62
64
 
65
+ # Returns this blog's posts keyed by publication date.
66
+ #
67
+ # @return [Hash] this blog's posts keyed by publication date
63
68
  def posts_by_month
64
69
  dates = {}
65
70
  self.posts.published.each do |p|
@@ -72,6 +77,10 @@ class Blog
72
77
  dates
73
78
  end
74
79
 
80
+ # Returns published posts matching the specified keyword.
81
+ #
82
+ # @param [String] the keyword to search for
83
+ # @return [Array] matching published posts
75
84
  def search(keyword)
76
85
  self.posts.published.where :content => /#{keyword}/i
77
86
  end
@@ -17,41 +17,74 @@ class BlogCategory
17
17
  validates_uniqueness_of :name
18
18
 
19
19
  # Class methods: Overrides =======================================================================
20
+
21
+ # Overrides children to sort by name.
22
+ #
23
+ # @return [Array] this blog category's children sorted by name
20
24
  def self.children
21
25
  super.asc :name
22
26
  end
23
27
 
28
+ # Overrides roots to sort by name.
29
+ #
30
+ # @return [Array] this blog category's roots sorted by name
24
31
  def self.roots
25
32
  super.asc :name
26
33
  end
27
34
 
28
35
  # Class methods ==================================================================================
36
+
37
+ # Returns the blog categories matching the specified name.
38
+ #
39
+ # @param [String] the name to search for
40
+ # @return [Array] the matching blog categories
29
41
  def self.by_name value
30
42
  self.find :first, :conditions => {:name => value}
31
43
  end
32
44
 
45
+ # Returns the blog categories matching the specified slug.
46
+ #
47
+ # @param [String] the slug to search for
48
+ # @return [Array] the matching blog categories
33
49
  def self.by_slug value
34
50
  self.find :first, :conditions => {:slug => /^#{value}$/i}
35
51
  end
36
52
 
53
+ # Returns the root blog categories that have posts.
54
+ #
55
+ # @return [Array] blog categories with posts
37
56
  def self.roots_with_posts
38
57
  self.roots.asc(:name).select{ |c| c.has_posts? }
39
58
  end
40
59
 
41
60
  # Instance methods: Overrides ====================================================================
61
+
62
+ # Returns child blog categories that have posts.
63
+ #
64
+ # @return [Array] child blog categories with posts
42
65
  def children_with_posts
43
66
  self.children.asc(:name).select{ |c| c.has_posts? }
44
67
  end
45
68
 
69
+ # Override the parent-ID setter to accept nil as a string.
70
+ #
71
+ # @param [String] parent ID
46
72
  def parent_id= value
47
73
  self[:parent_id] = value == 'nil' ? nil : value
48
74
  end
49
75
 
50
76
  # Instance methods ===============================================================================
77
+
78
+ # Returns true if this blog category has any posts.
79
+ #
80
+ # @return [Boolean] true if any posts exist
51
81
  def has_posts?
52
82
  ! self.all_posts.blank?
53
83
  end
54
84
 
85
+ # Sets the specified category as this blog category's parent.
86
+ #
87
+ # @param [String] the parent category's name
55
88
  def parent_category=(name)
56
89
  unless name.blank?
57
90
  self.parent = BlogCategory.find_or_create_by :name => name
@@ -59,18 +92,28 @@ class BlogCategory
59
92
  end
60
93
  end
61
94
 
95
+ # Returns all posts belonging to this blog category and its children.
96
+ #
97
+ # @return [Array] all posts for this blog category
62
98
  def all_posts
63
99
  (self.posts + self.children.map{ |c| c.posts }).uniq.flatten
64
100
  end
65
101
 
102
+ # Returns the path for this blog category.
103
+ #
104
+ # @return [String] this blog category's path
66
105
  def path
67
106
  "#{Blog.first.path}/topics/#{self.slug}"
68
107
  end
69
108
 
109
+ # Returns true if this blog category has a parent.
110
+ #
111
+ # @return [Boolean] true if subcategory
70
112
  def subcategory?
71
113
  ! self.root?
72
114
  end
73
115
 
116
+ # @deprecated Please use {#path} instead
74
117
  def url
75
118
  warn "[DEPRECATION] `url` is deprecated. Please use `path` instead."
76
119
  self.path
@@ -78,12 +121,14 @@ class BlogCategory
78
121
 
79
122
  private
80
123
 
81
- # Returns an array of this category's and its ancestors' names.
124
+ # Returns an array of names for this blog category and those of its ancestors.
125
+ #
126
+ # @return [Array] this blog category's name and those of its ancestors
82
127
  def ancestors_and_self_names
83
128
  self.ancestors_and_self.map{ |l| l.name }
84
129
  end
85
130
 
86
- # Returns the permalink for this locale.
131
+ # Sets this blog category's slug, based on its name and those of its ancestors.
87
132
  def set_slug
88
133
  self.slug = (ancestors_and_self_names * '/').to_url.gsub('-slash-', '/')
89
134
  end
data/app/models/post.rb CHANGED
@@ -4,7 +4,6 @@ class Post
4
4
  include Mongoid::Timestamps
5
5
  include Tanker
6
6
 
7
- # Constants ======================================================================================
8
7
  STATES = ['draft', 'published']
9
8
 
10
9
  # Scopes =========================================================================================
@@ -49,15 +48,25 @@ class Post
49
48
  validates_presence_of :content, :title
50
49
 
51
50
  # Instance methods: Overrides ====================================================================
51
+
52
+ # Returns this post's publication date, defaulting to published-at.
53
+ #
54
+ # @return [DateTime] publication or published-at date
52
55
  def publication_date
53
56
  self[:publication_date] || self.published_at
54
57
  end
55
58
 
56
59
  # Instance methods ===============================================================================
60
+
61
+ # Returns true if this post is an unpublished draft.
62
+ #
63
+ # @return [Boolean] true if draft
57
64
  def draft?
58
65
  self.state == 'draft' || self.state.nil?
59
66
  end
60
67
 
68
+ # Joins this post to its associated blog categories, insuring data integrity at both ends of the
69
+ # join.
61
70
  def fix_blog_category_join
62
71
  self.blog_categories.each do |cat|
63
72
  cat.post_ids << self.id
@@ -77,10 +86,16 @@ class Post
77
86
  self.path
78
87
  end
79
88
 
89
+ # Returns the index of this post in the blog's collection of posts.
90
+ #
91
+ # @return [Fixnum] the path for this post
80
92
  def my_index
81
93
  self.blog.posts.index(self)
82
94
  end
83
95
 
96
+ # Returns the next post in the blog.
97
+ #
98
+ # @return [Post] the next post
84
99
  def next_post
85
100
  i = self.my_index + 1
86
101
  i = 0 if i > (self.blog.posts.size - 1)
@@ -94,36 +109,56 @@ class Post
94
109
  "#{self.blog.path}/#{self.slug}".gsub('//', '/')
95
110
  end
96
111
 
112
+ # Returns the previous post in the blog.
113
+ #
114
+ # @return [Post] the previous post
97
115
  def previous_post
98
116
  i = self.my_index - 1
99
117
  i = self.blog.posts.size - 1 if i < 0
100
118
  self.blog.posts[i]
101
119
  end
102
120
 
121
+ # Publishes this post so it's publically available.
103
122
  def publish!
104
123
  self.update_attributes :state => 'published', :published_at => Time.zone.now
105
124
  end
106
125
 
126
+ # Returns whether this post is publically available.
127
+ #
128
+ # @return [Boolean] true if published
107
129
  def published?
108
130
  self.state == 'published'
109
131
  end
110
132
 
133
+ # Returns the first 200 characters of this post's summary, suitable for use as a meta description.
134
+ #
135
+ # @return [String] search description
111
136
  def search_description
112
137
  self.summary.gsub(/<\/?[^>]*>/, '')[0..199].html_safe
113
138
  end
114
139
 
140
+ # Returns this post's title.
141
+ #
142
+ # @return [String] title
115
143
  def search_title
116
144
  self.title
117
145
  end
118
146
 
147
+ # Reverts this post's status to draft so it is no longer publically available.
119
148
  def unpublish!
120
149
  self.update_attributes :state => 'draft'
121
150
  end
122
151
 
152
+ # Sets the specified state for this post, forcing lowercase.
153
+ #
154
+ # @param [String] state
123
155
  def state=(arg)
124
156
  self[:state] = arg.downcase
125
157
  end
126
158
 
159
+ # Returns this post's status.
160
+ #
161
+ # @return [String] status
127
162
  def status
128
163
  self.state ? self.state.capitalize : 'Draft'
129
164
  end
data/blog_logic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "blog_logic"
8
- s.version = "1.4.0"
8
+ s.version = "1.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bantik"]
12
- s.date = "2011-10-04"
12
+ s.date = "2011-11-01"
13
13
  s.description = "An engine for search-engine-optimized blog management."
14
14
  s.email = "corey@seologic.com"
15
15
  s.extra_rdoc_files = [
@@ -69,7 +69,6 @@ Gem::Specification.new do |s|
69
69
  "config/application.rb",
70
70
  "config/boot.rb",
71
71
  "config/cucumber.yml",
72
- "config/deploy.rb",
73
72
  "config/environment.rb",
74
73
  "config/environments/development.rb",
75
74
  "config/environments/production.rb",
data/config.ru CHANGED
@@ -1,4 +1,2 @@
1
- # This file is used by Rack-based servers to start the application.
2
-
3
1
  require ::File.expand_path('../config/environment', __FILE__)
4
- run BlogLogic::Application
2
+ run BlogLogic::Application
@@ -10,35 +10,7 @@ Bundler.require(:default, Rails.env) if defined?(Bundler)
10
10
 
11
11
  module BlogLogic
12
12
  class Application < Rails::Application
13
- # Settings in config/environments/* take precedence over those specified here.
14
- # Application configuration should go into files in config/initializers
15
- # -- all .rb files in that directory are automatically loaded.
16
-
17
- # Custom directories with classes and modules you want to be autoloadable.
18
- # config.autoload_paths += %W(#{config.root}/extras)
19
-
20
- # Only load the plugins named here, in the order given (default is alphabetical).
21
- # :all can be used as a placeholder for all plugins not explicitly named.
22
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
23
-
24
- # Activate observers that should always be running.
25
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
26
-
27
- # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
28
- # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
29
- # config.time_zone = 'Central Time (US & Canada)'
30
-
31
- # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
32
- # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
33
- # config.i18n.default_locale = :de
34
-
35
- # JavaScript files you want as :defaults (application.js is always included).
36
- # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
37
-
38
- # Configure the default encoding used in templates for Ruby 1.9.
39
13
  config.encoding = "utf-8"
40
-
41
- # Configure sensitive parameters which will be filtered from the log file.
42
14
  config.filter_parameters += [:password]
43
15
  end
44
- end
16
+ end
data/config/boot.rb CHANGED
@@ -1,6 +1,3 @@
1
1
  require 'rubygems'
2
-
3
- # Set up gems listed in the Gemfile.
4
2
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
-
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
3
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
data/config/cucumber.yml CHANGED
@@ -7,4 +7,4 @@ int_opts = "#{std_opts} -o tmp/feature_results.txt"
7
7
  default: <%= std_opts %> features
8
8
  wip: --tags @wip:3 --wip features
9
9
  rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
10
- integration: <%= int_opts %> features
10
+ integration: <%= int_opts %> features
@@ -1,6 +1,3 @@
1
- # Load the rails application
2
1
  require File.expand_path('../application', __FILE__)
3
2
  require File.expand_path('../../lib/blog_logic', __FILE__)
4
-
5
- # Initialize the rails application
6
- BlogLogic::Application.initialize!
3
+ BlogLogic::Application.initialize!
@@ -1,27 +1,11 @@
1
1
  BlogLogic::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
2
  config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
3
  config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
4
  config.consider_all_requests_local = true
14
5
  config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send
17
6
  config.action_mailer.raise_delivery_errors = false
18
-
19
- # Print deprecation notices to the Rails logger
20
7
  config.active_support.deprecation = :log
21
-
22
- # Only use best-standards-support built into browsers
23
8
  config.action_dispatch.best_standards_support = :builtin
24
-
25
9
  # Custom settings
26
10
  config.feature_results_path = "#{Rails.root}/tmp/feature_results.txt"
27
- end
11
+ end
@@ -1,49 +1,9 @@
1
1
  BlogLogic::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The production environment is meant for finished, "live" apps.
5
- # Code is not reloaded between requests
6
2
  config.cache_classes = true
7
-
8
- # Full error reports are disabled and caching is turned on
9
3
  config.consider_all_requests_local = false
10
4
  config.action_controller.perform_caching = true
11
-
12
- # Specifies the header that your server uses for sending files
13
5
  config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
-
15
- # For nginx:
16
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
-
18
- # If you have no front-end server that supports something like X-Sendfile,
19
- # just comment this out and Rails will serve the files
20
-
21
- # See everything in the log (default is :info)
22
- # config.log_level = :debug
23
-
24
- # Use a different logger for distributed setups
25
- # config.logger = SyslogLogger.new
26
-
27
- # Use a different cache store in production
28
- # config.cache_store = :mem_cache_store
29
-
30
- # Disable Rails's static asset server
31
- # In production, Apache or nginx will already do this
32
6
  config.serve_static_assets = false
33
-
34
- # Enable serving of images, stylesheets, and javascripts from an asset server
35
- # config.action_controller.asset_host = "http://assets.example.com"
36
-
37
- # Disable delivery errors, bad email addresses will be ignored
38
- # config.action_mailer.raise_delivery_errors = false
39
-
40
- # Enable threaded mode
41
- # config.threadsafe!
42
-
43
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
- # the I18n.default_locale when a translation can not be found)
45
7
  config.i18n.fallbacks = true
46
-
47
- # Send deprecation notices to registered listeners
48
8
  config.active_support.deprecation = :notify
49
- end
9
+ end
@@ -1,38 +1,12 @@
1
1
  BlogLogic::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
3
-
4
- # The test environment is used exclusively to run your application's
5
- # test suite. You never need to work with it otherwise. Remember that
6
- # your test database is "scratch space" for the test suite and is wiped
7
- # and recreated between test runs. Don't rely on the data there!
8
2
  config.cache_classes = true
9
-
10
- # Log error messages when you accidentally call methods on nil.
11
3
  config.whiny_nils = true
12
-
13
- # Show full error reports and disable caching
14
4
  config.consider_all_requests_local = true
15
5
  config.action_controller.perform_caching = false
16
-
17
- # Raise exceptions instead of rendering exception templates
18
6
  config.action_dispatch.show_exceptions = false
19
-
20
- # Disable request forgery protection in test environment
21
7
  config.action_controller.allow_forgery_protection = false
22
-
23
- # Tell Action Mailer not to deliver emails to the real world.
24
- # The :test delivery method accumulates sent emails in the
25
- # ActionMailer::Base.deliveries array.
26
8
  config.action_mailer.delivery_method = :test
27
-
28
- # Use SQL instead of Active Record's schema dumper when creating the test database.
29
- # This is necessary if your schema can't be completely dumped by the schema dumper,
30
- # like if you have constraints or database-specific column types
31
- # config.active_record.schema_format = :sql
32
-
33
- # Print deprecation notices to the stderr
34
9
  config.active_support.deprecation = :stderr
35
-
36
10
  # Custom settings
37
11
  config.admin_host = 'admin.bloglogic.com'
38
12
  # tanker gem
data/config/mongoid.yml CHANGED
@@ -15,5 +15,4 @@ development:
15
15
 
16
16
  test:
17
17
  <<: *defaults
18
- database: blog_logic_test
19
-
18
+ database: blog_logic_test
data/config/routes.rb CHANGED
@@ -19,4 +19,4 @@ Rails.application.routes.draw do
19
19
  end
20
20
  resources :blog_categories
21
21
  end
22
- end
22
+ end
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'blog_logic'
1
+ require 'blog_logic'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Admin::BlogsController do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Admin::PostsController do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe BlogsController do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe PostsController do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Blog do
4
4
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Post do
4
4
  before :all do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blog_logic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 0
10
- version: 1.4.0
9
+ - 1
10
+ version: 1.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bantik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-04 00:00:00 Z
18
+ date: 2011-11-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: bson_ext
@@ -267,7 +267,6 @@ files:
267
267
  - config/application.rb
268
268
  - config/boot.rb
269
269
  - config/cucumber.yml
270
- - config/deploy.rb
271
270
  - config/environment.rb
272
271
  - config/environments/development.rb
273
272
  - config/environments/production.rb
@@ -1046,3 +1045,4 @@ specification_version: 3
1046
1045
  summary: An engine for search-engine-optimized blog management.
1047
1046
  test_files: []
1048
1047
 
1048
+ has_rdoc:
data/config/deploy.rb DELETED
@@ -1,40 +0,0 @@
1
- # Deploy this gem to the gem server.
2
- #
3
- # Usage for a gem already on the gem server:
4
- #
5
- # cap deploy
6
- #
7
- # For a new gem:
8
- #
9
- # cap deploy:new
10
-
11
- # Global Variables =================================================================================
12
- default_run_options[:pty] = true
13
- role :app, 'jose.seologic.com'
14
- set :deploy_to, '/home/containers/rails/system/blog_logic'
15
- set :repository, 'git@github.com:ivanoblomov/blog_logic.git'
16
- set :scm, :git
17
- set :use_sudo, false
18
- set :user, 'cnewton'
19
-
20
- namespace :deploy do
21
- desc "Clone a new gem's repository on the gem server."
22
- task :new do
23
- run "git clone -q #{repository} #{deploy_to}"
24
- end
25
-
26
- task :install do
27
- run "cd #{deploy_to}; rm -f Gemfile.lock; sudo bundle; sudo rake install"
28
- end
29
-
30
- # disable default behavior
31
- task :restart do
32
- end
33
-
34
- task :update do
35
- run "cd #{deploy_to}; git pull"
36
- end
37
- end
38
-
39
- after 'deploy', 'deploy:install'
40
- after 'deploy:new', 'deploy:install'