wheelhouse-blog 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ Blog Plugin for Wheelhouse CMS
2
+ ==============================
3
+
4
+ This gem makes it easy to integrate a blog or news feed into your Wheelhouse CMS site.
5
+
6
+ It currently supports:
7
+
8
+ - RSS feed
9
+ - tags
10
+ - categories
11
+ - archives
12
+ - multiple blogs
13
+
14
+ It does not yet support commenting but this will be implemented in the near future. In the meanwhile, it is fairly easy to integrate comments using a third-party JavaScript library such as [Disqus](http://disqus.com/) or [Facebook Comments](https://developers.facebook.com/docs/reference/plugins/comments/).
15
+
16
+
17
+ Installation & Usage
18
+ --------------------
19
+
20
+ **1. Add `wheelhouse-blog` to your Gemfile:**
21
+
22
+ gem "wheelhouse-blog"
23
+
24
+ Then run `bundle install`.
25
+
26
+ **2. Create a new blog from the New Page dropdown.**
27
+
28
+ **3. Copy the templates from `app/templates/blog` to your theme templates folder to customize.**
@@ -0,0 +1,15 @@
1
+ @import wheelhouse
2
+
3
+ #blog-posts
4
+ +orange-table
5
+
6
+ #blog-categories
7
+ +clearfix
8
+
9
+ label
10
+ font-weight: normal
11
+ color: lighten(#4e6573, 10%)
12
+
13
+ li
14
+ margin-top: 0
15
+ margin-bottom: 3px
@@ -0,0 +1,8 @@
1
+ class Blog::BlogsController < Wheelhouse::ResourceController
2
+ self.resource_class = Blog::Blog
3
+ manage_site_breadcrumb
4
+
5
+ def section
6
+ Blog::Plugin.config.wheelhouse.blog.sections ? @blog.label : super
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ class Blog::PostsController < Wheelhouse::ResourceController
2
+ belongs_to :blog, :class_name => Blog::Blog
3
+ defaults :resource_class => Blog::Post, :collection_name => :all_posts
4
+
5
+ manage_site_breadcrumb
6
+ breadcrumb { [parent.label, blog_path(parent)] }
7
+
8
+ def section
9
+ Blog::Plugin.config.wheelhouse.blog.sections ? @blog.label : super
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ class Blog::BlogHandler < Wheelhouse::ResourceHandler
2
+ get :cache => true do
3
+ # Nothing extra required
4
+ end
5
+
6
+ get "/feed.xml", :cache => true do
7
+ request.format = :xml
8
+ render :template => "feed.xml", :layout => false
9
+ end
10
+
11
+ get '/tag/:tag', :cache => true do
12
+ @posts = @blog.posts.tagged_with(params[:tag])
13
+ render :template => "tag.html"
14
+ end
15
+
16
+ get '/category/:category', :cache => true do
17
+ @posts = @blog.posts.in_category(params[:category])
18
+ render :template => "category.html"
19
+ end
20
+
21
+ get "/:year/:month/:permalink", :cache => true do
22
+ @post = @blog.find_post(params[:year], params[:month], params[:permalink])
23
+ render @post
24
+ end
25
+
26
+ get "/:year/:month", :cache => true do
27
+ @year = params[:year].to_i
28
+ @month = params[:month].to_i
29
+ raise ActionController::RoutingError, "No route matches #{request.path.inspect}" if @year.zero? || @month.zero?
30
+
31
+ @posts = @blog.posts.in_year_and_month(@year, @month)
32
+ render :template => "archive.html"
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ # This handler is only used for post previewing
2
+ class Blog::PostHandler < Wheelhouse::ResourceHandler
3
+ get do
4
+ self.node = @post.blog
5
+ render @post
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Blog::BlogHelper
2
+ def blog_post_tag_links(post)
3
+ post.tags.map { |tag| link_to(tag, post.blog.tag_path(tag), :title => "View all posts tagged #{tag}") }.join(', ').html_safe
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ class Blog::Blog < Wheelhouse::Resource
2
+ include Wheelhouse::Resource::Addressable
3
+ include Wheelhouse::Resource::Content
4
+
5
+ property :title, String, :translate => true, :required => true
6
+
7
+ has_many :posts, :class => "Blog::Post", :conditions => { :state => 'Published' }, :order => :published_at.desc
8
+ has_many :all_posts, :class => "Blog::Post", :order => :created_at.desc
9
+
10
+ activities :all
11
+
12
+ icon "wheelhouse-blog/blog.png"
13
+
14
+ self.default_template = "blog/index"
15
+
16
+ def handler
17
+ Blog::BlogHandler
18
+ end
19
+
20
+ def find_post(year, month, permalink)
21
+ posts.find_by_year_and_month_and_permalink!(year.to_i, month.to_i, permalink)
22
+ end
23
+
24
+ def tag_path(tag)
25
+ path('tag', tag.parameterize)
26
+ end
27
+
28
+ def category_path(category)
29
+ path('category', category.parameterize)
30
+ end
31
+
32
+ def archive_path(year, month)
33
+ path(year.to_i, month.to_i)
34
+ end
35
+
36
+ def archives
37
+ selector = MongoModel::MongoOptions.new(posts.klass, posts.finder_options).to_a.first
38
+ posts.collection.group(:key => [:year, :month], :cond => selector, :initial => { :count => 0 }, :reduce => "function(doc, out) { out.count++ }").map { |hash|
39
+ year, month, count = hash["year"], hash["month"], hash["count"]
40
+
41
+ [Date.civil(year, month, 1), archive_path(year, month), count.to_i]
42
+ }.sort { |a, b| b.first <=> a.first }
43
+ end
44
+
45
+ def tags
46
+ selector = MongoModel::MongoOptions.new(posts.klass, posts.finder_options).to_a.first
47
+ posts.collection.distinct(:tags, selector)
48
+ end
49
+
50
+ def categories
51
+ selector = MongoModel::MongoOptions.new(posts.klass, posts.finder_options).to_a.first
52
+ posts.collection.distinct(:categories, selector)
53
+ end
54
+
55
+ def additional_children
56
+ posts
57
+ end
58
+ end
@@ -0,0 +1,84 @@
1
+ class Blog::Post < Wheelhouse::Resource
2
+ include Wheelhouse::Resource::Renderable
3
+ include Wheelhouse::Resource::Versioned
4
+ include Wheelhouse::Resource::Content
5
+
6
+ belongs_to :blog, :class => "Blog::Blog"
7
+
8
+ property :title, String, :translate => true, :required => true
9
+ property :permalink, String, :required => true
10
+ property :state, String, :default => 'Published'
11
+ property :published_at, Time
12
+ property :year, Integer
13
+ property :month, Integer
14
+
15
+ property :tags, Wheelhouse::Tags
16
+ property :categories, Wheelhouse::Tags
17
+
18
+ index :_tags
19
+ before_save { attributes[:_tags] = tags.map(&:parameterize) }
20
+
21
+ index :_categories
22
+ before_save { attributes[:_categories] = categories.map(&:parameterize) }
23
+
24
+ activities :all, :resource_name => :title
25
+
26
+ icon "wheelhouse-blog/post.png"
27
+
28
+ validates_uniqueness_of :permalink, :scope => :blog_id
29
+
30
+ scope :tagged_with, lambda { |tag| where(:_tags => tag.parameterize) }
31
+ scope :in_category, lambda { |category| where(:_categories => category.parameterize) }
32
+ scope :in_year_and_month, lambda { |year, month| where(:year => year, :month => month) }
33
+
34
+ scope :properties_for_admin, select(:id, :type, :title, :state, :published_at, :created_by_id, :author_name, :blog_id)
35
+
36
+ before_save :set_published_timestamp, :if => :published?
37
+ before_save :cache_author_name
38
+
39
+ delegate :site, :to => :blog
40
+ after_save :clear_cache!
41
+ after_destroy :clear_cache!
42
+
43
+ self.parent_resource = :blog
44
+ self.default_template = "post"
45
+
46
+ def published?
47
+ state == 'Published'
48
+ end
49
+
50
+ def path
51
+ blog.path(published_at.year, published_at.month, permalink)
52
+ end
53
+
54
+ def author_name
55
+ read_attribute(:author_name) || (author && author.name)
56
+ end
57
+
58
+ def author
59
+ created_by
60
+ end
61
+
62
+ def published_at
63
+ read_attribute(:published_at) || Time.now
64
+ end
65
+
66
+ def admin_path
67
+ persisted? ? blog_post_path(blog_id, self) : blog_posts_path(blog_id)
68
+ end
69
+
70
+ def handler
71
+ Blog::PostHandler
72
+ end
73
+
74
+ private
75
+ def set_published_timestamp
76
+ self.published_at = published_at
77
+ self.year = published_at.year
78
+ self.month = published_at.month
79
+ end
80
+
81
+ def cache_author_name
82
+ write_attribute(:author_name, author.name) if author
83
+ end
84
+ end
@@ -0,0 +1,6 @@
1
+ %h2= @blog.title
2
+
3
+ - if local_assigns[:description]
4
+ %p= description
5
+
6
+ = yield
@@ -0,0 +1,9 @@
1
+ %article.post
2
+ %h3= link_to_unless_current post.title, post
3
+
4
+ %p
5
+ %em
6
+ Posted:
7
+ = post.published_at.to_s(:short)
8
+
9
+ = post.content
@@ -0,0 +1,5 @@
1
+ - title [format_month(@year, @month), @blog.title].join(' - ')
2
+ - breadcrumb format_month(@year, @month)
3
+
4
+ = render :layout => "layout", :locals => { :description => "Posts from: #{format_month(@year, @month)}" } do
5
+ = render :partial => "post", :collection => @posts
@@ -0,0 +1,5 @@
1
+ - title ["Category: #{params[:category].titlecase}", @blog.title].join(' - ')
2
+ - breadcrumb "Category: #{params[:category].titlecase}"
3
+
4
+ = render :layout => "layout", :locals => { :description => "Posts in category: #{params[:category].titlecase}" } do
5
+ = render :partial => "post", :collection => @posts
@@ -0,0 +1,33 @@
1
+ xml.instruct!
2
+
3
+ xml.rss :version => '2.0', 'xmlns:atom' => 'http://www.w3.org/2005/Atom' do
4
+ xml.channel do
5
+ xml.title site.name
6
+ xml.description @blog.title
7
+ xml.link url(@blog)
8
+ xml.tag! 'atom:link', :href => request.url, :rel => 'self', :type => 'application/rss+xml'
9
+
10
+ @blog.posts.each do |post|
11
+ xml.item do
12
+ xml.title post.title
13
+ xml.author "#{post.author.email} (#{post.author.name})"
14
+ xml.pubDate post.published_at.to_s(:rss)
15
+
16
+ xml.description do
17
+ xml.cdata!(post.content.to_s)
18
+ end
19
+
20
+ post.categories.each do |category|
21
+ xml.category do
22
+ xml.cdata!(category)
23
+ end
24
+ end
25
+
26
+ xml.link url(post)
27
+ xml.guid url(post)
28
+
29
+ # xml.comments url(post.comments_path) if blog.comments_enabled?
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ - template.name = "Default Blog"
2
+ - template.resource = Blog::Blog
3
+ - title @blog.title
4
+
5
+ = render :layout => "layout" do
6
+ = render :partial => "post", :collection => @blog.posts
@@ -0,0 +1,6 @@
1
+ - template.name = "Blog Post"
2
+ - template.resource = Blog::Post
3
+ - title [@post.title, @blog.title].join(' - ')
4
+ - breadcrumb @post.title
5
+
6
+ = render :partial => "post", :object => @post, :layout => "layout"
@@ -0,0 +1,5 @@
1
+ - title ["Tag: #{params[:tag]}", @blog.title].join(' - ')
2
+ - breadcrumb "Tag: #{params[:tag]}"
3
+
4
+ = render :layout => "layout", :locals => { :description => "Posts tagged: #{params[:tag]}" } do
5
+ = render :partial => "post", :collection => @posts
@@ -0,0 +1,23 @@
1
+ - content_for(:head) do
2
+ = stylesheet_link_tag "wheelhouse-blog/admin"
3
+
4
+ .buttons
5
+ = link_to "New Post", new_blog_post_path(@blog), :class => 'add'
6
+
7
+ - @posts = @blog.all_posts.properties_for_admin.paginate(:page => params[:p])
8
+
9
+ = table_for Blog::Post, :id => "blog-posts" do |table|
10
+ - table.rows(@posts) do |row, post|
11
+ - row.resource = post
12
+
13
+ = row.column(:title, :link => true)
14
+ = row.column(:author) { post.author_name || 'None' }
15
+ = row.column(:published_at) { post.published? ? post.published_at.to_s(:short) : 'Draft' }
16
+ = row.controls do |c|
17
+ = c.delete
18
+
19
+ - table.empty do
20
+ No blog posts have been created.
21
+ = link_to "Create a new post.", new_blog_post_path(@blog)
22
+
23
+ = will_paginate @posts
@@ -0,0 +1,22 @@
1
+ - tab :posts => 'posts' if @blog.persisted?
2
+
3
+ - tab :blog_settings do
4
+ = field :title do
5
+ = form.text_field :title, :title => true
6
+
7
+ = content
8
+
9
+ - sidebar do
10
+ .buttons
11
+ = button "Save Settings", :icon => :publish, :submit => true, :id => "save-and-publish"
12
+
13
+ %hr
14
+
15
+ %dl
16
+ = navigation_options
17
+ = template_options
18
+
19
+ - if @blog.persisted?
20
+ %hr
21
+ = owner
22
+
@@ -0,0 +1,25 @@
1
+ - content_for(:head) do
2
+ = stylesheet_link_tag "wheelhouse-blog/admin"
3
+
4
+ - form! [@blog, @post], :as => :post, :url => @post.admin_path
5
+
6
+ - tab :post do
7
+ = field :title do
8
+ = form.text_field :title, :title => true
9
+
10
+ = content
11
+
12
+ - sidebar(:options) do
13
+ = sidebar_expander "Publishing Options" do
14
+ = field :published_at do
15
+ = form.datetime :published_at, :value => @post.read_attribute(:published_at) || ""
16
+
17
+ = field :permalink do
18
+ = form.permalink :permalink
19
+
20
+ = sidebar_expander "Tags & Categories" do
21
+ = field :categories do
22
+ = form.checkboxes :categories, @blog.categories, :editable => true, :placeholder => "Add a category..."
23
+
24
+ = field :tags do
25
+ = form.tags :tags, @blog.tags, :placeholder => "Add a tag..."
@@ -0,0 +1,19 @@
1
+ en:
2
+ resource:
3
+ models:
4
+ blog/post: Blog Post
5
+
6
+ helpers:
7
+ label:
8
+ blog:
9
+ title: Blog Title
10
+
11
+ post:
12
+ title: Post Title
13
+ content: Post Content
14
+ tags_string: Tags
15
+ published_at: Publish Date
16
+
17
+ tabs:
18
+ blog/blog:
19
+ blog_settings: Blog Settings
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Blog::Plugin.routes.draw do
2
+ extend Wheelhouse::RouteExtensions
3
+
4
+ resources :blogs do
5
+ resources :posts
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ require "wheelhouse"
2
+
3
+ module Blog
4
+ class Plugin < Wheelhouse::Plugin
5
+ config.wheelhouse.blog = ActiveSupport::OrderedOptions.new
6
+
7
+ # Enable blog sections by default
8
+ config.wheelhouse.blog.sections = true
9
+
10
+ isolate_namespace Blog
11
+
12
+ resources do
13
+ ::Blog::Blog.select(:id, :label).map do |b|
14
+ Resource(::Blog::Post, :sublabel => b.label, :url => blog.new_blog_post_path(b))
15
+ end
16
+ end
17
+
18
+ resource { Resource(::Blog::Blog) }
19
+
20
+ sections do
21
+ ::Blog::Blog.select(:id, :label).map do |blog|
22
+ Section(blog.label, blog)
23
+ end if ::Blog::Plugin.config.wheelhouse.blog.sections
24
+ end
25
+
26
+ initializer "precompile assets" do |app|
27
+ app.config.assets.precompile << "wheelhouse-blog/admin.*"
28
+ end
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wheelhouse-blog
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sam Pohlenz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: wheelhouse
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ description: Integrates blogs into your Wheelhouse CMS site.
31
+ email: info@wheelhousecms.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - app/assets/images/wheelhouse-blog/blog.png
37
+ - app/assets/images/wheelhouse-blog/post.png
38
+ - app/assets/stylesheets/wheelhouse-blog/admin.css.sass
39
+ - app/controllers/blog/blogs_controller.rb
40
+ - app/controllers/blog/posts_controller.rb
41
+ - app/handlers/blog/blog_handler.rb
42
+ - app/handlers/blog/post_handler.rb
43
+ - app/helpers/blog/blog_helper.rb
44
+ - app/models/blog/blog.rb
45
+ - app/models/blog/post.rb
46
+ - app/templates/blog/_layout.html.haml
47
+ - app/templates/blog/_post.html.haml
48
+ - app/templates/blog/archive.html.haml
49
+ - app/templates/blog/category.html.haml
50
+ - app/templates/blog/feed.xml.builder
51
+ - app/templates/blog/index.html.haml
52
+ - app/templates/blog/post.html.haml
53
+ - app/templates/blog/tag.html.haml
54
+ - app/views/blog/blogs/_posts.haml
55
+ - app/views/blog/blogs/form.haml
56
+ - app/views/blog/posts/form.haml
57
+ - config/locales/en.yml
58
+ - config/routes.rb
59
+ - lib/wheelhouse-blog.rb
60
+ - README.md
61
+ homepage: https://www.wheelhousecms.com
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 1.8.7
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 1.3.6
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.24
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Wheelhouse CMS Blog Plugin
85
+ test_files: []
86
+ has_rdoc: