refinerycms-news 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ class Admin::NewsItemsController < Admin::BaseController
2
+
3
+ crudify :news_item, :order => "created_at DESC"
4
+
5
+ end
@@ -0,0 +1,20 @@
1
+ class NewsItemsController < ApplicationController
2
+
3
+ before_filter :find_latest_news_items, :find_page
4
+ before_filter :find_news_item, :only => [:show]
5
+
6
+ protected
7
+
8
+ def find_latest_news_items
9
+ @news_items = NewsItem.latest # 10 items
10
+ end
11
+
12
+ def find_news_item
13
+ @news_item = NewsItem.published.find(params[:id])
14
+ end
15
+
16
+ def find_page
17
+ @page = Page.find_by_link_url("/news", :include => [:parts, :slugs])
18
+ end
19
+
20
+ end
@@ -0,0 +1,24 @@
1
+ class NewsItem < ActiveRecord::Base
2
+
3
+ validates_presence_of :title, :body, :publish_date
4
+
5
+ has_friendly_id :title, :use_slug => true
6
+
7
+ acts_as_indexed :fields => [:title, :body],
8
+ :index_file => %W(#{Rails.root} tmp index)
9
+
10
+ default_scope :order => "publish_date DESC"
11
+ # If you're using a named scope that includes a changing variable you need to wrap it in a lambda
12
+ # This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
13
+ named_scope :latest, lambda { { :conditions => ["publish_date < ?", Time.now], :limit => 10 } }
14
+ named_scope :published, lambda { { :conditions => ["publish_date < ?", Time.now] } }
15
+
16
+ def not_published? # has the published date not yet arrived?
17
+ publish_date > Time.now
18
+ end
19
+
20
+ def self.per_page
21
+ 20
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ <%= error_messages_for :news_item %>
2
+ <% form_for [:admin, @news_item] do |f| %>
3
+ <div class='field'>
4
+ <%= f.label :title %>
5
+ <%= f.text_field :title, :class => "larger", :style => 'width: 954px' %>
6
+ </div>
7
+ <div class='field'>
8
+ <%= f.label :publish_date %>
9
+ <%= f.datetime_select :publish_date %>
10
+ </div>
11
+ <div class='clearfix' style='width:963px'>
12
+ <div class='field'>
13
+ <%= f.label :body %>
14
+ <%= f.text_area :body, :rows => "20", :class => "wymeditor" %>
15
+ </div>
16
+ </div>
17
+ <%= render :partial => "/shared/admin/form_actions", :locals => {:f => f,
18
+ :continue_editing => true} %>
19
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>'>
2
+ <span class='title'>
3
+ <span class='actions'>
4
+ <%= link_to refinery_icon_tag('application_go.png'), news_item_url(news_item),
5
+ :title => 'View this news item live <br/><em>(opens in a new window)</em>',
6
+ :target => "_blank" %>
7
+ <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_news_item_path(news_item),
8
+ :title => 'Edit this news item' %>
9
+ <%= link_to refinery_icon_tag('delete.png'), admin_news_item_path(news_item),
10
+ :class => "cancel confirm-delete",
11
+ :title => "Remove this news item forever" %>
12
+ </span>
13
+ <%=h news_item.title %> <span class="preview">&nbsp;</span>
14
+ </span>
15
+ </li>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,31 @@
1
+ <div id='actions'>
2
+ <ul>
3
+ <li>
4
+ <%= render :partial => "/shared/admin/search", :locals => {:url => admin_news_items_url} %>
5
+ </li>
6
+ <li>
7
+ <%= link_to "Create News Item", new_admin_news_item_url, :class => "add_icon" %>
8
+ </li>
9
+ </ul>
10
+ </div>
11
+ <div id='records'>
12
+ <%= "<h2>Search Results for \"#{params[:search]}\"</h2>" if searching? %>
13
+ <% if @news_items.any? %>
14
+ <%= will_paginate @news_items, :previous_label => '&laquo;', :next_label => '&raquo;' %>
15
+ <ul>
16
+ <%= render :partial => "news_item", :collection => @news_items %>
17
+ </ul>
18
+ <%= will_paginate @news_items, :previous_label => '&laquo;', :next_label => '&raquo;' %>
19
+ <% else %>
20
+ <% unless searching? %>
21
+ <p>
22
+ <strong>
23
+ There are no news items yet.
24
+ Click "Create News Item" to add your first news item.
25
+ </strong>
26
+ </p>
27
+ <% else %>
28
+ <p>Sorry, no results found.</p>
29
+ <% end %>
30
+ <% end %>
31
+ </div>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,8 @@
1
+ <h2>Recent Posts</h2>
2
+ <ul>
3
+ <% @news_items.each do |item| %>
4
+ <li>
5
+ <%= link_to item.title, news_item_url(item) %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
@@ -0,0 +1,17 @@
1
+ <% content_for :body_content_left do %>
2
+ <%= @page[:body] %>
3
+
4
+ <% if @news_items.any? %>
5
+ <% @news_items.each do |item| %>
6
+ <h3><%= link_to item.title, news_item_url(item) %></h3>
7
+ <p>
8
+ <small>Published <%= item.publish_date.strftime("%A %d of %B, %Y") %></small>
9
+ </p>
10
+ <%= truncate(item.body, :length => 200, :omission => " ... #{link_to "Read more", news_item_url(item)}", :preserve_html_tags => true) %>
11
+ <% end %>
12
+ <% else %>
13
+ <p><em>Sorry we haven't posted up any news yet.</em></p>
14
+ <% end %>
15
+ <% end %>
16
+
17
+ <%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,26 @@
1
+ xml.instruct! :xml, :version => "1.0"
2
+ xml.rss :version => "2.0", "xmlns:atom" => "http://www.w3.org/2005/Atom" do
3
+ xml.channel do
4
+ # Required to pass W3C validation.
5
+ xml.atom :link, nil, {
6
+ :href => news_items_url(:format => 'rss'),
7
+ :rel => 'self', :type => 'application/rss+xml'
8
+ }
9
+
10
+ # Feed basics.
11
+ xml.title page_title
12
+ xml.description @page[:body].gsub(/<\/?[^>]*>/, "")
13
+ xml.link news_items_url(:format => 'rss')
14
+
15
+ # News items.
16
+ @news_items.each do |news_item|
17
+ xml.item do
18
+ xml.title news_item.title
19
+ xml.link news_item_url(news_item)
20
+ xml.description truncate(news_item.body, :length => 200, :preserve_html_tags => true)
21
+ xml.pubDate news_item.publish_date.to_s(:rfc822)
22
+ xml.guid news_item_url(news_item)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ <% content_for :body_content_title, "<h1>#{@news_item.title}</h1>" %>
2
+ <% content_for :body_content_left do %>
3
+ <p>
4
+ <small>Published <%= @news_item.publish_date.strftime("%A %d of %B, %Y") %></small>
5
+ </p>
6
+ <%= @news_item.body %>
7
+ <p>
8
+ <%= link_to "Back to all news", news_items_url %>
9
+ </p>
10
+ <% end %>
11
+ <% content_for :body_content_right, render(:partial => 'recent_posts') %>
12
+
13
+ <%= render :partial => "/shared/content_page" %>
File without changes
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.resources :news_items, :as => :news
3
+
4
+ map.namespace(:admin) do |admin|
5
+ admin.resources :news_items, :as => :news
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ class NewsGenerator < Rails::Generator::NamedBase
2
+
3
+ def manifest
4
+ record do |m|
5
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => setup_news_migration_assigns, :migration_file_name => "create_structure_for_news"
6
+ end
7
+ end
8
+
9
+ private
10
+ def setup_news_migration_assigns
11
+ returning(assigns = {}) do
12
+ assigns[:migration_name] = "CreateStructureForNews"
13
+ assigns[:table_name] = "news_items"
14
+
15
+ # add fields for migration
16
+ assigns[:attributes] = []
17
+ [%w(title string), %w(body text), %w(publish_date datetime)].each do |attribute|
18
+ assigns[:attributes] << Rails::Generator::GeneratedAttribute.new(attribute[0], attribute[1])
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,41 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :<%= table_name %> do |t|
5
+ <% attributes.each do |attribute| -%>
6
+ t.<%= attribute.type %> :<%= attribute.name %>
7
+ <% end -%>
8
+ t.timestamps
9
+
10
+ add_index :<%= table_name %>, :id
11
+
12
+ User.find(:all).each do |user|
13
+ user.plugins.create(:title => "News", :position => (user.plugins.maximum(:position) || -1) + 1)
14
+ end
15
+
16
+ page = Page.create(:title => "News",
17
+ :link_url => "/news",
18
+ :menu_match => "^/news.*$",
19
+ :deletable => false,
20
+ :position => Page.count)
21
+
22
+ RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |default_page_part|
23
+ page.parts.create(:title => default_page_part, :body => nil)
24
+ end
25
+
26
+ end
27
+
28
+ def self.down
29
+ UserPlugin.destroy_all({:title => "News"})
30
+
31
+ Page.find_all_by_link_url("/news").each do |page|
32
+ page.link_url, page.menu_match = nil
33
+ page.deletable = true
34
+ page.destroy
35
+ end
36
+ Page.destroy_all({:link_url => "/news"})
37
+
38
+ drop_table :<%= table_name %>
39
+ end
40
+
41
+ end
data/news.md ADDED
@@ -0,0 +1,20 @@
1
+ # News
2
+
3
+ ![Refinery News](http://refinerycms.com/system/images/0000/0646/news.png)
4
+
5
+ ## About
6
+
7
+ __Refinery's news plugin allows you to post updates to the news section of your website.__
8
+
9
+ Key features:
10
+
11
+ * Default news page shows a summary of recent news posts
12
+ * Detail view shows the full post and also linked to recent news on the "side bar"
13
+
14
+ ## But I don't want a News Section, how do I kill it?
15
+
16
+ Your news section loads because you have a page in your site that is told to not just render a normal page, but load the news section instead.
17
+
18
+ By default this page is called "News". Go to your "Pages" tab in the Refinery admin area and click the edit icon on "News". Now click on "Hide/Show Advanced Options" and you'll see that a "Custom URL" is set to ``/news``. Simply change this to nothing, or delete the "News" page.
19
+
20
+ You might also want to remove the News plugin from your backend view. To do that, you go to the "Users" tab in the Refinery admin area, edit your user, uncheck "News" from the list of plugins you can access.
data/rails/init.rb ADDED
@@ -0,0 +1,11 @@
1
+ Refinery::Plugin.register do |plugin|
2
+ plugin.title = "News"
3
+ plugin.description = "Provides a blog-like news section"
4
+ plugin.version = 1.0
5
+ plugin.menu_match = /admin\/news(_items)?$/
6
+ plugin.activity = {
7
+ :class => NewsItem,
8
+ :title => 'title',
9
+ :url_prefix => 'edit'
10
+ }
11
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-news
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 6
9
+ version: 0.9.6
10
+ platform: ruby
11
+ authors:
12
+ - Resolve Digital
13
+ - Philip Arndt
14
+ - David Jones
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-03-04 00:00:00 +13:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: A really straightforward open source Ruby on Rails news plugin designed for integration with RefineryCMS.
24
+ email: info@refinerycms.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - app/controllers/admin/news_items_controller.rb
33
+ - app/controllers/news_items_controller.rb
34
+ - app/models/news_item.rb
35
+ - app/views/admin/news_items/_form.html.erb
36
+ - app/views/admin/news_items/_news_item.html.erb
37
+ - app/views/admin/news_items/edit.html.erb
38
+ - app/views/admin/news_items/index.html.erb
39
+ - app/views/admin/news_items/new.html.erb
40
+ - app/views/news_items/_recent_posts.html.erb
41
+ - app/views/news_items/index.html.erb
42
+ - app/views/news_items/index.rss.builder
43
+ - app/views/news_items/show.html.erb
44
+ - config/locale/en.yml
45
+ - config/routes.rb
46
+ - lib/generators/news/news_generator.rb
47
+ - lib/generators/news/templates/migration.rb
48
+ - news.md
49
+ - rails/init.rb
50
+ has_rdoc: true
51
+ homepage: http://refinerycms.com
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project:
76
+ rubygems_version: 1.3.6
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Ruby on Rails news plugin for RefineryCMS.
80
+ test_files: []
81
+