refinerycms-news 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +17 -0
  3. data/Gemfile +69 -0
  4. data/Guardfile +20 -0
  5. data/Rakefile +19 -0
  6. data/app/controllers/refinery/news/admin/items_controller.rb +11 -0
  7. data/app/controllers/refinery/news/items_controller.rb +50 -0
  8. data/app/helpers/refinery/news/items_helper.rb +51 -0
  9. data/app/models/refinery/news/item.rb +91 -0
  10. data/app/views/{admin/news_items → refinery/news/admin/items}/_form.html.erb +13 -8
  11. data/app/views/{admin/news_items/_news_item.html.erb → refinery/news/admin/items/_item.html.erb} +8 -8
  12. data/app/views/{admin/news_items → refinery/news/admin/items}/_locale_picker.html.erb +1 -1
  13. data/app/views/{admin/news_items → refinery/news/admin/items}/edit.html.erb +0 -0
  14. data/app/views/refinery/news/admin/items/index.html.erb +30 -0
  15. data/app/views/{admin/news_items → refinery/news/admin/items}/new.html.erb +0 -0
  16. data/app/views/{news_items → refinery/news/items}/_recent_posts.html.erb +2 -2
  17. data/app/views/refinery/news/items/archive.html.erb +17 -0
  18. data/app/views/refinery/news/items/index.html.erb +28 -0
  19. data/app/views/{news_items → refinery/news/items}/index.rss.builder +5 -5
  20. data/app/views/refinery/news/items/show.html.erb +20 -0
  21. data/app/views/refinery/news/items/widgets/_news_archive.html.erb +10 -0
  22. data/app/views/refinery/news/shared/_body_content_right.html.erb +5 -0
  23. data/app/views/refinery/news/shared/_item.html.erb +22 -0
  24. data/config/locales/bg.yml +37 -0
  25. data/config/locales/cs.yml +29 -28
  26. data/config/locales/de.yml +27 -27
  27. data/config/locales/en.yml +39 -29
  28. data/config/locales/es-MX.yml +26 -26
  29. data/config/locales/es.yml +29 -27
  30. data/config/locales/fr.yml +28 -28
  31. data/config/locales/it.yml +27 -27
  32. data/config/locales/jp.yml +36 -0
  33. data/config/locales/lv.yml +28 -26
  34. data/config/locales/nb.yml +27 -27
  35. data/config/locales/nl.yml +27 -27
  36. data/config/locales/pl.yml +37 -0
  37. data/config/locales/pt-BR.yml +28 -28
  38. data/config/locales/ru.yml +26 -26
  39. data/config/locales/sk.yml +28 -28
  40. data/config/locales/sl.yml +31 -29
  41. data/config/locales/zh-CN.yml +37 -0
  42. data/config/locales/zh-TW.yml +37 -0
  43. data/config/routes.rb +13 -5
  44. data/db/migrate/20110817203701_create_news_items.rb +23 -0
  45. data/db/migrate/20110817203702_add_external_url_to_news_items.rb +15 -0
  46. data/db/migrate/20110817203703_translate_news_items.rb +21 -0
  47. data/db/migrate/20110817203704_add_image_id_to_news_items.rb +13 -0
  48. data/db/migrate/20110817203705_add_expiration_date_to_news_items.rb +15 -0
  49. data/db/migrate/20110817203706_remove_image_id_and_external_url_from_news.rb +19 -0
  50. data/db/migrate/20120129230838_add_source_to_news_items.rb +16 -0
  51. data/db/migrate/20120129230839_translate_source.rb +16 -0
  52. data/db/migrate/20120228150250_add_slug_to_news_items.rb +5 -0
  53. data/db/seeds.rb +22 -0
  54. data/lib/generators/refinery/news_generator.rb +19 -0
  55. data/lib/refinery/news.rb +22 -0
  56. data/lib/refinery/news/engine.rb +23 -0
  57. data/lib/refinerycms-news.rb +1 -23
  58. data/readme.md +10 -8
  59. data/refinerycms-news.gemspec +20 -0
  60. data/spec/factories/news.rb +7 -0
  61. data/spec/models/refinery/news/item_spec.rb +91 -0
  62. data/spec/requests/manage_news_items_spec.rb +90 -0
  63. data/spec/requests/news_archive.rb +12 -0
  64. data/spec/requests/visit_news_items_spec.rb +37 -0
  65. data/spec/spec_helper.rb +56 -0
  66. data/tasks/rspec.rake +4 -0
  67. metadata +113 -40
  68. data/app/controllers/admin/news_items_controller.rb +0 -5
  69. data/app/controllers/news_items_controller.rb +0 -33
  70. data/app/models/news_item.rb +0 -46
  71. data/app/views/admin/news_items/index.html.erb +0 -30
  72. data/app/views/news_items/index.html.erb +0 -23
  73. data/app/views/news_items/show.html.erb +0 -15
  74. data/db/migrate/1_create_news_items.rb +0 -23
  75. data/db/migrate/2_add_external_url_to_news_items.rb +0 -15
  76. data/db/migrate/3_translate_news_items.rb +0 -24
  77. data/db/migrate/4_add_image_id_to_news_items.rb +0 -13
  78. data/db/migrate/5_add_expiration_date_to_news_items.rb +0 -15
  79. data/db/migrate/6_remove_image_id_and_external_url_from_news.rb +0 -19
  80. data/db/seeds/refinerycms_news.rb +0 -24
  81. data/features/manage_news_items.feature +0 -56
  82. data/features/step_definitions/news_steps.rb +0 -25
  83. data/features/support/factories.rb +0 -7
  84. data/features/support/paths.rb +0 -26
  85. data/features/visit_news_items.feature +0 -27
  86. data/lib/gemspec.rb +0 -29
  87. data/lib/generators/refinerycms_news_generator.rb +0 -8
  88. data/lib/news.rb +0 -9
  89. data/spec/models/news_item_spec.rb +0 -89
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ Gemfile.lock
3
+ spec/dummy
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ before_script:
2
+ - "bundle exec rake refinery:testing:dummy_app > /dev/null"
3
+ script: "bundle exec rspec ./spec"
4
+ notifications:
5
+ email:
6
+ - parndt@gmail.com
7
+ - ugis.ozolss@gmail.com
8
+ - heinleng@gmail.com
9
+ env:
10
+ - DB=postgresql
11
+ - DB=mysql
12
+ rvm:
13
+ - 1.8.7
14
+ - 1.9.2
15
+ - 1.9.3
16
+ - rbx
17
+ - jruby
data/Gemfile ADDED
@@ -0,0 +1,69 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'refinerycms', '~> 2.0.1'
6
+
7
+ group :development, :test do
8
+ gem 'refinerycms-testing', '~> 2.0.0'
9
+ gem 'guard-rspec', '~> 0.6.0'
10
+
11
+ platforms :jruby do
12
+ gem 'activerecord-jdbcsqlite3-adapter'
13
+ gem 'activerecord-jdbcmysql-adapter'
14
+ gem 'activerecord-jdbcpostgresql-adapter'
15
+ gem 'jruby-openssl'
16
+ end
17
+
18
+ unless defined?(JRUBY_VERSION)
19
+ gem 'sqlite3'
20
+ gem 'mysql2'
21
+ gem 'pg'
22
+ end
23
+
24
+ platforms :mswin, :mingw do
25
+ gem 'win32console'
26
+ gem 'rb-fchange', '~> 0.0.5'
27
+ gem 'rb-notifu', '~> 0.0.4'
28
+ end
29
+
30
+ platforms :ruby do
31
+ gem 'spork', '~> 0.9.0.rc'
32
+ gem 'guard-spork'
33
+
34
+ unless ENV['TRAVIS']
35
+ require 'rbconfig'
36
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
37
+ gem 'rb-fsevent', '>= 0.3.9'
38
+ gem 'ruby_gntp'
39
+ end
40
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
41
+ gem 'rb-inotify', '>= 0.5.1'
42
+ gem 'libnotify', '~> 0.1.3'
43
+ gem 'therubyracer', '~> 0.9.9'
44
+ end
45
+ end
46
+ end
47
+
48
+ platforms :jruby do
49
+ unless ENV['TRAVIS']
50
+ require 'rbconfig'
51
+ if RbConfig::CONFIG['target_os'] =~ /darwin/i
52
+ gem 'ruby_gntp'
53
+ end
54
+ if RbConfig::CONFIG['target_os'] =~ /linux/i
55
+ gem 'rb-inotify', '>= 0.5.1'
56
+ gem 'libnotify', '~> 0.1.3'
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ # Refinery/rails should pull in the proper versions of these
63
+ group :assets do
64
+ gem 'sass-rails'
65
+ gem 'coffee-rails'
66
+ gem 'uglifier'
67
+ end
68
+
69
+ gem 'jquery-rails'
data/Guardfile ADDED
@@ -0,0 +1,20 @@
1
+ guard 'rspec', :version => 2, :cli => "--color" do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/controllers/#{m[1]}_#{m[2]}_spec.rb", "spec/requests/#{m[1]}_spec.rb"] }
6
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ watch('config/routes.rb') { "spec/routing" }
9
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
10
+ # Capybara request specs
11
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
12
+ end
13
+
14
+ guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
15
+ watch('config/application.rb')
16
+ watch('config/environment.rb')
17
+ watch(%r{^config/environments/.+\.rb$})
18
+ watch(%r{^config/initializers/.+\.rb$})
19
+ watch('spec/spec_helper.rb')
20
+ end
data/Rakefile ADDED
@@ -0,0 +1,19 @@
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_tasks
17
+ Refinery::Testing::Railtie.load_dummy_tasks(ENGINE_PATH)
18
+
19
+ load File.expand_path('../tasks/rspec.rake', __FILE__)
@@ -0,0 +1,11 @@
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
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,50 @@
1
+ module Refinery
2
+ module News
3
+ class ItemsController < ::ApplicationController
4
+ before_filter :find_page
5
+ before_filter :find_published_news_items, :only => [:index]
6
+ before_filter :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
+ date = "#{params[:month]}/#{params[:year]}"
19
+ @archive_date = Time.parse(date)
20
+ @date_title = @archive_date.strftime('%B %Y')
21
+ @items = Refinery::News::Item.live.by_archive(@archive_date).page(params[:page])
22
+ else
23
+ date = "01/#{params[:year]}"
24
+ @archive_date = Time.parse(date)
25
+ @date_title = @archive_date.strftime('%Y')
26
+ @items = Refinery::News::Item.live.by_year(@archive_date).page(params[:page])
27
+ end
28
+ end
29
+
30
+ protected
31
+
32
+ def find_latest_news_items
33
+ @items = Refinery::News::Item.latest.translated
34
+ end
35
+
36
+ def find_published_news_items
37
+ @items = Refinery::News::Item.published.translated.page(params[:page])
38
+ end
39
+
40
+ def find_news_item
41
+ @item = Refinery::News::Item.published.translated.find(params[:id])
42
+ end
43
+
44
+ def find_page
45
+ @page = ::Refinery::Page.find_by_link_url("/news") if defined?(::Refinery::Page)
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,51 @@
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 :partial => "/refinery/news/items/widgets/news_archive", :locals => { :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_link(item)
32
+ if item.publish_date >= Time.now.end_of_year.advance(:years => -3)
33
+ post_date = item.publish_date.strftime('%m/%Y')
34
+ year = post_date.split('/')[1]
35
+ month = post_date.split('/')[0]
36
+ count = News::Item.by_archive(Time.parse(post_date)).size
37
+ text = t("date.month_names")[month.to_i] + " #{year} (#{count})"
38
+
39
+ link_to(text, refinery.news_items_archive_path(:year => year, :month => month))
40
+ else
41
+ post_date = post.publish_date.strftime('01/%Y')
42
+ year = post_date.split('/')[1]
43
+ count = Refinery::News::Item.by_year(Time.parse(post_date)).size
44
+ text = "#{year} (#{count})"
45
+
46
+ link_to(text, refinery.news_items_archive_path(:year => year))
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,91 @@
1
+ module Refinery
2
+ module News
3
+ class Item < Refinery::Core::BaseModel
4
+ extend FriendlyId
5
+
6
+ translates :title, :body
7
+
8
+ attr_accessor :locale # to hold temporarily
9
+
10
+ alias_attribute :content, :body
11
+ validates :title, :content, :publish_date, :presence => true
12
+
13
+ friendly_id :title, :use => [:slugged]
14
+
15
+ acts_as_indexed :fields => [:title, :body]
16
+
17
+ default_scope :order => "publish_date DESC"
18
+
19
+ def not_published? # has the published date not yet arrived?
20
+ publish_date > Time.now
21
+ end
22
+
23
+ def next
24
+ self.class.next(self).first
25
+ end
26
+
27
+ def prev
28
+ self.class.previous(self).first
29
+ end
30
+
31
+ class << self
32
+ def by_archive(archive_date)
33
+ where(['publish_date between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month])
34
+ end
35
+
36
+ def by_year(archive_year)
37
+ where(['publish_date between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year])
38
+ end
39
+
40
+ def all_previous
41
+ where(['publish_date <= ?', Time.now.beginning_of_month])
42
+ end
43
+
44
+ def next(item)
45
+ self.send(:with_exclusive_scope) do
46
+ where("publish_date > ?", item.publish_date).order("publish_date ASC")
47
+ end
48
+ end
49
+
50
+ def previous(item)
51
+ where("publish_date < ?", item.publish_date)
52
+ end
53
+
54
+ def not_expired
55
+ where(arel_table[:expiration_date].eq(nil).or(arel_table[:expiration_date].gt(Time.now)))
56
+ end
57
+
58
+ def published
59
+ not_expired.where("publish_date < ?", Time.now)
60
+ end
61
+
62
+ def latest(limit = 10)
63
+ published.limit(limit)
64
+ end
65
+
66
+ def live
67
+ not_expired.where( "publish_date <= ?", Time.now)
68
+ end
69
+
70
+ # rejects any page that has not been translated to the current locale.
71
+ def translated
72
+ includes(:translations).where(
73
+ translation_class.arel_table[:locale].eq(::Globalize.locale)
74
+ ).where(
75
+ arel_table[:id].eq(translation_class.arel_table[:refinery_news_item_id])
76
+ )
77
+ end
78
+
79
+ def teasers_enabled?
80
+ Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news')
81
+ end
82
+
83
+ def teaser_enabled_toggle!
84
+ currently = Refinery::Setting.find_or_set(:teasers_enabled, true, :scoping => 'news')
85
+ Refinery::Setting.set(:teasers_enabled, :value => !currently, :scoping => 'news')
86
+ end
87
+ end
88
+
89
+ end
90
+ end
91
+ end
@@ -1,7 +1,7 @@
1
- <%= form_for [:admin, @news_item] do |f| %>
2
- <%= render :partial => "/shared/admin/error_messages",
1
+ <%= form_for [refinery, :news, :admin, @item] do |f| %>
2
+ <%= render :partial => "/refinery/admin/error_messages",
3
3
  :locals => {
4
- :object => @news_item,
4
+ :object => @item,
5
5
  :include_object_name => true
6
6
  } %>
7
7
 
@@ -27,16 +27,21 @@
27
27
  </div>
28
28
 
29
29
  <div class='field'>
30
- <%= f.label :content %>
31
- <%= f.text_area :content, :rows => "20", :class => "wymeditor widest" %>
30
+ <%= f.label :body %>
31
+ <%= f.text_area :body, :rows => "20", :class => "wymeditor widest" %>
32
32
  </div>
33
33
 
34
- <%= render :partial => "/shared/admin/form_actions",
34
+ <div class='field'>
35
+ <%= f.label :source %>
36
+ <%= f.text_field :source, :class => "larger widest" %>
37
+ </div>
38
+
39
+ <%= render :partial => "/refinery/admin/form_actions",
35
40
  :locals => {
36
41
  :f => f,
37
42
  :continue_editing => true,
38
- :delete_title => t('admin.news_items.news_item.delete'),
39
- :delete_confirmation => t('shared.admin.delete.message', :title => @news_item.title)
43
+ :delete_title => t('admin.news.items.item.delete'),
44
+ :delete_confirmation => t('shared.admin.delete.message', :title => @item.title)
40
45
  } %>
41
46
 
42
47
  <% end %>
@@ -1,28 +1,28 @@
1
1
  <li class='clearfix record <%= cycle("on", "on-hover") %>'>
2
2
  <span class='title'>
3
- <%= news_item.title %>
3
+ <%= item.title %>
4
4
  <span class="preview">
5
- <%= t('.published') %> <%= l(news_item.publish_date, :format => :short) %>
5
+ <%= t('.published') %> <%= l(item.publish_date, :format => :short) %>
6
6
  </span>
7
7
  <% if defined?(::Refinery::I18n) and ::Refinery::I18n.frontend_locales.many? and
8
- (locales = news_item.translations.collect{|t| t.locale}).present? %>
8
+ (locales = item.translations.collect{|t| t.locale}).present? %>
9
9
  <span class='preview'>
10
10
  <% locales.each do |locale| %>
11
- <%= refinery_icon_tag "flags/#{locale}.png", :size => '16x11' %>
11
+ <%= refinery_icon_tag "flags/#{locale}.png", :size => '32x32' %>
12
12
  <% end %>
13
13
  </span>
14
14
  <% end %>
15
15
  </span>
16
16
  <span class='actions'>
17
- <%= link_to refinery_icon_tag('application_go.png'), news_item_url(news_item),
17
+ <%= link_to refinery_icon_tag('application_go.png'), refinery.news_item_path(item),
18
18
  :title => t('.view_live_html'),
19
19
  :target => "_blank" %>
20
- <%= link_to refinery_icon_tag('application_edit.png'), edit_admin_news_item_path(news_item),
20
+ <%= link_to refinery_icon_tag('application_edit.png'), refinery.edit_news_admin_item_path(item),
21
21
  :title => t('.edit') %>
22
- <%= link_to refinery_icon_tag('delete.png'), admin_news_item_path(news_item),
22
+ <%= link_to refinery_icon_tag('delete.png'), refinery.news_admin_item_path(item),
23
23
  :class => "cancel confirm-delete",
24
24
  :title => t('.delete'),
25
25
  :method => :delete,
26
- :confirm => t('shared.admin.delete.message', :title => news_item.title) %>
26
+ :confirm => t('shared.admin.delete.message', :title => item.title) %>
27
27
  </span>
28
28
  </li>
@@ -4,7 +4,7 @@
4
4
  <% locales.each do |locale| %>
5
5
  <li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>>
6
6
  <%= link_to refinery_icon_tag("flags/#{locale}.png", :size => '48x33'),
7
- url_for(:switch_locale => locale) %>
7
+ refinery.url_for(:switch_locale => locale) %>
8
8
  </li>
9
9
  <% end %>
10
10
  </ul>
@@ -0,0 +1,30 @@
1
+ <div id='actions'>
2
+ <ul>
3
+ <li>
4
+ <%= render :partial => "/refinery/admin/search", :locals => {:url => refinery.news_admin_items_path} %>
5
+ </li>
6
+ <li>
7
+ <%= link_to t('.create'), refinery.new_news_admin_item_path, :class => "add_icon" %>
8
+ </li>
9
+ </ul>
10
+ </div>
11
+ <div id='records'>
12
+ <% if searching? %>
13
+ <h2><%= t('refinery.admin.search.results_for', :query => params[:search]) %></h2>
14
+ <% end %>
15
+ <% if @items.any? %>
16
+ <%= will_paginate @items %>
17
+ <ul>
18
+ <%= render :partial => "item", :collection => @items %>
19
+ </ul>
20
+ <%= will_paginate @items %>
21
+ <% else %>
22
+ <p>
23
+ <% unless searching? %>
24
+ <strong><%= t('.no_items_yet') %></strong>
25
+ <% else %>
26
+ <%= t('refinery.admin.search.no_results') %>
27
+ <% end %>
28
+ </p>
29
+ <% end %>
30
+ </div>