├── .rspec ├── lib ├── refinerycms-news.rb ├── refinery │ ├── news.rb │ └── news │ │ └── engine.rb └── generators │ └── refinery │ └── news_generator.rb ├── app ├── views │ └── refinery │ │ └── news │ │ ├── admin │ │ └── items │ │ │ ├── new.html.erb │ │ │ ├── edit.html.erb │ │ │ ├── index.html.erb │ │ │ ├── _item.html.erb │ │ │ └── _form.html.erb │ │ ├── shared │ │ ├── _body_content_right.html.erb │ │ └── _item.html.erb │ │ └── items │ │ ├── widgets │ │ └── _news_archive.html.erb │ │ ├── _recent_posts.html.erb │ │ ├── show.html.erb │ │ ├── archive.html.erb │ │ ├── index.rss.builder │ │ └── index.html.erb ├── controllers │ └── refinery │ │ └── news │ │ ├── admin │ │ └── items_controller.rb │ │ └── items_controller.rb ├── helpers │ └── refinery │ │ └── news │ │ └── items_helper.rb └── models │ └── refinery │ └── news │ └── item.rb ├── tasks ├── rspec.rake └── testing.rake ├── .github └── dependabot.yml ├── .gitignore ├── db ├── migrate │ ├── 20120228150250_add_slug_to_news_items.rb │ ├── 20110817203704_add_image_id_to_news_items.rb │ ├── 20110817203702_add_external_url_to_news_items.rb │ ├── 20110817203705_add_expiration_date_to_news_items.rb │ ├── 20120129230838_add_source_to_news_items.rb │ ├── 20120129230839_translate_source.rb │ ├── 20110817203701_create_news_items.rb │ ├── 20110817203703_translate_news_items.rb │ ├── 20110817203706_remove_image_id_and_external_url_from_news.rb │ └── 20131128000000_move_slug_to_news_item_translations.rb └── seeds.rb ├── spec ├── factories │ └── news.rb ├── features │ ├── news_archive.rb │ ├── visit_news_items_spec.rb │ └── manage_news_items_spec.rb ├── spec_helper.rb ├── helpers │ └── refinery │ │ └── news │ │ └── items_helper_spec.rb ├── controllers │ └── refinery │ │ └── news │ │ └── items_controller_spec.rb └── models │ └── refinery │ └── news │ └── item_spec.rb ├── bin ├── rails ├── spring ├── rake └── rspec ├── Rakefile ├── .travis.yml ├── config ├── routes.rb └── locales │ ├── ru.yml │ ├── zh-TW.yml │ ├── es-MX.yml │ ├── zh-CN.yml │ ├── sl.yml │ ├── cs.yml │ ├── nb.yml │ ├── it.yml │ ├── es.yml │ ├── bg.yml │ ├── de.yml │ ├── lv.yml │ ├── ja.yml │ ├── da.yml │ ├── sk.yml │ ├── en.yml │ ├── pl.yml │ ├── pt-BR.yml │ ├── uk.yml │ ├── fr.yml │ └── nl.yml ├── refinerycms-news.gemspec ├── license.md ├── Gemfile └── readme.md /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /lib/refinerycms-news.rb: -------------------------------------------------------------------------------- 1 | require 'refinery/news' 2 | -------------------------------------------------------------------------------- /app/views/refinery/news/admin/items/new.html.erb: -------------------------------------------------------------------------------- 1 | <%= render "form" %> 2 | -------------------------------------------------------------------------------- /app/views/refinery/news/admin/items/edit.html.erb: -------------------------------------------------------------------------------- 1 | <%= render "form" %> 2 | -------------------------------------------------------------------------------- /tasks/rspec.rake: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | 3 | desc "Run specs" 4 | RSpec::Core::RakeTask.new 5 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: bundler 4 | directory: "/" 5 | schedule: 6 | interval: monthly 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Gemfile.lock 3 | spec/dummy 4 | .idea 5 | 6 | # Local Gemfile for developing without sharing dependencies 7 | .gemfile 8 | -------------------------------------------------------------------------------- /db/migrate/20120228150250_add_slug_to_news_items.rb: -------------------------------------------------------------------------------- 1 | class AddSlugToNewsItems < ActiveRecord::Migration[4.2] 2 | def change 3 | add_column Refinery::News::Item.table_name, :slug, :string 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /app/views/refinery/news/shared/_body_content_right.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :side_body do %> 2 | <%= yield(:body_content_right_prepend) %> 3 | <%= news_item_archive_widget %> 4 | <%= yield(:body_content_right_append) %> 5 | <% end %> 6 | -------------------------------------------------------------------------------- /spec/factories/news.rb: -------------------------------------------------------------------------------- 1 | FactoryBot.define do 2 | factory :news_item, :class => Refinery::News::Item do 3 | title "Refinery CMS News Item" 4 | content "Some random text ..." 5 | publish_date Time.now - 5.minutes 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /app/views/refinery/news/items/widgets/_news_archive.html.erb: -------------------------------------------------------------------------------- 1 |
2 |

<%= t('archives', :scope => 'refinery.news.shared') %>

3 | 6 |
7 | -------------------------------------------------------------------------------- /bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | ENGINE_PATH = File.expand_path('../..', __FILE__) 5 | load File.expand_path('../../spec/dummy/bin/rails', __FILE__) 6 | -------------------------------------------------------------------------------- /spec/features/news_archive.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe "manage news items", :type => :feature do 4 | before do 5 | date = "dec/2011" 6 | @time = Time.parse(date) 7 | end 8 | 9 | it "should display proper date" do 10 | expect(@time).to eq("dec/2011") 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /app/views/refinery/news/items/_recent_posts.html.erb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasks/testing.rake: -------------------------------------------------------------------------------- 1 | namespace :refinery do 2 | namespace :testing do 3 | # Put any code in here that you want run when you test this extension against a dummy app. 4 | # For example, the call to require your gem and start your generator. 5 | task :setup_extension do 6 | 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /db/migrate/20110817203704_add_image_id_to_news_items.rb: -------------------------------------------------------------------------------- 1 | class AddImageIdToNewsItems < ActiveRecord::Migration[4.2] 2 | 3 | def up 4 | unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:image_id) 5 | add_column ::Refinery::News::Item.table_name, :image_id, :integer 6 | end 7 | end 8 | 9 | def down 10 | remove_column ::Refinery::News::Item.table_name, :image_id 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /app/controllers/refinery/news/admin/items_controller.rb: -------------------------------------------------------------------------------- 1 | module Refinery 2 | module News 3 | module Admin 4 | class ItemsController < ::Refinery::AdminController 5 | 6 | crudify :'refinery/news/item', :order => "publish_date DESC" 7 | 8 | private 9 | 10 | def item_params 11 | params.require(:item).permit(:title, :body, :content, :source, :publish_date, :expiration_date) 12 | end 13 | 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /db/migrate/20110817203702_add_external_url_to_news_items.rb: -------------------------------------------------------------------------------- 1 | class AddExternalUrlToNewsItems < ActiveRecord::Migration[4.2] 2 | 3 | def up 4 | unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:external_url) 5 | add_column ::Refinery::News::Item.table_name, :external_url, :string 6 | end 7 | end 8 | 9 | def down 10 | if ::Refinery::News::Item.column_names.map(&:to_sym).include?(:external_url) 11 | remove_column ::Refinery::News::Item.table_name, :external_url 12 | end 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /lib/refinery/news.rb: -------------------------------------------------------------------------------- 1 | require 'refinerycms-core' 2 | require 'refinerycms-settings' 3 | 4 | module Refinery 5 | autoload :NewsGenerator, 'generators/refinery/news_generator' 6 | 7 | module News 8 | require 'refinery/news/engine' 9 | 10 | class << self 11 | attr_writer :root 12 | 13 | def root 14 | @root ||= Pathname.new(File.expand_path('../../../', __FILE__)) 15 | end 16 | 17 | def factory_paths 18 | @factory_paths ||= [ root.join("spec/factories").to_s ] 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /db/migrate/20110817203705_add_expiration_date_to_news_items.rb: -------------------------------------------------------------------------------- 1 | class AddExpirationDateToNewsItems < ActiveRecord::Migration[4.2] 2 | 3 | def up 4 | unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:expiration_date) 5 | add_column ::Refinery::News::Item.table_name, :expiration_date, :datetime 6 | end 7 | end 8 | 9 | def down 10 | if ::Refinery::News::Item.column_names.map(&:to_sym).include?(:expiration_date) 11 | remove_column ::Refinery::News::Item.table_name, :expiration_date 12 | end 13 | end 14 | 15 | end 16 | -------------------------------------------------------------------------------- /db/migrate/20120129230838_add_source_to_news_items.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from refinery_news (originally 7) 2 | class AddSourceToNewsItems < ActiveRecord::Migration[4.2] 3 | 4 | def up 5 | unless Refinery::News::Item.column_names.map(&:to_sym).include?(:source) 6 | add_column Refinery::News::Item.table_name, :source, :string 7 | end 8 | end 9 | 10 | def down 11 | if Refinery::News::Item.column_names.map(&:to_sym).include?(:source) 12 | remove_column Refinery::News::Item.table_name, :source 13 | end 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | begin 3 | require 'bundler/setup' 4 | rescue LoadError 5 | puts 'You must `gem install bundler` and `bundle install` to run rake tasks' 6 | end 7 | 8 | ENGINE_PATH = File.dirname(__FILE__) 9 | APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__) 10 | 11 | if File.exists?(APP_RAKEFILE) 12 | load 'rails/tasks/engine.rake' 13 | end 14 | 15 | require "refinerycms-testing" 16 | Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH) 17 | 18 | load File.expand_path('../tasks/rspec.rake', __FILE__) 19 | 20 | task :default => :spec 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | cache: bundler 3 | sudo: false 4 | addons: 5 | postgresql: '10' 6 | services: 7 | - mysql 8 | branches: 9 | only: 10 | - master 11 | bundler_args: --without development 12 | before_script: "bin/rake refinery:testing:dummy_app" 13 | script: "bin/rspec spec" 14 | notifications: 15 | irc: 16 | use_notice: true 17 | skip_join: true 18 | channels: 19 | - "irc.freenode.org#refinerycms" 20 | webhooks: 21 | - https://webhooks.gitter.im/e/b5d48907cdc89864b874 22 | env: 23 | - DB=postgresql 24 | - DB=mysql 25 | rvm: 26 | - 2.6 27 | -------------------------------------------------------------------------------- /bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # This file loads spring without using Bundler, in order to be fast 4 | # It gets overwritten when you run the `spring binstub` command 5 | 6 | unless defined?(Spring) 7 | require "rubygems" 8 | require "bundler" 9 | 10 | if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m) 11 | ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR) 12 | ENV["GEM_HOME"] = "" 13 | Gem.paths = ENV 14 | 15 | gem "spring", match[1] 16 | require "spring/binstub" 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # This file was generated by Bundler. 4 | # 5 | # The application 'rake' is installed as part of a gem, and 6 | # this file is here to facilitate running it. 7 | # 8 | begin 9 | if Dir.exist?(File.expand_path('../../spec/dummy', __FILE__)) 10 | load File.expand_path("../spring", __FILE__) 11 | end 12 | rescue LoadError 13 | end 14 | require 'pathname' 15 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", 16 | Pathname.new(__FILE__).realpath) 17 | 18 | require 'rubygems' 19 | require 'bundler/setup' 20 | 21 | load Gem.bin_path('rake', 'rake') 22 | -------------------------------------------------------------------------------- /db/migrate/20120129230839_translate_source.rb: -------------------------------------------------------------------------------- 1 | # This migration comes from refinery_news (originally 8) 2 | class TranslateSource < ActiveRecord::Migration[4.2] 3 | 4 | def up 5 | unless Refinery::News::Item::Translation.column_names.map(&:to_sym).include?(:source) 6 | add_column Refinery::News::Item::Translation.table_name, :source, :string 7 | end 8 | end 9 | 10 | def down 11 | if Refinery::News::Item::Translation.column_names.map(&:to_sym).include?(:source) 12 | remove_column Refinery::News::Item::Translation.table_name, :source 13 | end 14 | end 15 | 16 | end 17 | -------------------------------------------------------------------------------- /config/routes.rb: -------------------------------------------------------------------------------- 1 | Refinery::Core::Engine.routes.draw do 2 | namespace :news do 3 | root :to => "items#index" 4 | get 'archive/:year(/:month)', :to => 'items#archive', :as => 'items_archive', :constraints => { :year => /\d{4}/, :month => /\d{1,2}/ } 5 | resources :items, :only => [:show, :index], :path => '' 6 | end 7 | 8 | namespace :news, :path => '' do 9 | namespace :admin, :path => Refinery::Core.backend_route do 10 | scope :path => 'news' do 11 | root :to => "items#index" 12 | resources :items, :except => :show 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/generators/refinery/news_generator.rb: -------------------------------------------------------------------------------- 1 | module Refinery 2 | class NewsGenerator < Rails::Generators::Base 3 | def rake_db 4 | rake("refinery_news:install:migrations") 5 | rake("refinery_settings:install:migrations") 6 | end 7 | 8 | def append_load_seed_data 9 | create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb')) 10 | append_file 'db/seeds.rb', :verbose => true do 11 | <<-EOH 12 | 13 | # Added by Refinery CMS News engine 14 | Refinery::News::Engine.load_seed 15 | EOH 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /bin/rspec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # 3 | # This file was generated by Bundler. 4 | # 5 | # The application 'rspec' is installed as part of a gem, and 6 | # this file is here to facilitate running it. 7 | # 8 | 9 | begin 10 | if Dir.exist?(File.expand_path('../../spec/dummy', __FILE__)) 11 | load File.expand_path("../spring", __FILE__) 12 | end 13 | rescue LoadError 14 | end 15 | require 'pathname' 16 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile", 17 | Pathname.new(__FILE__).realpath) 18 | 19 | require 'rubygems' 20 | require 'bundler/setup' 21 | 22 | load Gem.bin_path('rspec-core', 'rspec') 23 | -------------------------------------------------------------------------------- /db/migrate/20110817203701_create_news_items.rb: -------------------------------------------------------------------------------- 1 | class CreateNewsItems < ActiveRecord::Migration[4.2] 2 | 3 | def up 4 | create_table ::Refinery::News::Item.table_name do |t| 5 | t.string :title 6 | t.text :body 7 | t.datetime :publish_date 8 | 9 | t.timestamps 10 | end 11 | 12 | add_index ::Refinery::News::Item.table_name, :id 13 | end 14 | 15 | def down 16 | ::Refinery::UserPlugin.destroy_all :name => "refinerycms_news" 17 | 18 | ::Refinery::Page.delete_all :link_url => "/news" 19 | 20 | drop_table ::Refinery::News::Item.table_name 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /db/migrate/20110817203703_translate_news_items.rb: -------------------------------------------------------------------------------- 1 | class TranslateNewsItems < ActiveRecord::Migration[4.2] 2 | 3 | def up 4 | ::Refinery::News::Item.reset_column_information 5 | unless defined?(::Refinery::News::Item::Translation) && ::Refinery::News::Item::Translation.table_exists? 6 | ::Refinery::News::Item.create_translation_table!({ 7 | :title => :string, 8 | :body => :text, 9 | }, { 10 | :migrate_data => true 11 | }) 12 | end 13 | end 14 | 15 | def down 16 | ::Refinery::News::Item.reset_column_information 17 | 18 | ::Refinery::News::Item.drop_translation_table! 19 | end 20 | 21 | end 22 | -------------------------------------------------------------------------------- /lib/refinery/news/engine.rb: -------------------------------------------------------------------------------- 1 | module Refinery 2 | module News 3 | class Engine < Rails::Engine 4 | include Refinery::Engine 5 | 6 | isolate_namespace Refinery::News 7 | 8 | initializer "init plugin" do 9 | Refinery::Plugin.register do |plugin| 10 | plugin.pathname = root 11 | plugin.name = "refinerycms_news" 12 | plugin.menu_match = /refinery\/news(\/items)?$/ 13 | plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.news_admin_items_path } 14 | end 15 | end 16 | 17 | config.after_initialize do 18 | Refinery.register_engine(Refinery::News) 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/views/refinery/news/items/show.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :body_content_title, @item.title %> 2 | <% content_for :body do %> 3 |
4 |

5 | <%= t('.published') %> <%= l(@item.publish_date, :format => :long) %> 6 |

7 | <% if @item.source.present? %> 8 |

9 | <%= t('.source') %> <%= @item.source %> 10 |

11 | <% end %> 12 | <%= @item.body.html_safe %> 13 |

14 | <%= link_to t('.back_to_index'), refinery.news_items_path %> 15 |

16 |
17 | <% end %> 18 | <% content_for :side_body, render(:partial => 'recent_posts') %> 19 | 20 | <%= render "/refinery/content_page" %> 21 | -------------------------------------------------------------------------------- /db/seeds.rb: -------------------------------------------------------------------------------- 1 | if defined?(::Refinery::User) 2 | ::Refinery::User.all.each do |user| 3 | if user.plugins.where(:name => 'refinerycms_news').blank? 4 | user.plugins.create(:name => 'refinerycms_news') 5 | end 6 | end 7 | end 8 | 9 | if defined?(::Refinery::Page) 10 | unless ::Refinery::Page.where(:menu_match => "^/news.*$").any? 11 | page = ::Refinery::Page.create( 12 | :title => "News", 13 | :link_url => "/news", 14 | :deletable => false, 15 | :menu_match => "^/news.*$" 16 | ) 17 | 18 | ::Refinery::Pages.default_parts.each do |default_page_part| 19 | page.parts.create(title: default_page_part[:title], slug: default_page_part[:slug], body: nil) 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /app/views/refinery/news/items/archive.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :title, "#{t('.news_item_archive_for', :date => l(@archive_date, :format => archive_date_format(@archive_for_month)))}" %> 2 | 3 | <% content_for :body do %> 4 |

<%= t('.news_item_archive_for', :date => l(@archive_date, :format => archive_date_format(@archive_for_month))) %>

5 | <% if @items.any? %> 6 |
7 | <%= render :partial => "/refinery/news/shared/item", :collection => @items %> 8 |
9 | <% else %> 10 |

<%= t('.no_news_item_articles_posted', :date => l(@archive_date, :format => '%B %Y')) %>

11 | <% end %> 12 | <% end %> 13 | 14 | <%= render '/refinery/news/shared/body_content_right' %> 15 | 16 | <%= render "/refinery/content_page" %> 17 | <% content_for :stylesheets, stylesheet_link_tag('refinery/news/frontend') %> 18 | -------------------------------------------------------------------------------- /db/migrate/20110817203706_remove_image_id_and_external_url_from_news.rb: -------------------------------------------------------------------------------- 1 | class RemoveImageIdAndExternalUrlFromNews < ActiveRecord::Migration[4.2] 2 | def up 3 | if ::Refinery::News::Item.column_names.map(&:to_sym).include?(:external_url) 4 | remove_column ::Refinery::News::Item.table_name, :external_url 5 | end 6 | if ::Refinery::News::Item.column_names.map(&:to_sym).include?(:image_id) 7 | remove_column ::Refinery::News::Item.table_name, :image_id 8 | end 9 | end 10 | 11 | def down 12 | unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:external_url) 13 | add_column ::Refinery::News::Item.table_name, :external_url, :string 14 | end 15 | unless ::Refinery::News::Item.column_names.map(&:to_sym).include?(:image_id) 16 | add_column ::Refinery::News::Item.table_name, :image_id, :integer 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | # Configure Rails Environment 4 | ENV["RAILS_ENV"] ||= 'test' 5 | 6 | require File.expand_path("../dummy/config/environment", __FILE__) 7 | 8 | require 'rspec/rails' 9 | require 'capybara/rspec' 10 | 11 | Rails.backtrace_cleaner.remove_silencers! 12 | 13 | RSpec.configure do |config| 14 | config.mock_with :rspec 15 | config.filter_run :focus => true 16 | config.run_all_when_everything_filtered = true 17 | end 18 | 19 | # set javascript driver for capybara 20 | Capybara.javascript_driver = :selenium 21 | 22 | # Requires supporting files with custom matchers and macros, etc, 23 | # in ./support/ and its subdirectories including factories. 24 | ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p| 25 | Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s] 26 | }.flatten.sort.each do |support_file| 27 | require support_file 28 | end 29 | -------------------------------------------------------------------------------- /app/views/refinery/news/shared/_item.html.erb: -------------------------------------------------------------------------------- 1 |
2 |
3 |

<%= link_to item.title, refinery.news_item_path(item) %>

4 |
5 | 8 |
9 |
10 |
11 | <% if news_item_teaser_enabled? %> 12 | <%= news_item_teaser(item) %> 13 | <% else %> 14 | <%= item.body.html_safe %> 15 | <% end %> 16 |
17 | 22 |
23 | -------------------------------------------------------------------------------- /app/views/refinery/news/admin/items/index.html.erb: -------------------------------------------------------------------------------- 1 |
2 | 10 |
11 |
12 | <% if searching? %> 13 |

<%= t('refinery.admin.search.results_for', :query => params[:search]) %>

14 | <% end %> 15 | <% if @items.any? %> 16 | <%= will_paginate @items %> 17 | 20 | <%= will_paginate @items %> 21 | <% else %> 22 |

23 | <% unless searching? %> 24 | <%= t('.no_items_yet') %> 25 | <% else %> 26 | <%= t('refinery.admin.search.no_results') %> 27 | <% end %> 28 |

29 | <% end %> 30 |
31 | -------------------------------------------------------------------------------- /refinerycms-news.gemspec: -------------------------------------------------------------------------------- 1 | # Encoding: UTF-8 2 | require 'date' 3 | 4 | Gem::Specification.new do |s| 5 | s.name = %q{refinerycms-news} 6 | s.version = %q{4.0.0} 7 | s.description = %q{A really straightforward open source Ruby on Rails news engine designed for integration with Refinery CMS.} 8 | s.summary = %q{Ruby on Rails news engine for Refinery CMS.} 9 | s.email = %q{info@refinerycms.com} 10 | s.homepage = %q{http://refinerycms.com} 11 | s.authors = ["Philip Arndt", "Uģis Ozols"] 12 | s.require_paths = %w(lib) 13 | 14 | s.files = `git ls-files`.split("\n") 15 | s.test_files = `git ls-files -- spec/*`.split("\n") 16 | 17 | s.add_dependency 'refinerycms-core', '~> 4.0' 18 | s.add_dependency 'refinerycms-settings', '~> 4.0' 19 | s.add_dependency 'friendly_id', '~> 5.2' 20 | s.add_dependency 'friendly_id-mobility', '~> 0.5' 21 | 22 | # Development dependencies 23 | s.add_development_dependency 'refinerycms-testing', '~> 4.0' 24 | end 25 | -------------------------------------------------------------------------------- /app/views/refinery/news/items/index.rss.builder: -------------------------------------------------------------------------------- 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 => refinery.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].to_s.gsub(/<\/?[^>]*>/, "") # .to_s protects from nil errors 13 | xml.link refinery.news_items_url(:format => 'rss') 14 | 15 | # News items. 16 | @items.each do |news_item| 17 | xml.item do 18 | xml.title news_item.title 19 | xml.link refinery.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 refinery.news_item_url(news_item) 23 | end 24 | end 25 | end 26 | end -------------------------------------------------------------------------------- /config/locales/ru.yml: -------------------------------------------------------------------------------- 1 | ru: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: "Новости" 6 | news: 7 | admin: 8 | items: 9 | item: 10 | view_live_html: "Просмотреть новость
(будет открыто в новом окне)" 11 | edit: "Редактировать новость" 12 | delete: "Удалить новость" 13 | published: Опубликовано 14 | index: 15 | create: "Создать новость" 16 | item: "Новости" 17 | no_items_yet: 'Новостей пока нет.' 18 | items: 19 | show: 20 | back_to_index: "Вернуться к новостям" 21 | published: "Опубликована" 22 | recent_posts: 23 | recent_posts: "Последние публикации" 24 | index: 25 | published: "Опубликовано" 26 | read_more: "Читать далее" 27 | activerecord: 28 | attributes: 29 | 'refinery/news/item': 30 | title: "Заголовок" 31 | body: "Публикация" 32 | publish_date: "Дата публикации" 33 | models: 34 | 'refinery/news/item': "Новость" 35 | -------------------------------------------------------------------------------- /config/locales/zh-TW.yml: -------------------------------------------------------------------------------- 1 | zh-TW: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: 新聞 6 | description: 提供簡單的新聞發佈功能 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "查看此新聞
(在新視窗打開)" 12 | edit: "編輯此新聞" 13 | delete: "永遠删除此新聞" 14 | published: 已發佈 15 | index: 16 | create: "新增新聞" 17 | item: 新聞 18 | no_items_yet: '目前沒有新聞. 點選 "新增新聞" 來新增你的第一條新聞 .' 19 | shared: 20 | items: 21 | read_more: 閱讀更多 22 | created_at: '%{when}發表' 23 | archives: 存檔 24 | items: 25 | show: 26 | back_to_index: "回到新聞清單" 27 | published: 已發佈 28 | recent_posts: 29 | recent_posts: 近期發佈新聞 30 | index: 31 | published: 已發佈 32 | read_more: 更多 33 | no_items_yet: 目前沒有新聞. 34 | activerecord: 35 | attributes: 36 | 'refinery/news/item': 37 | title: 標題 38 | body: 內文 39 | publish_date: 發佈時間 40 | expiration_date: 失效時間 41 | models: 42 | 'refinery/news/item': 新聞條目 43 | -------------------------------------------------------------------------------- /config/locales/es-MX.yml: -------------------------------------------------------------------------------- 1 | es-MX: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Noticias 6 | news: 7 | admin: 8 | items: 9 | item: 10 | view_live_html: "View this news item live
(opens in a new window)" 11 | edit: "Modificar esta noticia" 12 | delete: "Eliminar esta noticia" 13 | index: 14 | create: "Crear una noticia" 15 | item: Noticias 16 | no_items_yet: 'Aun no hay noticias. Haga click en "Crear una noticia" para agregar la primera noticia.' 17 | items: 18 | show: 19 | back_to_index: "Regresar a noticias" 20 | published: Publicada 21 | recent_posts: 22 | recent_posts: Publicaciones recientes 23 | index: 24 | published: Publicada 25 | read_more: Leer mas 26 | no_items_yet: "Lo sentimos, aun no ha publicado noticias." 27 | activerecord: 28 | attributes: 29 | 'refinery/news/item': 30 | title: Título 31 | body: Contenido 32 | publish_date: Fecha de publicación 33 | models: 34 | 'refinery/news/item': Noticia 35 | -------------------------------------------------------------------------------- /config/locales/zh-CN.yml: -------------------------------------------------------------------------------- 1 | zh-CN: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: 新闻 6 | description: 提供一个简单的新闻分类 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "查看这条新闻
(在新窗口打开)" 12 | edit: "编辑这条新闻" 13 | delete: "永远删除这条新闻" 14 | published: 已发布 15 | index: 16 | create: "添加一条新闻" 17 | item: 新闻 18 | no_items_yet: '目前没有新闻. 点击 "添加新闻" 来添加你的第一条新闻.' 19 | shared: 20 | items: 21 | read_more: 阅读更多 22 | created_at: '%{when}发表' 23 | archives: 存档 24 | items: 25 | show: 26 | back_to_index: "返回所有新闻" 27 | published: 已发布 28 | source: 来源 29 | recent_posts: 30 | recent_posts: 最近新闻 31 | index: 32 | published: 已发布 33 | read_more: 更多 34 | no_items_yet: 目前没有新闻。 35 | activerecord: 36 | attributes: 37 | 'refinery/news/item': 38 | title: 标题 39 | body: 正文 40 | publish_date: 发布时间 41 | expiration_date: 过期时间 42 | models: 43 | 'refinery/news/item': 新闻条目 44 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2005-2011 [Resolve Digital Ltd.](http://www.resolvedigital.co.nz) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /app/views/refinery/news/items/index.html.erb: -------------------------------------------------------------------------------- 1 | <% content_for :body do %> 2 | <%=raw @page.content_for(Refinery::Pages.default_parts.first[:slug].to_sym) unless params[:page] %> 3 | 4 | <% if @items.any? %> 5 | <% @items.each do |item| %> 6 |
7 |

<%= link_to item.title, refinery.news_item_path(item) %>

8 |

9 | <%= t('.published') %> <%= l(item.publish_date, :format => :long) %> 10 |

11 | <%= truncate item.body, :length => 200, 12 | :omission => " ... #{link_to t('.read_more'), refinery.news_item_path(item)}", 13 | :preserve_html_tags => true %> 14 |
15 | <% end %> 16 | 17 | <%= will_paginate @items %> 18 | <% else %> 19 |

<%= t('.no_items_yet') %>

20 | <% end %> 21 | <% end -%> 22 | 23 | <% content_for :body_content_right_prepend do -%> 24 | <%= raw @page.content_for(::Refinery::Pages.default_parts.second[:slug].to_sym) %> 25 | <% end if ::Refinery::Pages.default_parts.many? -%> 26 | <%= render '/refinery/news/shared/body_content_right' %> 27 | 28 | <%= render "/refinery/content_page" %> 29 | -------------------------------------------------------------------------------- /config/locales/sl.yml: -------------------------------------------------------------------------------- 1 | sl: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Novice 6 | description: Upravljanje z novicami v obliki blog-a 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Poglej si to novico v živo
(odpre se v novem oknu)" 12 | edit: "Uredi novico" 13 | delete: "Odstrani novico" 14 | published: Objavljeno 15 | index: 16 | create: "Ustvari novico" 17 | item: Novica 18 | no_items_yet: 'Trenutno še ni vpisane nobene novice. Ustvarite prvo novico s klikom na "Ustvari novico".' 19 | items: 20 | show: 21 | back_to_index: "Nazaj na seznam novic" 22 | published: Objavljeno 23 | recent_posts: 24 | recent_posts: Zadnji vnosi 25 | index: 26 | published: Objavljeno 27 | read_more: Preberi več 28 | no_items_yet: Trenutno še ni vpisane nobene novice. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Naslov 33 | body: Opis 34 | publish_date: Datum objave 35 | models: 36 | 'refinery/news/item': Novice 37 | -------------------------------------------------------------------------------- /spec/helpers/refinery/news/items_helper_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | module Refinery 4 | module News 5 | describe ItemsHelper, :type => :helper do 6 | describe '#news_item_archive_links' do 7 | before do 8 | 2.times { FactoryBot.create(:news_item, :publish_date => Time.utc(2012, 05)) } 9 | 3.times { FactoryBot.create(:news_item, :publish_date => Time.utc(2012, 04)) } 10 | end 11 | 12 | it 'returns list of links to archives' do 13 | expected = '' 14 | expect(helper.news_item_archive_links).to eq(expected) 15 | end 16 | end 17 | 18 | describe "#archive_date_format" do 19 | context "when date_for_month is true" do 20 | it "returns month and year" do 21 | expect(helper.archive_date_format(true)).to eq("%B %Y") 22 | end 23 | end 24 | 25 | context "when date_for_month is nil" do 26 | it "returns year" do 27 | expect(helper.archive_date_format(nil)).to eq("%Y") 28 | end 29 | end 30 | end 31 | end 32 | end 33 | end 34 | 35 | -------------------------------------------------------------------------------- /config/locales/cs.yml: -------------------------------------------------------------------------------- 1 | cs: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Novinky 6 | description: Poskytuje jednoduchou správu novinek 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Zobrazit novinku v novém okně" 12 | edit: "Editovať novinku" 13 | delete: "Smazat novinku" 14 | published: Zveřejněna 15 | index: 16 | create: "Přidat novinku" 17 | item: Novinka 18 | no_items_yet: 'Momentálně nejsou žádné novinky. Klikni na "Přidat novinku" pro vytvoření první.' 19 | items: 20 | show: 21 | back_to_index: "Návrat na seznam novinek" 22 | published: Zveřejněné 23 | recent_posts: 24 | recent_posts: Poslední příspěvky 25 | index: 26 | published: Zveřejněné 27 | read_more: Číst dále 28 | no_items_yet: Neexistují žádné záznamy novinek. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Název 33 | body: Obsah 34 | publish_date: Datum zveřejnění 35 | expiration_date: Datum vypršení platnosti 36 | models: 37 | 'refinery/news/item': Novinka 38 | -------------------------------------------------------------------------------- /spec/features/visit_news_items_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe "visit news items", :type => :feature do 4 | before do 5 | FactoryBot.create(:page, :link_url => "/") 6 | FactoryBot.create(:page, :link_url => "/news", :title => "News") 7 | FactoryBot.create(:news_item, :title => "unpublished", :publish_date => 1.day.from_now) 8 | @published_news_item = FactoryBot.create(:news_item, :title => "published", :source => "http://refinerycms.com", :publish_date => 1.hour.ago) 9 | end 10 | 11 | it "shows news link in menu" do 12 | visit "/" 13 | 14 | within "#menu" do 15 | expect(page).to have_content("News") 16 | expect(page).to have_selector("a[href='/news']") 17 | end 18 | end 19 | 20 | it "shows news item" do 21 | visit refinery.news_items_path 22 | 23 | expect(page).to have_content("published") 24 | expect(page).to have_selector("a[href='/news/published']") 25 | 26 | expect(page).to have_no_content("unpublished") 27 | expect(page).to have_no_selector("a[href='/news/unpublished']") 28 | end 29 | 30 | it "has a source on the news item" do 31 | visit refinery.news_item_path(@published_news_item) 32 | 33 | expect(page).to have_content("Source http://refinerycms.com") 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /config/locales/nb.yml: -------------------------------------------------------------------------------- 1 | nb: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Nyheter 6 | description: Legger til en seksjon for nyheter 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Se hvordan nyheten ser ut for dine besøkende akkurat nå
(åpnes i et nytt vindu)" 12 | edit: "Rediger denne nyheten" 13 | delete: "Fjern denne nyheten permanent" 14 | published: Publisert 15 | index: 16 | create: "Legg til Nyhet" 17 | item: Nyhet 18 | no_items_yet: 'Det er ikke lagt til noen nyheter enda. Klikk "Legg til Nyhet" for å legge inn din første nyhet.' 19 | items: 20 | show: 21 | back_to_index: "Tilbake til nyhetsoversikt" 22 | published: Publisert 23 | recent_posts: 24 | recent_posts: Nylige Poster 25 | index: 26 | published: Publisert 27 | read_more: Les mer 28 | no_items_yet: Det er ingen nyheter enda. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Tittel 33 | body: Tekst 34 | publish_date: Publiseringsdato 35 | models: 36 | 'refinery/news/item': Nyhet 37 | -------------------------------------------------------------------------------- /config/locales/it.yml: -------------------------------------------------------------------------------- 1 | it: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Notizie 6 | description: Fornisce una sezione notizie in stile blog 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Visualzza questa notizia live
(si apre in una nuova finestra)" 12 | edit: "Modifica questa notizia" 13 | delete: "Rimuovi questa notizia per sempre" 14 | published: Pubblicata 15 | index: 16 | create: "Crea Notizia" 17 | item: Notizia 18 | no_items_yet: 'Non ci sono ancora notizie. Fare clic su "Crea Notizia" per aggiungere la prima notizia.' 19 | items: 20 | show: 21 | back_to_index: "Torna a tutte le notizie" 22 | published: Pubblicata 23 | recent_posts: 24 | recent_posts: Messaggi Recenti 25 | index: 26 | published: Pubblicata 27 | read_more: Per saperne di più 28 | no_items_yet: Non ci sono ancora notizie. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Titolo 33 | body: Corpo 34 | publish_date: Data di pubblicazione 35 | models: 36 | 'refinery/news/item': Notizia 37 | -------------------------------------------------------------------------------- /db/migrate/20131128000000_move_slug_to_news_item_translations.rb: -------------------------------------------------------------------------------- 1 | class MoveSlugToNewsItemTranslations < ActiveRecord::Migration[4.2] 2 | def up 3 | # Fix index problem if this is rolled back 4 | remove_index Refinery::News::Item.translation_class.table_name, :refinery_news_item_id 5 | add_index Refinery::News::Item.translation_class.table_name, :refinery_news_item_id, :name => :index_refinery_news_item_translations_fk 6 | 7 | # Add the column 8 | add_column Refinery::News::Item.translation_class.table_name, :slug, :string 9 | 10 | # Ensure the slug is translated. 11 | Refinery::News::Item.reset_column_information 12 | Refinery::News::Item.find_each do |item| 13 | item.slug = item.slug 14 | item.save 15 | end 16 | end 17 | 18 | def down 19 | # Move the slug back to the news item table 20 | Refinery::News::Item.reset_column_information 21 | Refinery::News::Item.find_each do |item| 22 | item.slug = if item.translations.many? 23 | item.translations.detect{|t| t.slug.present?}.slug 24 | else 25 | item.translations.first.slug 26 | end 27 | item.save 28 | end 29 | 30 | # Remove the column from the translations table 31 | remove_column Refinery::News::Item.translation_class.table_name, :slug 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /config/locales/es.yml: -------------------------------------------------------------------------------- 1 | es: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Noticias 6 | description: Proporciona una seccion de noticias similar a un blog 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Ver este elemento en tu web
(abre una nueva ventana)" 12 | edit: "Editar esta noticia" 13 | delete: "Borrar completamente esta noticia" 14 | published: Publicada 15 | index: 16 | create: "Crear noticia" 17 | item: Noticia 18 | no_items_yet: 'Aún no hay noticias. Haz click en "Crear noticia" para añadir la primera.' 19 | items: 20 | show: 21 | back_to_index: "Volver al listado de noticias" 22 | published: Publicada 23 | recent_posts: 24 | recent_posts: Artículos recientes 25 | index: 26 | published: Publicada 27 | read_more: Leer más 28 | no_items_yet: Aún no hay ninguna noticia. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Título 33 | body: Contenido 34 | publish_date: Fecha de publicación 35 | expiration_date: Fecha de expiración 36 | models: 37 | 'refinery/news/item': Noticia 38 | -------------------------------------------------------------------------------- /app/views/refinery/news/admin/items/_item.html.erb: -------------------------------------------------------------------------------- 1 |
  • 2 | 3 | <%= item.title %> 4 | 5 | <%= t('.published') %> <%= l(item.publish_date, :format => :short) %> 6 | 7 | <% if Refinery::I18n.frontend_locales.many? and 8 | (locales = item.translations.collect{|t| t.locale}).present? %> 9 | 10 | <% locales.each do |locale| %> 11 | <%= link_to refinery_icon_tag("flags/#{locale}", :size => '16x11'), refinery.edit_news_admin_item_path(item, :switch_locale => locale), 12 | :class => "locale" %> 13 | <% end %> 14 | 15 | <% end %> 16 | 17 | 18 | <%= action_icon 'go', refinery.news_item_path(item), t('.view_live_html'), target: "_blank" %> 19 | <%= action_icon 'edit', refinery.edit_news_admin_item_path(item), t('.edit') %> 20 | <%= action_icon 'delete', refinery.news_admin_item_path(item), t('.delete'), 21 | class: "cancel confirm-delete", 22 | method: :delete, 23 | data: { 24 | confirm: t('refinery.admin.delete.message', :title => item.title) 25 | } %> 26 | 27 |
  • 28 | -------------------------------------------------------------------------------- /config/locales/bg.yml: -------------------------------------------------------------------------------- 1 | bg: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Новини 6 | description: Осигурява опростена секция за новини 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Преглед на тази новина
    (ще се отвори се в нов прозорец)" 12 | edit: "Редакция на тази новина" 13 | delete: "Премахване на тази новина завинаги" 14 | published: Публикувано на 15 | index: 16 | create: "Добавяне на новина" 17 | item: Новини 18 | no_items_yet: 'Все още няма новини. Натиснете "Добавяне на новина", за да въведете новина.' 19 | items: 20 | show: 21 | back_to_index: "Обратно към всички новини" 22 | published: Публикувано на 23 | recent_posts: 24 | recent_posts: Последни публикации 25 | index: 26 | published: Публикувано на 27 | read_more: Цялата новина 28 | no_items_yet: Все още няма публикувани новини. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Заглавие 33 | body: Съдържание 34 | publish_date: Дата на публикуване 35 | expiration_date: Крайна дата 36 | models: 37 | 'refinery/news/item': Новина 38 | -------------------------------------------------------------------------------- /config/locales/de.yml: -------------------------------------------------------------------------------- 1 | de: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: News 6 | description: Bietet einen einfachen Newsbereich an 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Diesen News-Eintrag live anschauen
    (Öffnet sich in eine neuen Fenster)" 12 | edit: "Diesen News-Eintrag editieren" 13 | delete: "Diesen News-Eintrag endgültig löschen" 14 | published: Veröffentlicht 15 | index: 16 | create: "News-Eintrag hinzufügen" 17 | item: News 18 | no_items_yet: 'Es sind keine News-Einträge vorhanden. Klick auf "News-Eintrag hinzufügen" um den ersten Eintrag zu machen.' 19 | items: 20 | show: 21 | back_to_index: "Zurück zur Übersicht" 22 | published: Veröffentlicht 23 | recent_posts: 24 | recent_posts: Aktuelle Einträge 25 | index: 26 | published: Veröffentlicht 27 | read_more: Weiterlesen 28 | no_items_yet: Zur Zeit gibt es keine News. 29 | activerecord: 30 | attributes: 31 | 'refinery/news/item': 32 | title: Titel 33 | body: Inhalt 34 | publish_date: Veröffentlichungsdatum 35 | models: 36 | 'refinery/news/item': News-Eintrag 37 | -------------------------------------------------------------------------------- /config/locales/lv.yml: -------------------------------------------------------------------------------- 1 | lv: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Jaunumi 6 | description: Piedāvā blogveidīgu jaunumu sadaļu 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: Apskatīt šo jaunumu
    Atvērsies jaunā logā 12 | delete: Dzēst šo jaunumu 13 | edit: Labot šo jaunumu 14 | published: Ievietots 15 | index: 16 | create: Izveidot Jaunumu 17 | item: Jaunumi 18 | no_items_yet: Vēl nav neviena jaunuma. Spied "Izveidot Jaunumu", lai izveidotu pirmo jaunumu. 19 | items: 20 | show: 21 | back_to_index: Atgriezties pie visiem jaunumiem 22 | published: Ievietots 23 | source: Avots 24 | recent_posts: 25 | recent_posts: Pēdējie jaunumi 26 | index: 27 | published: Ievietots 28 | read_more: Lasīt vairāk 29 | no_items_yet: Vēl nav neviena jaunuma. 30 | source: Avots 31 | activerecord: 32 | attributes: 33 | 'refinery/news/item': 34 | title: Virsraksts 35 | body: Saturs 36 | publish_date: Publikācijas datums 37 | expiration_date: Publikācijas beigu datums 38 | source: Avots 39 | models: 40 | 'refinery/news/item': jaunums 41 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | 5 | gem 'refinerycms', '~> 4.0.3' 6 | 7 | group :development, :test do 8 | gem 'refinerycms-testing', '~> 4.0.3' 9 | gem 'listen' 10 | end 11 | 12 | group :test do 13 | gem 'pry' 14 | gem 'launchy' 15 | gem 'selenium-webdriver' 16 | end 17 | 18 | # Add support for refinerycms-acts-as-indexed 19 | gem 'refinerycms-acts-as-indexed', ['~> 3.0', '>= 3.0.0'] 20 | 21 | # Add the default visual editor, for now. 22 | gem 'refinerycms-wymeditor', ['~> 2.2', '>= 2.2.0'] 23 | 24 | # Database Configuration 25 | unless ENV['TRAVIS'] 26 | gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby 27 | gem 'sqlite3', :platform => :ruby 28 | end 29 | 30 | if !ENV['TRAVIS'] || ENV['DB'] == 'mysql' 31 | gem 'activerecord-jdbcmysql-adapter', :platform => :jruby 32 | gem 'jdbc-mysql', '= 5.1.13', :platform => :jruby 33 | gem 'mysql2', :platform => :ruby 34 | end 35 | 36 | if !ENV['TRAVIS'] || ENV['DB'] == 'postgresql' 37 | gem 'activerecord-jdbcpostgresql-adapter', :platform => :jruby 38 | gem 'pg', :platform => :ruby 39 | end 40 | 41 | # Refinery/rails should pull in the proper versions of these 42 | group :assets do 43 | gem 'sass-rails' 44 | gem 'coffee-rails' 45 | end 46 | 47 | # Load local gems according to Refinery developer preference. 48 | if File.exist?(local_gemfile = File.expand_path('../.gemfile', __FILE__)) 49 | eval_gemfile local_gemfile 50 | end 51 | -------------------------------------------------------------------------------- /app/views/refinery/news/admin/items/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for [refinery, :news, :admin, @item] do |f| %> 2 | <%= render "/refinery/admin/error_messages", 3 | :object => @item, 4 | :include_object_name => true %> 5 | 6 | <%= render '/refinery/admin/locale_picker', :current_locale => Mobility.locale %> 7 | 8 |
    9 | <%= f.label :title %> 10 | <%= f.text_field :title, :class => "larger widest" %> 11 |
    12 | 13 |
    14 | <%= f.label :publish_date %> 15 | <%= f.datetime_select :publish_date %> 16 |
    17 | 18 |
    19 | <%= f.label :expiration_date %> 20 | <%= f.datetime_select :expiration_date, :start_year => Time.now.year, 21 | :include_blank => true %> 22 |
    23 | 24 |
    25 | <%= f.label :body %> 26 | <%= f.text_area :body, :rows => "20", :class => "visual_editor widest" %> 27 |
    28 | 29 |
    30 | <%= f.label :source %> 31 | <%= f.text_field :source, :class => "larger widest" %> 32 |
    33 | 34 | <%= render "/refinery/admin/form_actions", 35 | :f => f, 36 | :continue_editing => true, 37 | :delete_title => t('admin.news.items.item.delete'), 38 | :delete_confirmation => t('shared.admin.delete.message', :title => @item.title) %> 39 | 40 | <% end %> 41 | -------------------------------------------------------------------------------- /config/locales/ja.yml: -------------------------------------------------------------------------------- 1 | ja: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: 'ニュース' 6 | description: '簡単なニュースを投稿出来るプラグイン' 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: 'このニュースを見る
    (新規ウインドウで開かれます)' 12 | edit: 'このニュースを編集' 13 | delete: 'このニュースを削除' 14 | published: '公開日時' 15 | index: 16 | create: '新規ニュースを追加' 17 | item: 'ニュース' 18 | no_items_yet: 'まだニュースが何もありません。「新規ニュースを追加」をクリックしてニュースを追加して下さい。' 19 | shared: 20 | items: 21 | read_more: '続きを読む' 22 | created_at: '作成日時:%{when}' 23 | archives: 記録 24 | items: 25 | show: 26 | back_to_index: 'ニュース一覧に戻る' 27 | published: '公開日時' 28 | source: '参照元' 29 | recent_posts: 30 | recent_posts: '最近のニュース' 31 | index: 32 | published: '公開日時' 33 | read_more: '続きを読む' 34 | no_items_yet: 'まだニュースが何もありません。' 35 | source: '参照元' 36 | archive: 37 | news_item_archive_for: '記録日時 %{date}' 38 | no_news_item_articles_posted: '%{date}からニュースが追加されていません。' 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: '題名' 43 | body: '本文' 44 | publish_date: '公開日時' 45 | expiration_date: '公開終了日時' 46 | source: '参照元' 47 | models: 48 | 'refinery/news/item': 'ニュース' -------------------------------------------------------------------------------- /app/controllers/refinery/news/items_controller.rb: -------------------------------------------------------------------------------- 1 | module Refinery 2 | module News 3 | class ItemsController < ::ApplicationController 4 | before_action :find_page 5 | before_action :find_published_news_items, :only => [:index] 6 | before_action :find_news_item, :find_latest_news_items, :only => [:show] 7 | 8 | def index 9 | # render 'index' 10 | end 11 | 12 | def show 13 | # render 'show' 14 | end 15 | 16 | def archive 17 | if params[:month].present? 18 | @archive_for_month = true 19 | @archive_date = Time.parse("#{params[:month]}/#{params[:year]}") 20 | @items = Item.archived.translated.by_archive(@archive_date).page(params[:page]) 21 | else 22 | @archive_date = Time.parse("01/#{params[:year]}") 23 | @items = Item.archived.translated.by_year(@archive_date).page(params[:page]) 24 | end 25 | end 26 | 27 | protected 28 | 29 | def find_latest_news_items 30 | @items = Item.latest.translated 31 | end 32 | 33 | def find_published_news_items 34 | @items = Item.published.translated.page(params[:page]) 35 | end 36 | 37 | def find_news_item 38 | @item = Item.published.translated.friendly.find(params[:id]) 39 | end 40 | 41 | def find_page 42 | @page = ::Refinery::Page.find_by_link_url("/news") if defined?(::Refinery::Page) 43 | end 44 | 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /config/locales/da.yml: -------------------------------------------------------------------------------- 1 | da: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Nyheder 6 | description: Giver en simpel nyhedssektion 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Vis nyheden live
    (åbner i et nyt vindue)" 12 | edit: "Redigér nyheden" 13 | delete: "Slet nyheden permanent" 14 | published: Offentliggjort 15 | index: 16 | create: "Tilføj nyhed" 17 | item: Nyheder 18 | no_items_yet: 'Der er ingen nyheder endnu. Klik "Tilføj nyhed" for at oprette den første.' 19 | shared: 20 | items: 21 | created_at: 'Oprettet %{when}' 22 | archives: Arkiver 23 | items: 24 | show: 25 | back_to_index: "Tilbage til nyheder" 26 | published: Offentliggjort 27 | source: Kilde 28 | recent_posts: 29 | recent_posts: "Seneste indlæg" 30 | index: 31 | published: Offentliggjort 32 | read_more: "Læs mere" 33 | no_items_yet: "Der er ingen nyheder endnu." 34 | source: Kilde 35 | archive: 36 | news_item_archive_for: 'Arkiv for %{date}' 37 | no_news_item_articles_posted: 'Der er ingen nyhedsartikler oprettet for %{date}.' 38 | activerecord: 39 | attributes: 40 | 'refinery/news/item': 41 | title: Titel 42 | body: Krop 43 | publish_date: Offentliggørelsesdato 44 | expiration_date: Udløbsdato 45 | source: Kilde 46 | models: 47 | 'refinery/news/item': Nyhed 48 | -------------------------------------------------------------------------------- /config/locales/sk.yml: -------------------------------------------------------------------------------- 1 | sk: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Novinky 6 | description: Poskytuje jednoduchú správu noviniek 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Zobraziť novinku v novom okne" 12 | edit: "Editovať novinku" 13 | delete: "Zmazať novinku" 14 | published: Uverejnená 15 | index: 16 | create: "Pridať novinku" 17 | item: Novinka 18 | no_items_yet: 'Momentálne nie sú žiadne novinky. Klikni na "Pridať novinku" pre vytvorenie prvej.' 19 | shared: 20 | items: 21 | read_more: Čítaj viac 22 | created_at: 'Vytvorené %{when}' 23 | archives: Archív 24 | items: 25 | show: 26 | back_to_index: "Návrat na zoznam noviniek" 27 | published: Zverejnené 28 | source: "Zdroj:" 29 | recent_posts: 30 | recent_posts: Posledné príspevky 31 | index: 32 | published: Zverejnené 33 | read_more: Čítať viac 34 | no_items_yet: Neexistujú žiadne záznamy noviniek. 35 | source: 'Zdroj:' 36 | archive: 37 | news_item_archive_for: 'Archív pre %{date}' 38 | no_news_item_articles_posted: 'Nenašli sa novinky vyhovujúce dátumu %{date}.' 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: Názov 43 | body: Obsah 44 | publish_date: Dátum zverejnenia 45 | expiration_date: Dátum expirácie 46 | source: Zdroj 47 | models: 48 | 'refinery/news/item': Novinka 49 | -------------------------------------------------------------------------------- /config/locales/en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: News 6 | description: Provides a simple news section 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "View this news item live
    (opens in a new window)" 12 | edit: "Edit this news item" 13 | delete: "Remove this news item forever" 14 | published: Published 15 | index: 16 | create: "Add News Item" 17 | item: News 18 | no_items_yet: 'There are no news items yet. Click "Add News Item" to add your first news item.' 19 | shared: 20 | items: 21 | read_more: Read more 22 | created_at: 'Created at %{when}' 23 | archives: Archives 24 | items: 25 | show: 26 | back_to_index: "Back to all news" 27 | published: Published 28 | source: Source 29 | recent_posts: 30 | recent_posts: Recent Posts 31 | index: 32 | published: Published 33 | read_more: Read more 34 | no_items_yet: There are no news item entries yet. 35 | source: Source 36 | archive: 37 | news_item_archive_for: 'Archive for %{date}' 38 | no_news_item_articles_posted: 'There are no news articles posted for %{date}. Stay tuned.' 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: Title 43 | body: Body 44 | publish_date: Publish date 45 | expiration_date: Expiration date 46 | source: Source 47 | models: 48 | 'refinery/news/item': News Item 49 | -------------------------------------------------------------------------------- /config/locales/pl.yml: -------------------------------------------------------------------------------- 1 | pl: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Aktualności 6 | description: Aktualności i wydarzenia 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Zobacz podgląd
    (otwiera nowe okno)" 12 | edit: "Edytuj wiadomość" 13 | delete: "Skasuj wiadomość na zawsze" 14 | published: Opublikowano 15 | index: 16 | create: "Dodaj nową aktualizację" 17 | item: Aktualizacja 18 | no_items_yet: 'W bazie nie ma żadnych rezultatów, dodaj nową aktualizację.' 19 | shared: 20 | items: 21 | read_more: Czytaj więcej 22 | created_at: 'Utworzono %{when}' 23 | archives: Archiwum 24 | items: 25 | show: 26 | back_to_index: "Powrót do wszystkich aktualności" 27 | published: Opublikowano 28 | source: Źródło 29 | recent_posts: 30 | recent_posts: Ostatnie aktualności 31 | index: 32 | published: Opublikowano 33 | read_more: Czytaj więcej 34 | no_items_yet: "Przepraszamy, brak rezultatów." 35 | source: Źródło 36 | archive: 37 | news_item_archive_for: 'Archiwum dla %{date}' 38 | no_news_item_articles_posted: 'Nie ma artykułów opublikowanych w %{date}.' 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: Tytuł 43 | body: Treść 44 | publish_date: Data opublikowania 45 | expiration_date: Data wygaśnięcia 46 | source: Źródło 47 | models: 48 | 'refinery/news/item': Aktualnośći 49 | -------------------------------------------------------------------------------- /config/locales/pt-BR.yml: -------------------------------------------------------------------------------- 1 | pt-BR: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Notícias 6 | description: Disponibiliza uma simples sessão de notícias 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Ver esta notícia no site
    (abrirá em uma nova janela)" 12 | edit: "Alterar esta notícia" 13 | delete: "Remover esta notícia para sempre" 14 | published: Publicado 15 | index: 16 | create: "Criar Notícia" 17 | item: Notícia 18 | no_items_yet: 'Não há notícias cadastradas. Clique em "Criar Notícia" para cadastrar sua primeira notícia.' 19 | shared: 20 | items: 21 | created_at: 'Criado em %{when}' 22 | archives: Arquivos 23 | items: 24 | show: 25 | back_to_index: "Voltar para todas as notícias" 26 | published: Publicado 27 | source: Fonte 28 | recent_posts: 29 | recent_posts: Notícias recentes 30 | index: 31 | published: Publicado 32 | read_more: Leia mais 33 | no_items_yet: Não há notícias cadastradas. 34 | source: Fonte 35 | archive: 36 | news_item_archive_for: 'Arquivo do dia: %{date}' 37 | no_news_item_articles_posted: 'Não existe nenhuma notícia postada em %{date}.' 38 | activerecord: 39 | attributes: 40 | 'refinery/news/item': 41 | title: Título 42 | body: Conteúdo 43 | publish_date: Data de publicação 44 | expiration_date: Data de expiração 45 | source: Fonte 46 | models: 47 | 'refinery/news/item': Notícia 48 | -------------------------------------------------------------------------------- /config/locales/uk.yml: -------------------------------------------------------------------------------- 1 | uk: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Новини 6 | description: Надає просту секцію новин 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Проглядати цю новину наживо
    (відкриється у новому вікні)" 12 | edit: "Редагувати цю новину" 13 | delete: "Видалити цю новину назавжди" 14 | published: Опубліковано 15 | index: 16 | create: "Додати новину" 17 | item: Новина 18 | no_items_yet: 'Новин ще немає. Натисніть "Додати новину" що додати свою першу новину.' 19 | shared: 20 | items: 21 | read_more: Читати повністю 22 | created_at: 'Створено %{when}' 23 | archives: Архіви 24 | items: 25 | show: 26 | back_to_index: "Назад до всіх новин" 27 | published: Опубліковано 28 | source: Джерело 29 | recent_posts: 30 | recent_posts: Останні повідомлення 31 | index: 32 | published: Опубліковано 33 | read_more: Читати повністю 34 | no_items_yet: Новин ще немає. 35 | source: Джерело 36 | archive: 37 | news_item_archive_for: 'Архів за %{date}' 38 | no_news_item_articles_posted: 'Жодної новини не опубліковано %{date}. Залишайтеся на зв’язку' 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: Назва новини 43 | body: Новина 44 | publish_date: Дата публікації 45 | expiration_date: Термін придатності 46 | source: Джерело 47 | models: 48 | 'refinery/news/item': Новина 49 | -------------------------------------------------------------------------------- /app/helpers/refinery/news/items_helper.rb: -------------------------------------------------------------------------------- 1 | module Refinery 2 | module News 3 | module ItemsHelper 4 | def news_item_archive_widget 5 | items = Refinery::News::Item.select('publish_date').all_previous 6 | return nil if items.blank? 7 | 8 | render "/refinery/news/items/widgets/news_archive", :items => items 9 | end 10 | alias_method :news_archive_list, :news_item_archive_widget 11 | 12 | def next_or_previous?(item) 13 | item.next.present? or item.prev.present? 14 | end 15 | 16 | def news_item_teaser_enabled? 17 | Refinery::News::Item.teasers_enabled? 18 | end 19 | 20 | def news_item_teaser(item) 21 | if item.respond_to?(:custom_teaser) && item.custom_teaser.present? 22 | item.custom_teaser.html_safe 23 | else 24 | truncate(item.body, { 25 | :length => Refinery::Setting.find_or_set(:news_item_teaser_length, 250), 26 | :preserve_html_tags => true 27 | }).html_safe 28 | end 29 | end 30 | 31 | def news_item_archive_links 32 | html = '' 33 | item_months = ::Refinery::News::Item.archived.group_by {|i| i.publish_date.beginning_of_month} 34 | item_months.each do |month, items| 35 | if items.present? 36 | text = "#{t("date.month_names")[month.month]} #{month.year} (#{items.count})" 37 | html += "
  • #{link_to(text, refinery.news_items_archive_path(:year => month.year, :month => month.month))}
  • " 38 | end 39 | end 40 | content_tag('ul', raw(html)) 41 | end 42 | 43 | def archive_date_format(date_for_month) 44 | date_for_month ? "%B %Y" : "%Y" 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /config/locales/fr.yml: -------------------------------------------------------------------------------- 1 | fr: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Actualités 6 | description: 'Fournit une rubrique "Actualités"' 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Visualiser cette nouvelle
    (ouvre une nouvelle fenêtre)" 12 | edit: "Modifier cette actualité" 13 | delete: "Détruire cette actualité à tout jamais" 14 | published: Publiée 15 | index: 16 | create: "Créer une actualité" 17 | item: Actualité 18 | no_items_yet: 'Aucune actualité. Cliquer sur "Créer une actualité" pour créer votre première actualité.' 19 | shared: 20 | items: 21 | read_more: Lire la suite 22 | created_at: 'Créée le %{when}' 23 | archives: Archives 24 | items: 25 | show: 26 | back_to_index: "Retour à la liste des actualités" 27 | published: Publiée le 28 | source: Source 29 | recent_posts: 30 | recent_posts: Dernières actualités 31 | index: 32 | published: Publiée le 33 | read_more: Plus 34 | no_items_yet: Aucune actualité pour le moment. 35 | source: Source 36 | archive: 37 | news_item_archive_for: 'À archiver le %{date}' 38 | no_news_item_articles_posted: "Aucune actualité en date du %{date}. Restez à l'écoute !" 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: Titre 43 | body: Texte 44 | publish_date: Date de publication 45 | expiration_date: Date d'expiration 46 | source: Source 47 | models: 48 | 'refinery/news/item': Nouvelle 49 | -------------------------------------------------------------------------------- /config/locales/nl.yml: -------------------------------------------------------------------------------- 1 | nl: 2 | refinery: 3 | plugins: 4 | refinerycms_news: 5 | title: Nieuws 6 | description: Nieuwsberichten voor de op de site. 7 | news: 8 | admin: 9 | items: 10 | item: 11 | view_live_html: "Bekijk dit bericht op de website.
    (opent in een nieuw venster.)" 12 | edit: "Bewerk dit bericht" 13 | delete: "Verwijder dit bericht permanent" 14 | published: Gepubliceerd op 15 | index: 16 | create: "Maak een nieuw nieuwsbericht" 17 | item: Nieuws 18 | no_items_yet: 'Er zijn nog geen nieuwsberichten. Klik op "Maak een nieuw niewsbericht" om het eerste bericht te maken.' 19 | shared: 20 | items: 21 | read_more: Lees meer 22 | created_at: 'Aangemaakt op %{when}' 23 | archives: Archief 24 | items: 25 | show: 26 | back_to_index: "Terug naar de andere berichten" 27 | published: Gepubliceerd op 28 | source: Bron 29 | recent_posts: 30 | recent_posts: Laatste nieuws item 31 | index: 32 | published: Gepubliceerd op 33 | read_more: Lees meer 34 | no_items_yet: "Sorry, er zijn nog geen nieuwsberichten geplaatst." 35 | source: Bron 36 | archive: 37 | news_item_archive_for: 'Archief voor %{date}' 38 | no_news_item_articles_posted: 'Er zijn nog geen nieuwsberichten voor %{date}.' 39 | activerecord: 40 | attributes: 41 | 'refinery/news/item': 42 | title: Titel 43 | body: Inhoud 44 | publish_date: Publiceer datum 45 | expiration_date: Verval datum 46 | source: Bron 47 | models: 48 | 'refinery/news/item': Nieuws Item 49 | -------------------------------------------------------------------------------- /spec/controllers/refinery/news/items_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | module Refinery 4 | module News 5 | describe ItemsController, :type => :controller do 6 | let!(:item) { FactoryBot.create(:news_item) } 7 | let(:refinery_page) { Refinery::Page.where(:link_url => "/news").first } 8 | 9 | describe "#index" do 10 | it "assigns items and page" do 11 | get :index 12 | expect(assigns(:items).first).to eq(item) 13 | expect(assigns(:page)).to eq(refinery_page) 14 | end 15 | 16 | it "renders 'index' template" do 17 | get :index 18 | expect(response).to render_template(:index) 19 | end 20 | end 21 | 22 | describe "#show" do 23 | it "assigns item and page" do 24 | get :show, params: { id: item.id } 25 | expect(assigns(:item)).to eq(item) 26 | expect(assigns(:page)).to eq(refinery_page) 27 | end 28 | 29 | it "renders 'show' template" do 30 | get :show, params: { id: item.id } 31 | expect(response).to render_template(:show) 32 | end 33 | end 34 | 35 | describe "#archive" do 36 | context "when month is present" do 37 | it "assigns archive_date and items" do 38 | allow(Refinery::News::Item).to receive_message_chain(:archived, :translated, :by_archive, :page).and_return(item) 39 | get :archive, params: { month: 05, year: 1999 } 40 | expect(assigns(:archive_date)).to eq(Time.parse("05/1999")) 41 | expect(assigns(:items)).to eq(item) 42 | expect(assigns(:archive_for_month)).to be_truthy 43 | end 44 | end 45 | 46 | context "when month isnt present" do 47 | it "assigns archive_date and items" do 48 | allow(Refinery::News::Item).to receive_message_chain(:archived, :translated, :by_year, :page).and_return(item) 49 | get :archive, params: { year: 1999 } 50 | expect(assigns(:archive_date)).to eq(Time.parse("01/1999")) 51 | expect(assigns(:items)).to eq(item) 52 | end 53 | end 54 | 55 | it "renders 'archive' template" do 56 | get :archive, params: { year: 1999 } 57 | expect(response).to render_template(:archive) 58 | end 59 | 60 | it "assigns page" do 61 | get :archive, params: { year: 1999 } 62 | expect(assigns(:page)).to eq(refinery_page) 63 | end 64 | end 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /spec/features/manage_news_items_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe "manage news items", :type => :feature do 4 | refinery_login 5 | 6 | context "when no news items" do 7 | it "invites to create one" do 8 | visit refinery.news_admin_items_path 9 | expect(page).to have_content("There are no news items yet. Click \"Add News Item\" to add your first news item.") 10 | end 11 | end 12 | 13 | describe "action links" do 14 | it "shows add news item link" do 15 | visit refinery.news_admin_items_path 16 | 17 | within "#actions" do 18 | expect(page).to have_content("Add News Item") 19 | expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/news/items/new']") 20 | end 21 | end 22 | end 23 | 24 | describe "new/create" do 25 | it "allows to create news item" do 26 | visit refinery.news_admin_items_path 27 | 28 | click_link "Add News Item" 29 | 30 | fill_in "Title", :with => "My first news item" 31 | fill_in "Body", :with => "bla bla" 32 | fill_in "Source", :with => "http://refinerycms.com" 33 | click_button "Save" 34 | 35 | expect(page).to have_content("'My first news item' was successfully added.") 36 | expect(page.body).to match(/Remove this news item forever/) 37 | expect(page.body).to match(/Edit this news item/) 38 | expect(page.body).to match(%r{/#{Refinery::Core.backend_route}/news/items/my-first-news-item/edit}) 39 | expect(page.body).to match(/View this news item live/) 40 | expect(page.body).to match(%r{/news/items/my-first-news-item}) 41 | 42 | expect(Refinery::News::Item.count).to eq(1) 43 | end 44 | end 45 | 46 | describe "edit/update" do 47 | before { FactoryBot.create(:news_item, :title => "Update me") } 48 | 49 | it "updates news item" do 50 | visit refinery.news_admin_items_path 51 | 52 | expect(page).to have_content("Update me") 53 | 54 | click_link "Edit this news item" 55 | 56 | fill_in "Title", :with => "Updated" 57 | click_button "Save" 58 | 59 | expect(page).to have_content("'Updated' was successfully updated.") 60 | end 61 | end 62 | 63 | describe "destroy" do 64 | before { FactoryBot.create(:news_item, :title => "Delete me") } 65 | 66 | it "removes news item" do 67 | visit refinery.news_admin_items_path 68 | 69 | click_link "Remove this news item forever" 70 | 71 | expect(page).to have_content("'Delete me' was successfully removed.") 72 | 73 | expect(Refinery::News::Item.count).to eq(0) 74 | end 75 | end 76 | 77 | context "duplicate news item titles" do 78 | before { FactoryBot.create(:news_item, :title => "I was here first") } 79 | 80 | it "isn't a problem" do 81 | visit refinery.new_news_admin_item_path 82 | 83 | fill_in "Title", :with => "I was here first" 84 | fill_in "Body", :with => "Doesn't matter" 85 | click_button "Save" 86 | 87 | expect(Refinery::News::Item.count).to eq(2) 88 | end 89 | end 90 | end 91 | -------------------------------------------------------------------------------- /app/models/refinery/news/item.rb: -------------------------------------------------------------------------------- 1 | require 'acts_as_indexed' 2 | require 'mobility' 3 | 4 | module Refinery 5 | module News 6 | class Item < Refinery::Core::BaseModel 7 | extend FriendlyId 8 | 9 | translates :title, :body, :slug 10 | 11 | alias_attribute :content, :body 12 | 13 | validates :title, :content, :publish_date, :presence => true 14 | 15 | validates :source, length: {maximum: 255}, allow_blank: true 16 | 17 | acts_as_indexed :fields => [:title, :body] 18 | 19 | default_scope proc { order "publish_date DESC" } 20 | 21 | friendly_id :title, :use => [:slugged, :mobility] 22 | 23 | # If title changes tell friendly_id to regenerate slug when saving record 24 | def should_generate_new_friendly_id? 25 | attribute_changed?(:title) 26 | end 27 | 28 | def not_published? # has the published date not yet arrived? 29 | publish_date > Time.now 30 | end 31 | 32 | def next 33 | self.class.next(self).first 34 | end 35 | 36 | def prev 37 | self.class.previous(self).first 38 | end 39 | 40 | class << self 41 | def by_archive(archive_date) 42 | where(:publish_date => archive_date.beginning_of_month..archive_date.end_of_month) 43 | end 44 | 45 | def by_year(archive_year) 46 | where(:publish_date => archive_year.beginning_of_year..archive_year.end_of_year) 47 | end 48 | 49 | def all_previous 50 | where(['publish_date <= ?', Time.now.beginning_of_month]) 51 | end 52 | 53 | def next(item) 54 | self.send(:with_exclusive_scope) do 55 | where("publish_date > ?", item.publish_date).order("publish_date ASC") 56 | end 57 | end 58 | 59 | def previous(item) 60 | where("publish_date < ?", item.publish_date) 61 | end 62 | 63 | def not_expired 64 | where(arel_table[:expiration_date].eq(nil).or(arel_table[:expiration_date].gt(Time.now))) 65 | end 66 | 67 | def published 68 | not_expired.where("publish_date < ?", Time.now) 69 | end 70 | 71 | def latest(limit = 10) 72 | published.limit(limit) 73 | end 74 | 75 | def live 76 | not_expired.where("publish_date <= ?", Time.now) 77 | end 78 | 79 | def archived 80 | where("publish_date <= ?", Time.now) 81 | end 82 | 83 | # rejects any page that has not been translated to the current locale. 84 | def translated 85 | includes(:translations).where( 86 | translation_class.arel_table[:locale].eq(::Mobility.locale) 87 | ).where( 88 | arel_table[:id].eq(translation_class.arel_table[:refinery_news_item_id]) 89 | ).references(:translations) 90 | end 91 | 92 | def teasers_enabled? 93 | Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news') 94 | end 95 | 96 | def teaser_enabled_toggle! 97 | currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news') 98 | Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'news') 99 | end 100 | end 101 | 102 | end 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Refinery CMS News 2 | 3 | [![Build Status](https://travis-ci.org/refinery/refinerycms-news.svg?branch=master)](https://travis-ci.org/refinery/refinerycms-news) 4 | 5 | ## About 6 | 7 | __Refinery's news engine 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 | ## Requirements 15 | 16 | [Refinery CMS](http://refinerycms.com) "core" engine version 2.0.0 or later. 17 | 18 | ### Gem Installation using Bundler (The very best way) 19 | 20 | Include the latest [gem](http://rubygems.org/gems/refinerycms-news) into your Refinery CMS application's Gemfile: 21 | 22 | ```ruby 23 | gem "refinerycms-news", '~> 2.1.0' 24 | ``` 25 | 26 | Then type the following at command line inside your Refinery CMS application's root directory: 27 | 28 | bundle install 29 | rails generate refinery:news 30 | rake db:migrate 31 | rake db:seed 32 | 33 | ## How to display a news feed on the homepage: 34 | 35 | Assuming you've already overridden the homepage view: 36 | 37 | $ rake refinery:override view=refinery/pages/home 38 | 39 | You can render the `recent_posts` partial. However, you will need to set the recent News items manually, since this is normally handled in the News::Items controller: 40 | 41 | ```erb 42 | <% @items = Refinery::News::Item.latest(5) %> 43 | <%= render :partial => '/refinery/news/items/recent_posts' %> 44 | ``` 45 | 46 | ## Configuring the number of items per page 47 | 48 | To modify the number of items per page for the news items index without 49 | affecting the archive page you must override the method in the controller that 50 | sets `@items` for the index: `find_published_news_items`. 51 | 52 | Currently the method body is: 53 | ```ruby 54 | @items = Item.published.translated.page(params[:page]) 55 | ``` 56 | 57 | The `page` convenience method needs to be replaced with `paginate` and 58 | `per_page` passed as an option. Add a decorator for the items controller with 59 | the following contents: 60 | 61 | ```ruby 62 | module Refinery::News 63 | ItemsController.class_eval do 64 | def find_published_news_items 65 | @items = Item.published.translated.paginate :page => params[:page], 66 | :per_page => 8 67 | end 68 | end 69 | end 70 | ``` 71 | 72 | ## Customising the views 73 | 74 | Type this command at your project root to override the default front end views: 75 | 76 | $ rake refinery:override view=refinery/news/items/* 77 | Copied view template file to app/views/refinery/news/items/_recent_posts.html.erb 78 | Copied view template file to app/views/refinery/news/items/index.html.erb 79 | Copied view template file to app/views/refinery/news/items/show.html.erb 80 | etc. 81 | 82 | ## RSS (Really Simple Syndication) 83 | 84 | To get RSS for your entire site, insert this into the head section of your layout after installing: 85 | 86 | ```erb 87 | <%= auto_discovery_link_tag(:rss, refinery.news_items_url(:format => 'rss')) %> 88 | ``` 89 | 90 | ## More Information 91 | * Check out our [Website](http://refinerycms.com/) 92 | * Refinery Documentation is available in the [guides](http://refinerycms.com/guides) 93 | * Questions can be asked on our [Google Group](http://group.refinerycms.org) 94 | * Questions can also be asked in our IRC room, [#refinerycms on freenode](irc://irc.freenode.net/refinerycms) 95 | -------------------------------------------------------------------------------- /spec/models/refinery/news/item_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | module Refinery 4 | module News 5 | describe Item, :type => :model do 6 | 7 | let(:news_item) { FactoryBot.create(:news_item) } 8 | let(:publish_date) { Date.current } 9 | 10 | describe "#archive" do 11 | let(:publish_date) { Time.utc(2012,1,15) } 12 | let(:future_date) { Time.utc(2012,2,15) } 13 | let(:archive_range) { Time.parse("2012-01-17") } 14 | 15 | it "should show 5 news items with publish dates in same month" do 16 | 5.times { FactoryBot.create(:news_item, :publish_date => publish_date) } 17 | 2.times { FactoryBot.create(:news_item, :publish_date => future_date) } 18 | 19 | expect(Refinery::News::Item.by_archive(archive_range).count).to eq(5) 20 | end 21 | end 22 | 23 | describe "validations" do 24 | subject do 25 | Refinery::News::Item.create!( 26 | content: 'Some random text ...', 27 | publish_date: publish_date, 28 | title: 'Refinery CMS' 29 | ) 30 | end 31 | 32 | it { is_expected.to be_valid } 33 | 34 | describe '#errors' do 35 | subject { super().errors } 36 | it { is_expected.to be_empty } 37 | end 38 | 39 | describe '#title' do 40 | subject { super().title } 41 | it { is_expected.to eq("Refinery CMS") } 42 | end 43 | 44 | describe '#content' do 45 | subject { super().content } 46 | it { is_expected.to eq("Some random text ...") } 47 | end 48 | 49 | describe '#publish_date' do 50 | subject { super().publish_date } 51 | it { is_expected.to eq(publish_date) } 52 | end 53 | end 54 | 55 | describe "attribute aliasing" do 56 | subject { news_item } 57 | 58 | describe '#content' do 59 | subject { super().content } 60 | it { is_expected.to eq(news_item.body) } 61 | end 62 | end 63 | 64 | describe "default scope" do 65 | it "orders by publish date in DESC order" do 66 | news_item1 = FactoryBot.create(:news_item, :publish_date => 1.hour.ago) 67 | news_item2 = FactoryBot.create(:news_item, :publish_date => 2.hours.ago) 68 | news_items = Refinery::News::Item.all 69 | expect(news_items.first).to eq(news_item1) 70 | expect(news_items.second).to eq(news_item2) 71 | end 72 | end 73 | 74 | describe ".not_expired" do 75 | let!(:news_item) { FactoryBot.create(:news_item) } 76 | 77 | specify "expiration date not set" do 78 | expect(Refinery::News::Item.not_expired.count).to eq(1) 79 | end 80 | 81 | specify "expiration date set in future" do 82 | news_item.expiration_date = Time.now + 1.hour 83 | news_item.save! 84 | expect(Refinery::News::Item.not_expired.count).to eq(1) 85 | end 86 | 87 | specify "expiration date in past" do 88 | news_item.expiration_date = Time.now - 1.hour 89 | news_item.save! 90 | expect(Refinery::News::Item.not_expired.count).to eq(0) 91 | end 92 | end 93 | 94 | describe ".published" do 95 | it "returns only published news items" do 96 | FactoryBot.create(:news_item) 97 | FactoryBot.create(:news_item, :publish_date => Time.now + 1.hour) 98 | expect(Refinery::News::Item.published.count).to eq(1) 99 | end 100 | end 101 | 102 | describe ".latest" do 103 | it "returns 10 latest news items by default" do 104 | 5.times { FactoryBot.create(:news_item) } 105 | 5.times { FactoryBot.create(:news_item, :publish_date => Time.now + 1.hour) } 106 | expect(Refinery::News::Item.latest.count).to eq(5) 107 | 7.times { FactoryBot.create(:news_item) } 108 | expect(Refinery::News::Item.latest.count).to eq(10) 109 | end 110 | 111 | it "returns latest n news items" do 112 | 4.times { FactoryBot.create(:news_item) } 113 | expect(Refinery::News::Item.latest(3).count).to eq(3) 114 | end 115 | end 116 | 117 | describe ".not_published?" do 118 | it "returns not published news items" do 119 | news_item = FactoryBot.create(:news_item, :publish_date => Time.now + 1.hour) 120 | expect(news_item.not_published?).to be_truthy 121 | end 122 | end 123 | 124 | describe ".archived" do 125 | it "returns all published/expired news items" do 126 | expired = FactoryBot.create(:news_item, :publish_date => Time.now - 2.months, :expiration_date => Time.now - 1.months) 127 | published = FactoryBot.create(:news_item, :publish_date => Time.now - 1.month) 128 | not_published = FactoryBot.create(:news_item, :publish_date => Time.now + 1.month) 129 | expect(Refinery::News::Item.archived).to include(expired) 130 | expect(Refinery::News::Item.archived).to include(published) 131 | expect(Refinery::News::Item.archived).to_not include(not_published) 132 | end 133 | end 134 | 135 | describe "#should_generate_new_friendly_id?" do 136 | context "when title changes" do 137 | it "regenerates slug upon save" do 138 | news_item = FactoryBot.create(:news_item, :title => "Test Title") 139 | 140 | news_item.title = "Test Title 2" 141 | news_item.save! 142 | 143 | expect(news_item.slug).to eq("test-title-2") 144 | end 145 | end 146 | end 147 | end 148 | end 149 | end 150 | --------------------------------------------------------------------------------