refinerycms-news 0.9.8.4 → 0.9.9
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/news_item.rb +2 -2
- data/app/views/admin/news_items/_form.html.erb +8 -2
- data/app/views/admin/news_items/_news_item.html.erb +3 -1
- data/app/views/news_items/show.html.erb +2 -2
- data/config/locales/en.yml +2 -1
- data/config/locales/ru.yml +34 -0
- data/config/routes.rb +5 -5
- data/lib/gemspec.rb +2 -0
- data/lib/generators/refinerycms_news/templates/db/migrate/migration_number_create_singular_name.rb +23 -0
- data/lib/generators/refinerycms_news/templates/db/seeds/seed.rb +16 -0
- data/lib/generators/refinerycms_news_generator.rb +50 -0
- data/lib/news.rb +1 -1
- data/lib/refinerycms-news.rb +23 -0
- data/readme.md +4 -13
- metadata +26 -10
- data/generators/news/news_generator.rb +0 -29
- data/generators/news/templates/migration.rb +0 -42
- data/rails/init.rb +0 -14
data/app/models/news_item.rb
CHANGED
@@ -11,8 +11,8 @@ class NewsItem < ActiveRecord::Base
|
|
11
11
|
|
12
12
|
# If you're using a named scope that includes a changing variable you need to wrap it in a lambda
|
13
13
|
# This avoids the query being cached thus becoming unaffected by changes (i.e. Time.now is constant)
|
14
|
-
|
15
|
-
|
14
|
+
scope :latest, lambda { |*limit| { :conditions => ["publish_date < ?", Time.now], :limit => (limit.first || 10) } }
|
15
|
+
scope :published, lambda { { :conditions => ["publish_date < ?", Time.now] } }
|
16
16
|
|
17
17
|
def not_published? # has the published date not yet arrived?
|
18
18
|
publish_date > Time.now
|
@@ -1,5 +1,9 @@
|
|
1
1
|
<% form_for [:admin, @news_item] do |f| %>
|
2
|
-
<%=
|
2
|
+
<%= render :partial => "/shared/admin/error_messages",
|
3
|
+
:locals => {
|
4
|
+
:object => @news_item,
|
5
|
+
:include_object_name => true
|
6
|
+
} %>
|
3
7
|
|
4
8
|
<div class='field'>
|
5
9
|
<%= f.label :title %>
|
@@ -19,7 +23,9 @@
|
|
19
23
|
<%= render :partial => "/shared/admin/form_actions",
|
20
24
|
:locals => {
|
21
25
|
:f => f,
|
22
|
-
:continue_editing => true
|
26
|
+
:continue_editing => true,
|
27
|
+
:delete_title => t('admin.news_items.news_item.delete'),
|
28
|
+
:delete_confirmation => t('shared.admin.delete.message', :title => @news_item.title)
|
23
29
|
} %>
|
24
30
|
|
25
31
|
<% end %>
|
@@ -11,6 +11,8 @@
|
|
11
11
|
:title => t('.edit') %>
|
12
12
|
<%= link_to refinery_icon_tag('delete.png'), admin_news_item_path(news_item),
|
13
13
|
:class => "cancel confirm-delete",
|
14
|
-
:title => t('.delete')
|
14
|
+
:title => t('.delete'),
|
15
|
+
:'data-method' => :delete,
|
16
|
+
:'data-confirm' => t('shared.admin.delete.message', :title => news_item.title) %>
|
15
17
|
</span>
|
16
18
|
</li>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<% content_for :body_content_title,
|
1
|
+
<% content_for :body_content_title, @news_item.title %>
|
2
2
|
<% content_for :body_content_left do %>
|
3
3
|
<p>
|
4
4
|
<small><%= t('.published') %> <%= l(@news_item.publish_date, :format => :long) %></small>
|
5
5
|
</p>
|
6
|
-
<%= @news_item.body %>
|
6
|
+
<%= @news_item.body.html_safe %>
|
7
7
|
<p>
|
8
8
|
<%= link_to t('.back_to_index'), news_items_url %>
|
9
9
|
</p>
|
data/config/locales/en.yml
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
ru:
|
2
|
+
plugins:
|
3
|
+
news:
|
4
|
+
title: "Новости"
|
5
|
+
admin:
|
6
|
+
news_items:
|
7
|
+
news_item:
|
8
|
+
view_live: "Просмотреть новость <br/><em>(будет открыто в новом окне)</em>"
|
9
|
+
edit: "Редактировать новость"
|
10
|
+
delete: "Удалить новость"
|
11
|
+
index:
|
12
|
+
actions: "Действия"
|
13
|
+
create: "Создать новость"
|
14
|
+
news_item: "Новости"
|
15
|
+
no_items: "Ничего не найдено."
|
16
|
+
no_items_yet: 'Новостей пока нет.'
|
17
|
+
news_items:
|
18
|
+
show:
|
19
|
+
back_to_index: "Вернуться к новостям"
|
20
|
+
published: "Опубликована"
|
21
|
+
no_items: "Пока новостей нет."
|
22
|
+
recent_posts:
|
23
|
+
recent_posts: "Последние публикации"
|
24
|
+
index:
|
25
|
+
published: "Опубликовано"
|
26
|
+
read_more: "Читать далее"
|
27
|
+
activerecord:
|
28
|
+
attributes:
|
29
|
+
news_item:
|
30
|
+
title: "Заголовок"
|
31
|
+
body: "Публикация"
|
32
|
+
publish_date: "Дата публикации"
|
33
|
+
models:
|
34
|
+
news_item: "Новость"
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
Refinery::Application.routes.draw do
|
2
|
+
resources :news, :as => :news_items, :controller => :news_items
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
|
5
|
+
resources :news, :as => :news_items, :controller => :news_items
|
6
6
|
end
|
7
|
-
end
|
7
|
+
end
|
data/lib/gemspec.rb
CHANGED
data/lib/generators/refinerycms_news/templates/db/migrate/migration_number_create_singular_name.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Create<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :<%= table_name %>, :id => true 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
|
+
load(Rails.root.join('db', 'seeds', 'refinerycms_news.rb').to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
UserPlugin.destroy_all({:name => "refinerycms_news"})
|
17
|
+
|
18
|
+
Page.delete_all({:link_url => "/news"})
|
19
|
+
|
20
|
+
drop_table :<%= table_name %>
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
User.find(:all).each do |user|
|
2
|
+
user.plugins.create(:name => "refinerycms_news",
|
3
|
+
:position => (user.plugins.maximum(:position) || -1) +1)
|
4
|
+
end
|
5
|
+
|
6
|
+
page = Page.create(
|
7
|
+
:title => "News",
|
8
|
+
:link_url => "/news",
|
9
|
+
:deletable => false,
|
10
|
+
:position => ((Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
|
11
|
+
:menu_match => "^/news.*$"
|
12
|
+
)
|
13
|
+
|
14
|
+
Page.default_parts.each do |default_page_part|
|
15
|
+
page.parts.create(:title => default_page_part, :body => nil)
|
16
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class RefinerycmsNewsGenerator < Rails::Generators::NamedBase
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path('../refinerycms_news/templates/', __FILE__)
|
7
|
+
argument :name, :type => :string, :default => 'news_items', :banner => ''
|
8
|
+
argument :attributes, :type => :array, :default => ["title:string", "body:text", "publish_date:datetime"]
|
9
|
+
|
10
|
+
def generate
|
11
|
+
# seed file
|
12
|
+
template 'db/seeds/seed.rb', Rails.root.join('db/seeds/refinerycms_news.rb')
|
13
|
+
|
14
|
+
next_migration_number = ActiveRecord::Generators::Base.next_migration_number(File.dirname(__FILE__))
|
15
|
+
template('db/migrate/migration_number_create_singular_name.rb',
|
16
|
+
Rails.root.join("db/migrate/#{next_migration_number}_create_#{singular_name}.rb"))
|
17
|
+
|
18
|
+
puts "------------------------"
|
19
|
+
puts "Now run:"
|
20
|
+
puts "rake db:migrate"
|
21
|
+
puts "------------------------"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Below is a hack until this issue:
|
26
|
+
# https://rails.lighthouseapp.com/projects/8994/tickets/3820-make-railsgeneratorsmigrationnext_migration_number-method-a-class-method-so-it-possible-to-use-it-in-custom-generators
|
27
|
+
# is fixed on the Rails project.
|
28
|
+
|
29
|
+
require 'rails/generators/named_base'
|
30
|
+
require 'rails/generators/migration'
|
31
|
+
require 'rails/generators/active_model'
|
32
|
+
require 'active_record'
|
33
|
+
|
34
|
+
module ActiveRecord
|
35
|
+
module Generators
|
36
|
+
class Base < Rails::Generators::NamedBase #:nodoc:
|
37
|
+
include Rails::Generators::Migration
|
38
|
+
|
39
|
+
# Implement the required interface for Rails::Generators::Migration.
|
40
|
+
def self.next_migration_number(dirname) #:nodoc:
|
41
|
+
next_migration_number = current_migration_number(dirname) + 1
|
42
|
+
if ActiveRecord::Base.timestamped_migrations
|
43
|
+
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
44
|
+
else
|
45
|
+
"%.3d" % next_migration_number
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/news.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'refinery'
|
2
|
+
require File.expand_path('../news', __FILE__)
|
3
|
+
|
4
|
+
module Refinery
|
5
|
+
module News
|
6
|
+
|
7
|
+
class Engine < Rails::Engine
|
8
|
+
config.after_initialize do
|
9
|
+
Refinery::Plugin.register do |plugin|
|
10
|
+
plugin.name = "refinerycms_news"
|
11
|
+
plugin.menu_match = /(admin|refinery)\/news(_items)?$/
|
12
|
+
plugin.url = {:controller => '/admin/news_items', :action => 'index'}
|
13
|
+
plugin.activity = {
|
14
|
+
:class => NewsItem,
|
15
|
+
:title => 'title',
|
16
|
+
:url_prefix => 'edit'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/readme.md
CHANGED
@@ -17,27 +17,18 @@ To install the news engine, you can either include the gem or install as a plugi
|
|
17
17
|
|
18
18
|
## Requirements
|
19
19
|
|
20
|
-
[RefineryCMS](http://refinerycms.com) version 0.9.
|
20
|
+
[RefineryCMS](http://refinerycms.com) version 0.9.8 or later.
|
21
21
|
|
22
|
-
### Gem Installation using Bundler
|
22
|
+
### Gem Installation using Bundler (The very best way)
|
23
23
|
|
24
24
|
Include the latest [gem](http://rubygems.org/gems/refinerycms-news) into your Refinery CMS application's Gemfile:
|
25
25
|
|
26
|
-
gem "refinerycms-news", '~> 0.9.
|
26
|
+
gem "refinerycms-news", '~> 0.9.9'
|
27
27
|
|
28
28
|
Then type the following at command line inside your Refinery CMS application's root directory:
|
29
29
|
|
30
30
|
bundle install
|
31
|
-
|
32
|
-
rake db:migrate
|
33
|
-
|
34
|
-
### Rails Engine Installation
|
35
|
-
|
36
|
-
If you do not want to install the engine via bundler then you can install it as an engine inside your application's vendor directory.
|
37
|
-
Type the following at command line inside your Refinery CMS application's root directory:
|
38
|
-
|
39
|
-
script/plugin install git://github.com/resolve/refinerycms-news.git
|
40
|
-
script/generate news
|
31
|
+
rails generate refinerycms_news
|
41
32
|
rake db:migrate
|
42
33
|
|
43
34
|
## RSS (Really Simple Syndication)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinerycms-news
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.9.8.4
|
9
|
+
- 9
|
10
|
+
version: 0.9.9
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Resolve Digital
|
@@ -16,10 +15,25 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-
|
18
|
+
date: 2010-09-09 00:00:00 +12:00
|
20
19
|
default_executable:
|
21
|
-
dependencies:
|
22
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: refinerycms
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 43
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 8
|
34
|
+
version: 0.9.8
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
23
37
|
description: A really straightforward open source Ruby on Rails news engine designed for integration with RefineryCMS.
|
24
38
|
email: info@refinerycms.com
|
25
39
|
executables: []
|
@@ -44,13 +58,15 @@ files:
|
|
44
58
|
- config/locales/en.yml
|
45
59
|
- config/locales/nl.yml
|
46
60
|
- config/locales/pt-BR.yml
|
61
|
+
- config/locales/ru.yml
|
47
62
|
- config/routes.rb
|
48
|
-
- generators/news/news_generator.rb
|
49
|
-
- generators/news/templates/migration.rb
|
50
63
|
- lib/gemspec.rb
|
64
|
+
- lib/generators/refinerycms_news/templates/db/migrate/migration_number_create_singular_name.rb
|
65
|
+
- lib/generators/refinerycms_news/templates/db/seeds/seed.rb
|
66
|
+
- lib/generators/refinerycms_news_generator.rb
|
51
67
|
- lib/news.rb
|
68
|
+
- lib/refinerycms-news.rb
|
52
69
|
- license.md
|
53
|
-
- rails/init.rb
|
54
70
|
- readme.md
|
55
71
|
- test/fixtures/news_items.yml
|
56
72
|
- test/unit/news_items_test.rb
|
@@ -1,29 +0,0 @@
|
|
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)
|
@@ -1,42 +0,0 @@
|
|
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(:name => "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/rails/init.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
Refinery::Plugin.register do |plugin|
|
2
|
-
plugin.title = "News"
|
3
|
-
plugin.name = "news"
|
4
|
-
plugin.description = "Provides a blog-like news section"
|
5
|
-
plugin.version = 1.0
|
6
|
-
plugin.menu_match = /(admin|refinery)\/news(_items)?$/
|
7
|
-
plugin.url = '/refinery/news'
|
8
|
-
plugin.activity = {
|
9
|
-
:class => NewsItem,
|
10
|
-
:title => 'title',
|
11
|
-
:url_prefix => 'edit'
|
12
|
-
}
|
13
|
-
plugin.directory = directory
|
14
|
-
end
|