refinerycms-subscriptions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/app/controllers/refinery/subscriptions/admin/subscriptions_controller.rb +12 -0
  2. data/app/controllers/refinery/subscriptions/subscriptions_controller.rb +35 -0
  3. data/app/mailers/refinery/subscriptions/subscription_mailer.rb +14 -0
  4. data/app/models/refinery/subscriptions/setting.rb +21 -0
  5. data/app/models/refinery/subscriptions/subscription.rb +13 -0
  6. data/app/views/refinery/subscriptions/admin/subscriptions/_actions.html.erb +25 -0
  7. data/app/views/refinery/subscriptions/admin/subscriptions/_form.html.erb +15 -0
  8. data/app/views/refinery/subscriptions/admin/subscriptions/_records.html.erb +18 -0
  9. data/app/views/refinery/subscriptions/admin/subscriptions/_sortable_list.html.erb +5 -0
  10. data/app/views/refinery/subscriptions/admin/subscriptions/_subscription.html.erb +20 -0
  11. data/app/views/refinery/subscriptions/admin/subscriptions/_subscriptions.html.erb +2 -0
  12. data/app/views/refinery/subscriptions/admin/subscriptions/edit.html.erb +1 -0
  13. data/app/views/refinery/subscriptions/admin/subscriptions/index.html.erb +7 -0
  14. data/app/views/refinery/subscriptions/admin/subscriptions/new.html.erb +1 -0
  15. data/app/views/refinery/subscriptions/shared/_subscription.html.erb +6 -0
  16. data/app/views/refinery/subscriptions/subscription_mailer/notification.text.erb +9 -0
  17. data/app/views/refinery/subscriptions/subscriptions/new.html.erb +4 -0
  18. data/app/views/refinery/subscriptions/subscriptions/thank_you.html.erb +1 -0
  19. data/config/locales/en.yml +42 -0
  20. data/config/locales/hr.yml +13 -0
  21. data/config/routes.rb +23 -0
  22. data/db/migrate/1_create_subscriptions_subscriptions.rb +26 -0
  23. data/db/seeds.rb +25 -0
  24. data/lib/generators/refinery/subscriptions_generator.rb +20 -0
  25. data/lib/refinery/subscriptions.rb +22 -0
  26. data/lib/refinery/subscriptions/engine.rb +27 -0
  27. data/lib/refinerycms-subscriptions.rb +1 -0
  28. data/lib/tasks/refinery/subscriptions.rake +13 -0
  29. data/readme.md +10 -0
  30. metadata +122 -0
@@ -0,0 +1,12 @@
1
+ module Refinery
2
+ module Subscriptions
3
+ module Admin
4
+ class SubscriptionsController < ::Refinery::AdminController
5
+
6
+ crudify :'refinery/subscriptions/subscription',
7
+ :title_attribute => 'email', :xhr_paging => true
8
+
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ module Refinery
2
+ module Subscriptions
3
+ class SubscriptionsController < ::ApplicationController
4
+
5
+ before_filter :find_page, :only => [:new, :create]
6
+
7
+ def new
8
+ @subscription = ::Refinery::Subscriptions::Subscription.new
9
+ end
10
+
11
+ def create
12
+ @subscription = ::Refinery::Subscriptions::Subscription.new(params[:subscription])
13
+
14
+ if @subscription.save
15
+ begin
16
+ ::Refinery::Subscriptions::SubscriptionMailer.notification(@subscription, request).deliver
17
+ rescue
18
+ logger.warn "There was an error delivering an subscription notification.\n#{$!}\n"
19
+ end
20
+
21
+ redirect_to refinery.thank_you_subscriptions_subscriptions_path
22
+ else
23
+ render :action => 'new'
24
+ end
25
+ end
26
+
27
+ protected
28
+
29
+ def find_page
30
+ @page = ::Refinery::Page.where(:link_url => "/subscriptions").first
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ module Refinery
2
+ module Subscriptions
3
+ class SubscriptionMailer < ActionMailer::Base
4
+
5
+ def notification(subscription, request)
6
+ @subscription = subscription
7
+ mail :subject => Refinery::Subscriptions::Setting.notification_subject,
8
+ :to => Refinery::Subscriptions::Setting.notification_recipients,
9
+ :from => "\"#{Refinery::Core.site_name}\" <no-reply@#{request.domain}>",
10
+ :reply_to => @subscription.email
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ module Refinery
2
+ module Subscriptions
3
+ class Setting
4
+
5
+ class << self
6
+
7
+ def notification_recipients
8
+ Refinery::Setting.find_or_set(:subscription_notification_recipients,
9
+ ((Refinery::Role[:refinery].users.first.email rescue nil) if defined?(Refinery::Role)).to_s,
10
+ :scoping => "subscriptions")
11
+ end
12
+
13
+ def notification_subject
14
+ Refinery::Setting.find_or_set(:subscription_notification_subject,
15
+ "New subscription to your newsletter",
16
+ :scoping => "subscriptions")
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Refinery
2
+ module Subscriptions
3
+ class Subscription < Refinery::Core::BaseModel
4
+ self.table_name = 'refinery_subscriptions'
5
+
6
+ attr_accessible :email, :position
7
+
8
+ acts_as_indexed :fields => [:email]
9
+
10
+ validates :email, :presence => true, :uniqueness => true, :format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ <ul>
2
+ <% if ::Refinery::Subscriptions::Admin::SubscriptionsController.searchable? %>
3
+ <li>
4
+ <%= render '/refinery/admin/search', :url => refinery.subscriptions_admin_subscriptions_path %>
5
+ </li>
6
+ <% end %>
7
+ <li>
8
+ <%= link_to t('.create_new'), refinery.new_subscriptions_admin_subscription_path,
9
+ :class => "add_icon" %>
10
+ </li>
11
+ <% if !searching? && ::Refinery::Subscriptions::Admin::SubscriptionsController.sortable? && ::Refinery::Subscriptions::Subscription.any? %>
12
+ <li>
13
+ <%= link_to t('.reorder', :what => "Subscriptions"),
14
+ refinery.subscriptions_admin_subscriptions_path,
15
+ :id => "reorder_action",
16
+ :class => "reorder_icon" %>
17
+
18
+ <%= link_to t('.reorder_done', :what => "Subscriptions"),
19
+ refinery.subscriptions_admin_subscriptions_path,
20
+ :id => "reorder_action_done",
21
+ :style => "display: none;",
22
+ :class => "reorder_icon" %>
23
+ </li>
24
+ <% end %>
25
+ </ul>
@@ -0,0 +1,15 @@
1
+ <%= form_for [refinery, :subscriptions_admin, @subscription] do |f| -%>
2
+ <%= render '/refinery/admin/error_messages',
3
+ :object => @subscription,
4
+ :include_object_name => true %>
5
+
6
+ <div class='field'>
7
+ <%= f.label :email -%>
8
+ <%= f.text_field :email, :class => 'larger widest' -%>
9
+ </div>
10
+
11
+ <%= render '/refinery/admin/form_actions', :f => f,
12
+ :continue_editing => false,
13
+ :delete_title => t('delete', :scope => 'refinery.subscriptions.admin.subscriptions.subscription'),
14
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @subscription.email) -%>
15
+ <% end -%>
@@ -0,0 +1,18 @@
1
+ <% if searching? %>
2
+ <h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
3
+ <% end %>
4
+ <div class='pagination_container'>
5
+ <% if @subscriptions.any? %>
6
+ <%= render 'subscriptions' %>
7
+ <% else %>
8
+ <p>
9
+ <% unless searching? %>
10
+ <strong>
11
+ <%= t('.no_items_yet') %>
12
+ </strong>
13
+ <% else %>
14
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
15
+ <% end %>
16
+ </p>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,5 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'subscription', :collection => @subscriptions %>
3
+ </ul>
4
+ <%= render '/refinery/admin/sortable_list',
5
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
@@ -0,0 +1,20 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(subscription) -%>">
2
+ <span class='title'>
3
+ <%= subscription.email %>
4
+
5
+ </span>
6
+ <span class='actions'>
7
+
8
+ <%= link_to refinery_icon_tag("application_go.png"), refinery.subscriptions_subscriptions_path(subscription),
9
+ :title => t('.view_live_html'),
10
+ :target => "_blank" %>
11
+
12
+ <%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_subscriptions_admin_subscription_path(subscription),
13
+ :title => t('.edit') %>
14
+ <%= link_to refinery_icon_tag("delete.png"), refinery.subscriptions_admin_subscription_path(subscription),
15
+ :class => "cancel confirm-delete",
16
+ :title => t('.delete'),
17
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => subscription.email),
18
+ :method => :delete %>
19
+ </span>
20
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @subscriptions if Refinery::Subscriptions::Admin::SubscriptionsController.pageable? %>
2
+ <%= render 'sortable_list' %>
@@ -0,0 +1,7 @@
1
+ <section id='records'>
2
+ <%= render 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render 'actions' %>
6
+ </aside>
7
+ <%= render '/refinery/admin/make_sortable', :tree => false if !searching? and ::Refinery::Subscriptions::Admin::SubscriptionsController.sortable? and ::Refinery::Subscriptions::Subscription.count > 1 %>
@@ -0,0 +1,6 @@
1
+ <div class='subscriptions'>
2
+ <%= form_for [refinery, :subscriptions, @subscription] do |f| %>
3
+ <%= f.email_field :email, :placeholder => t('.email') %>
4
+ <%= f.submit t('.send') %>
5
+ <% end %>
6
+ </div>
@@ -0,0 +1,9 @@
1
+ <%=raw t('.greeting') %>,
2
+
3
+ <%=raw t('.you_received_new_subscription') %>
4
+
5
+ <%=raw t('.email') %>: <%= @subscription.email %>
6
+
7
+ <%=raw Refinery::Core.site_name %>
8
+
9
+ <%=raw t('.ps') %>
@@ -0,0 +1,4 @@
1
+ <% content_for :body do %>
2
+ <%= render "/refinery/subscriptions/shared/subscription" %>
3
+ <% end %>
4
+ <%= render "/refinery/content_page" %>
@@ -0,0 +1 @@
1
+ <%= render "/refinery/content_page" %>
@@ -0,0 +1,42 @@
1
+ en:
2
+ refinery:
3
+ plugins:
4
+ subscriptions:
5
+ title: Subscriptions
6
+ subscriptions:
7
+ config:
8
+ from_name: "%{site_name}"
9
+ admin:
10
+ subscriptions:
11
+ actions:
12
+ create_new: Add New Subscription
13
+ reorder: Reorder Subscriptions
14
+ reorder_done: Done Reordering Subscriptions
15
+ records:
16
+ title: Subscriptions
17
+ sorry_no_results: Sorry! There are no results found.
18
+ no_items_yet: There are no Subscriptions yet. Click "Add New Subscription" to add your first subscription.
19
+ subscription:
20
+ view_live_html: View this subscription live <br/><em>(opens in a new window)</em>
21
+ edit: Edit this subscription
22
+ delete: Remove this subscription forever
23
+ subscriptions:
24
+ new:
25
+ send: 'Subscribe'
26
+ show:
27
+ other: Other Subscriptions
28
+ shared:
29
+ subscription:
30
+ send: 'Subscribe'
31
+ email: 'Email'
32
+ subscription_mailer:
33
+ notification:
34
+ greeting: Hi there
35
+ you_received_new_subscription: You just received a new subscription to your newsletter.
36
+ email: Email
37
+ closing_line: Kind Regards
38
+ ps: P.S. All your subscriptions are stored in the "Subscriptions" section of Refinery should you ever want to view it later there.
39
+ activerecord:
40
+ attributes:
41
+ 'refinery/subscriptions/subscription':
42
+ email: Email
@@ -0,0 +1,13 @@
1
+ en:
2
+ refinery:
3
+ subscriptions:
4
+ config:
5
+ from_name: "%{site_name}"
6
+ shared:
7
+ subscription:
8
+ send: 'Prijavi se'
9
+ email: 'Email'
10
+ activerecord:
11
+ attributes:
12
+ 'refinery/subscriptions/subscription':
13
+ email: Email
@@ -0,0 +1,23 @@
1
+ Refinery::Core::Engine.routes.append do
2
+
3
+ # Frontend routes
4
+ namespace :subscriptions do
5
+ resources :subscriptions, :path => '',
6
+ :only => [:new, :create],
7
+ :controller => 'subscriptions' do
8
+ get :thank_you, :on => :collection
9
+ end
10
+ end
11
+
12
+ # Admin routes
13
+ namespace :subscriptions, :path => '' do
14
+ namespace :admin, :path => 'refinery' do
15
+ resources :subscriptions, :except => :show do
16
+ collection do
17
+ post :update_positions
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,26 @@
1
+ class CreateSubscriptionsSubscriptions < ActiveRecord::Migration
2
+
3
+ def up
4
+ create_table :refinery_subscriptions do |t|
5
+ t.string :email
6
+ t.integer :position
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ end
12
+
13
+ def down
14
+ if defined?(::Refinery::UserPlugin)
15
+ ::Refinery::UserPlugin.destroy_all({:name => "refinerycms-subscriptions"})
16
+ end
17
+
18
+ if defined?(::Refinery::Page)
19
+ ::Refinery::Page.delete_all({:link_url => "/subscriptions/subscriptions"})
20
+ end
21
+
22
+ drop_table :refinery_subscriptions
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ (Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : [:en]).each do |lang|
2
+ I18n.locale = lang
3
+
4
+ if defined?(Refinery::User)
5
+ Refinery::User.all.each do |user|
6
+ if user.plugins.where(:name => 'refinerycms-subscriptions').blank?
7
+ user.plugins.create(:name => 'refinerycms-subscriptions',
8
+ :position => (user.plugins.maximum(:position) || -1) +1)
9
+ end
10
+ end
11
+ end
12
+
13
+ url = "/subscriptions"
14
+ if defined?(Refinery::Page) && Refinery::Page.where(:link_url => url).empty?
15
+ page = Refinery::Page.create(
16
+ :title => 'Subscriptions',
17
+ :link_url => url,
18
+ :deletable => false,
19
+ :menu_match => "^#{url}(\/|\/.+?|)$"
20
+ )
21
+ Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
22
+ page.parts.create(:title => default_page_part, :body => nil, :position => index)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ module Refinery
2
+ class SubscriptionsGenerator < Rails::Generators::Base
3
+
4
+ def rake_db
5
+ rake "refinery_subscriptions:install:migrations"
6
+ rake "refinery_settings:install:migrations"
7
+ end
8
+
9
+ def append_load_seed_data
10
+ create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
11
+ append_file 'db/seeds.rb', :verbose => true do
12
+ <<-EOH
13
+
14
+ # Added by Refinery CMS Subscriptions extension
15
+ Refinery::Subscriptions::Engine.load_seed
16
+ EOH
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'refinerycms-core'
2
+ require 'refinerycms-settings'
3
+
4
+ module Refinery
5
+ autoload :SubscriptionsGenerator, 'generators/refinery/subscriptions_generator'
6
+
7
+ module Subscriptions
8
+ require 'refinery/subscriptions/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
@@ -0,0 +1,27 @@
1
+ module Refinery
2
+ module Subscriptions
3
+ class Engine < Rails::Engine
4
+ include Refinery::Engine
5
+ isolate_namespace Refinery::Subscriptions
6
+
7
+ engine_name :refinery_subscriptions
8
+
9
+ initializer "register refinerycms_subscriptions plugin" do
10
+ Refinery::Plugin.register do |plugin|
11
+ plugin.name = "subscriptions"
12
+ plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.subscriptions_admin_subscriptions_path }
13
+ plugin.pathname = root
14
+ plugin.activity = {
15
+ :class_name => :'refinery/subscriptions/subscription',
16
+ :title => 'email'
17
+ }
18
+
19
+ end
20
+ end
21
+
22
+ config.after_initialize do
23
+ Refinery.register_extension(Refinery::Subscriptions)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require 'refinery/subscriptions'
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :subscriptions do
4
+
5
+ # call this task by running: rake refinery:subscriptions:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,10 @@
1
+ # Subscriptions extension for Refinery CMS.
2
+
3
+ ## How to build this extension as a gem
4
+
5
+ cd vendor/extensions/subscriptions
6
+ gem build refinerycms-subscriptions.gemspec
7
+ gem install refinerycms-subscriptions.gem
8
+
9
+ # Sign up for a http://rubygems.org/ account and publish the gem
10
+ gem push refinerycms-subscriptions.gem
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-subscriptions
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Refactorit
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: refinerycms-core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: refinerycms-settings
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: refinerycms-testing
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.10
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.10
62
+ description: Ruby on Rails Subscriptions extension for Refinery CMS
63
+ email:
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - app/models/refinery/subscriptions/subscription.rb
69
+ - app/models/refinery/subscriptions/setting.rb
70
+ - app/controllers/refinery/subscriptions/subscriptions_controller.rb
71
+ - app/controllers/refinery/subscriptions/admin/subscriptions_controller.rb
72
+ - app/views/refinery/subscriptions/subscriptions/new.html.erb
73
+ - app/views/refinery/subscriptions/subscriptions/thank_you.html.erb
74
+ - app/views/refinery/subscriptions/shared/_subscription.html.erb
75
+ - app/views/refinery/subscriptions/subscription_mailer/notification.text.erb
76
+ - app/views/refinery/subscriptions/admin/subscriptions/new.html.erb
77
+ - app/views/refinery/subscriptions/admin/subscriptions/edit.html.erb
78
+ - app/views/refinery/subscriptions/admin/subscriptions/_subscription.html.erb
79
+ - app/views/refinery/subscriptions/admin/subscriptions/_subscriptions.html.erb
80
+ - app/views/refinery/subscriptions/admin/subscriptions/_actions.html.erb
81
+ - app/views/refinery/subscriptions/admin/subscriptions/_sortable_list.html.erb
82
+ - app/views/refinery/subscriptions/admin/subscriptions/_form.html.erb
83
+ - app/views/refinery/subscriptions/admin/subscriptions/index.html.erb
84
+ - app/views/refinery/subscriptions/admin/subscriptions/_records.html.erb
85
+ - app/mailers/refinery/subscriptions/subscription_mailer.rb
86
+ - config/locales/en.yml
87
+ - config/locales/hr.yml
88
+ - config/routes.rb
89
+ - db/migrate/1_create_subscriptions_subscriptions.rb
90
+ - db/seeds.rb
91
+ - lib/refinerycms-subscriptions.rb
92
+ - lib/generators/refinery/subscriptions_generator.rb
93
+ - lib/refinery/subscriptions.rb
94
+ - lib/refinery/subscriptions/engine.rb
95
+ - lib/tasks/refinery/subscriptions.rake
96
+ - readme.md
97
+ homepage:
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.23
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Subscriptions extension for Refinery CMS
121
+ test_files: []
122
+ has_rdoc: