sneakin-refinerycms-news 0.9.7.1

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.paginate(:page => params[:page]) # 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,18 @@
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
+ <%= will_paginate(@news_items) %>
13
+ <% else %>
14
+ <p><em>Sorry we haven't posted up any news yet.</em></p>
15
+ <% end %>
16
+ <% end %>
17
+
18
+ <%= 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,29 @@
1
+ class NewsGenerator < Rails::Generator::NamedBase
2
+
3
+ def initialize(*runtime_args)
4
+ # set first argument to the table's name so that the user doesn't have to pass it in.
5
+ runtime_args[0] = ["news_items"]
6
+ super(*runtime_args)
7
+ end
8
+
9
+ def banner
10
+ "Usage: script/generate news"
11
+ end
12
+
13
+ def manifest
14
+ record do |m|
15
+ m.migration_template 'migration.rb', 'db/migrate',
16
+ :migration_file_name => "create_structure_for_news",
17
+ :assigns => {
18
+ :migration_name => "CreateStructureForNews",
19
+ :table_name => "news_items",
20
+ :attributes => [
21
+ Rails::Generator::GeneratedAttribute.new("title", "string"),
22
+ Rails::Generator::GeneratedAttribute.new("body", "text"),
23
+ Rails::Generator::GeneratedAttribute.new("publish_date", "datetime")
24
+ ]
25
+ }
26
+ end
27
+ end
28
+
29
+ end if defined?(Rails::Generator::NamedBase)
@@ -0,0 +1,42 @@
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
+ end
10
+
11
+ add_index :<%= table_name %>, :id
12
+
13
+ User.find(:all).each do |user|
14
+ user.plugins.create(:title => "News", :position => (user.plugins.maximum(:position) || -1) + 1)
15
+ end
16
+
17
+ page = Page.create(:title => "News",
18
+ :link_url => "/news",
19
+ :menu_match => "^/news.*$",
20
+ :deletable => false,
21
+ :position => Page.count)
22
+
23
+ RefinerySetting.find_or_set(:default_page_parts, ["Body", "Side Body"]).each do |default_page_part|
24
+ page.parts.create(:title => default_page_part, :body => nil)
25
+ end
26
+
27
+ end
28
+
29
+ def self.down
30
+ UserPlugin.destroy_all({:title => "News"})
31
+
32
+ Page.find_all_by_link_url("/news").each do |page|
33
+ page.link_url, page.menu_match = nil
34
+ page.deletable = true
35
+ page.destroy
36
+ end
37
+ Page.destroy_all({:link_url => "/news"})
38
+
39
+ drop_table :<%= table_name %>
40
+ end
41
+
42
+ end
data/lib/news.rb ADDED
@@ -0,0 +1 @@
1
+ #empty, but required.
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,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sneakin-refinerycms-news
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.7.1
5
+ platform: ruby
6
+ authors:
7
+ - Resolve Digital
8
+ - Philip Arndt
9
+ - David Jones
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2010-05-01 00:00:00 -04:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: will_paginate
19
+ type: :runtime
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 2.3.11
26
+ version:
27
+ description: A really straightforward open source Ruby on Rails news plugin designed for integration with RefineryCMS.
28
+ email: info@refinerycms.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files: []
34
+
35
+ files:
36
+ - app/controllers/admin/news_items_controller.rb
37
+ - app/controllers/news_items_controller.rb
38
+ - app/models/news_item.rb
39
+ - app/views/admin/news_items/_form.html.erb
40
+ - app/views/admin/news_items/_news_item.html.erb
41
+ - app/views/admin/news_items/edit.html.erb
42
+ - app/views/admin/news_items/index.html.erb
43
+ - app/views/admin/news_items/new.html.erb
44
+ - app/views/news_items/_recent_posts.html.erb
45
+ - app/views/news_items/index.html.erb
46
+ - app/views/news_items/index.rss.builder
47
+ - app/views/news_items/show.html.erb
48
+ - config/locale/en.yml
49
+ - config/routes.rb
50
+ - generators/news/news_generator.rb
51
+ - generators/news/templates/migration.rb
52
+ - lib/news.rb
53
+ - rails/init.rb
54
+ has_rdoc: true
55
+ homepage: http://refinerycms.com
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Ruby on Rails news plugin for RefineryCMS.
82
+ test_files: []
83
+