Permalink
Browse files

Initial extraction from RefineryCMS core

  • Loading branch information...
0 parents commit ce2bb1b1b96435d2c3a6692a64a472e9eaf5cc6a @parndt parndt committed Mar 4, 2010
@@ -0,0 +1,5 @@
+class Admin::NewsItemsController < Admin::BaseController
+
+ crudify :news_item, :order => "created_at DESC"
+
+end
@@ -0,0 +1,20 @@
+class NewsItemsController < ApplicationController
+
+ before_filter :find_latest_news_items, :find_page
+ before_filter :find_news_item, :only => [:show]
+
+protected
+
+ def find_latest_news_items
+ @news_items = NewsItem.latest # 10 items
+ end
+
+ def find_news_item
+ @news_item = NewsItem.published.find(params[:id])
+ end
+
+ def find_page
+ @page = Page.find_by_link_url("/news", :include => [:parts, :slugs])
+ end
+
+end
@@ -0,0 +1,24 @@
+class NewsItem < ActiveRecord::Base
+
+ validates_presence_of :title, :body, :publish_date
+
+ has_friendly_id :title, :use_slug => true
+
+ acts_as_indexed :fields => [:title, :body],
+ :index_file => %W(#{Rails.root} tmp index)
+
+ default_scope :order => "publish_date DESC"
+ # If you're using a named scope that includes a changing variable you need to wrap it in a lambda
+ # This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
+ named_scope :latest, lambda { { :conditions => ["publish_date < ?", Time.now], :limit => 10 } }
+ named_scope :published, lambda { { :conditions => ["publish_date < ?", Time.now] } }
+
+ def not_published? # has the published date not yet arrived?
+ publish_date > Time.now
+ end
+
+ def self.per_page
+ 20
+ end
+
+end
@@ -0,0 +1,19 @@
+<%= error_messages_for :news_item %>
+<% form_for [:admin, @news_item] do |f| %>
+ <div class='field'>
+ <%= f.label :title %>
+ <%= f.text_field :title, :class => "larger", :style => 'width: 954px' %>
+ </div>
+ <div class='field'>
+ <%= f.label :publish_date %>
+ <%= f.datetime_select :publish_date %>
+ </div>
+ <div class='clearfix' style='width:963px'>
+ <div class='field'>
+ <%= f.label :body %>
+ <%= f.text_area :body, :rows => "20", :class => "wymeditor" %>
+ </div>
+ </div>
+ <%= render :partial => "/shared/admin/form_actions", :locals => {:f => f,
+ :continue_editing => true} %>
+<% end %>
@@ -0,0 +1,15 @@
+<li class='clearfix record <%= cycle("on", "on-hover") %>'>
+ <span class='title'>
+ <span class='actions'>
+ <%= link_to refinery_icon_tag('application_go.png'), news_item_url(news_item),
+ :title => 'View this news item live <br/><em>(opens in a new window)</em>',
+ :target => "_blank" %>
+ <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_news_item_path(news_item),
+ :title => 'Edit this news item' %>
+ <%= link_to refinery_icon_tag('delete.png'), admin_news_item_path(news_item),
+ :class => "cancel confirm-delete",
+ :title => "Remove this news item forever" %>
+ </span>
+ <%=h news_item.title %> <span class="preview">&nbsp;</span>
+ </span>
+</li>
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
@@ -0,0 +1,31 @@
+<div id='actions'>
+ <ul>
+ <li>
+ <%= render :partial => "/shared/admin/search", :locals => {:url => admin_news_items_url} %>
+ </li>
+ <li>
+ <%= link_to "Create News Item", new_admin_news_item_url, :class => "add_icon" %>
+ </li>
+ </ul>
+</div>
+<div id='records'>
+ <%= "<h2>Search Results for \"#{params[:search]}\"</h2>" if searching? %>
+ <% if @news_items.any? %>
+ <%= will_paginate @news_items, :previous_label => '&laquo;', :next_label => '&raquo;' %>
+ <ul>
+ <%= render :partial => "news_item", :collection => @news_items %>
+ </ul>
+ <%= will_paginate @news_items, :previous_label => '&laquo;', :next_label => '&raquo;' %>
+ <% else %>
+ <% unless searching? %>
+ <p>
+ <strong>
+ There are no news items yet.
+ Click "Create News Item" to add your first news item.
+ </strong>
+ </p>
+ <% else %>
+ <p>Sorry, no results found.</p>
+ <% end %>
+ <% end %>
+</div>
@@ -0,0 +1 @@
+<%= render :partial => "form" %>
@@ -0,0 +1,8 @@
+<h2>Recent Posts</h2>
+<ul>
+ <% @news_items.each do |item| %>
+ <li>
+ <%= link_to item.title, news_item_url(item) %>
+ </li>
+ <% end %>
+</ul>
@@ -0,0 +1,17 @@
+<% content_for :body_content_left do %>
+ <%= @page[:body] %>
+
+ <% if @news_items.any? %>
+ <% @news_items.each do |item| %>
+ <h3><%= link_to item.title, news_item_url(item) %></h3>
+ <p>
+ <small>Published <%= item.publish_date.strftime("%A %d of %B, %Y") %></small>
+ </p>
+ <%= truncate(item.body, :length => 200, :omission => " ... #{link_to "Read more", news_item_url(item)}", :preserve_html_tags => true) %>
+ <% end %>
+ <% else %>
+ <p><em>Sorry we haven't posted up any news yet.</em></p>
+ <% end %>
+<% end %>
+
+<%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,26 @@
+xml.instruct! :xml, :version => "1.0"
+xml.rss :version => "2.0", "xmlns:atom" => "http://www.w3.org/2005/Atom" do
+ xml.channel do
+ # Required to pass W3C validation.
+ xml.atom :link, nil, {
+ :href => news_items_url(:format => 'rss'),
+ :rel => 'self', :type => 'application/rss+xml'
+ }
+
+ # Feed basics.
+ xml.title page_title
+ xml.description @page[:body].gsub(/<\/?[^>]*>/, "")
+ xml.link news_items_url(:format => 'rss')
+
+ # News items.
+ @news_items.each do |news_item|
+ xml.item do
+ xml.title news_item.title
+ xml.link news_item_url(news_item)
+ xml.description truncate(news_item.body, :length => 200, :preserve_html_tags => true)
+ xml.pubDate news_item.publish_date.to_s(:rfc822)
+ xml.guid news_item_url(news_item)
+ end
+ end
+ end
+end
@@ -0,0 +1,13 @@
+<% content_for :body_content_title, "<h1>#{@news_item.title}</h1>" %>
+<% content_for :body_content_left do %>
+ <p>
+ <small>Published <%= @news_item.publish_date.strftime("%A %d of %B, %Y") %></small>
+ </p>
+ <%= @news_item.body %>
+ <p>
+ <%= link_to "Back to all news", news_items_url %>
+ </p>
+<% end %>
+<% content_for :body_content_right, render(:partial => 'recent_posts') %>
+
+<%= render :partial => "/shared/content_page" %>
No changes.
@@ -0,0 +1,7 @@
+ActionController::Routing::Routes.draw do |map|
+ map.resources :news_items, :as => :news
+
+ map.namespace(:admin) do |admin|
+ admin.resources :news_items, :as => :news
+ end
+end
@@ -0,0 +1,23 @@
+class NewsGenerator < Rails::Generator::NamedBase
+
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => setup_news_migration_assigns, :migration_file_name => "create_structure_for_news"
+ end
+ end
+
+private
+ def setup_news_migration_assigns
+ returning(assigns = {}) do
+ assigns[:migration_name] = "CreateStructureForNews"
+ assigns[:table_name] = "news_items"
+
+ # add fields for migration
+ assigns[:attributes] = []
+ [%w(title string), %w(body text), %w(publish_date datetime)].each do |attribute|
+ assigns[:attributes] << Rails::Generator::GeneratedAttribute.new(attribute[0], attribute[1])
+ end
+ end
+ end
+
+end
@@ -0,0 +1,41 @@
+class <%= migration_name %> < ActiveRecord::Migration
+
+ def self.up
+ create_table :<%= table_name %> do |t|
+<% attributes.each do |attribute| -%>
+ t.<%= attribute.type %> :<%= attribute.name %>
+<% end -%>
+ t.timestamps
+
+ add_index :<%= table_name %>, :id
+
+ User.find(:all).each do |user|
+ user.plugins.create(:title => "News", :position => (user.plugins.maximum(:position) || -1) + 1)
+ end
+
+ page = Page.create(:title => "News",
+ :link_url => "/news",
+ :menu_match => "^/news.*$",
+ :deletable => false,
+ :position => Page.count)
+
+ RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |default_page_part|
+ page.parts.create(:title => default_page_part, :body => nil)
+ end
+
+ end
+
+ def self.down
+ UserPlugin.destroy_all({:title => "News"})
+
+ Page.find_all_by_link_url("/news").each do |page|
+ page.link_url, page.menu_match = nil
+ page.deletable = true
+ page.destroy
+ end
+ Page.destroy_all({:link_url => "/news"})
+
+ drop_table :<%= table_name %>
+ end
+
+end
20 news.md
@@ -0,0 +1,20 @@
+# News
+
+![Refinery News](http://refinerycms.com/system/images/0000/0646/news.png)
+
+## About
+
+__Refinery's news plugin allows you to post updates to the news section of your website.__
+
+Key features:
+
+* Default news page shows a summary of recent news posts
+* Detail view shows the full post and also linked to recent news on the "side bar"
+
+## But I don't want a News Section, how do I kill it?
+
+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.
+
+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.
+
+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.
@@ -0,0 +1,11 @@
+Refinery::Plugin.register do |plugin|
+ plugin.title = "News"
+ plugin.description = "Provides a blog-like news section"
+ plugin.version = 1.0
+ plugin.menu_match = /admin\/news(_items)?$/
+ plugin.activity = {
+ :class => NewsItem,
+ :title => 'title',
+ :url_prefix => 'edit'
+ }
+end
@@ -0,0 +1,53 @@
+Gem::Specification.new do |s|
+
+ s.name = %q{refinerycms-news}
+ s.version = "0.9.6"
+
+ s.authors = ["Resolve Digital", "Philip Arndt", "David Jones"]
+ s.date = %q{2010-03-04}
+
+ s.description = %q{A really straightforward open source Ruby on Rails news plugin designed for integration with RefineryCMS.}
+ s.summary = %q{Ruby on Rails news plugin for RefineryCMS.}
+
+ s.email = %q{info@refinerycms.com}
+
+ s.homepage = %q{http://refinerycms.com}
+ s.rubygems_version = %q{1.3.4}
+
+ s.files = [
+ "app",
+ "app/controllers",
+ "app/controllers/admin",
+ "app/controllers/admin/news_items_controller.rb",
+ "app/controllers/news_items_controller.rb",
+ "app/models",
+ "app/models/news_item.rb",
+ "app/views",
+ "app/views/admin",
+ "app/views/admin/news_items",
+ "app/views/admin/news_items/_form.html.erb",
+ "app/views/admin/news_items/_news_item.html.erb",
+ "app/views/admin/news_items/edit.html.erb",
+ "app/views/admin/news_items/index.html.erb",
+ "app/views/admin/news_items/new.html.erb",
+ "app/views/news_items",
+ "app/views/news_items/_recent_posts.html.erb",
+ "app/views/news_items/index.html.erb",
+ "app/views/news_items/index.rss.builder",
+ "app/views/news_items/show.html.erb",
+ "config",
+ "config/locale",
+ "config/locale/en.yml",
+ "config/routes.rb",
+ "lib",
+ "lib/generators",
+ "lib/generators/news",
+ "lib/generators/news/news_generator.rb",
+ "lib/generators/news/templates",
+ "lib/generators/news/templates/migration.rb",
+ "news.md",
+ "rails",
+ "rails/init.rb"
+ ]
+
+end

0 comments on commit ce2bb1b

Please sign in to comment.