sooner 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module Sooner
2
2
  class SubscribersController < ApplicationController
3
-
3
+
4
4
  unloadable
5
5
 
6
6
  def new
@@ -9,19 +9,23 @@ module Sooner
9
9
 
10
10
  def create
11
11
  @subscriber = Subscriber.new(params[:sooner_subscriber])
12
-
13
- respond_to do |format|
12
+ if @subscriber.valid?
14
13
  if Sooner.csv_store
15
- result = @subscriber.save_csv
14
+ @subscriber.save_csv
16
15
  end
17
16
  if Sooner.db_store
18
- result = @subscriber.save
17
+ @subscriber.save
18
+ end
19
+ render :update do |page|
20
+ page.replace_html 'sooner_subscriber', Sooner.subscribed
19
21
  end
20
- if result
21
- format.html { render :partial => "subscribed" }
22
- else
23
- format.html { render :partial => "already_subscribed" }
22
+ elsif @subscriber.errors[:name].include?('has already been taken') || @subscriber.errors[:email].include?('has already been taken')
23
+ render :update do |page|
24
+ page.replace_html 'sooner_subscriber', Sooner.already_subscribed
24
25
  end
26
+ else
27
+ flash[:notice] = Sooner.error_subscribed
28
+ redirect_to new_subscriber_path
25
29
  end
26
30
  end
27
31
  end
@@ -8,7 +8,7 @@ module Sooner
8
8
  def save_csv
9
9
  begin
10
10
  file = File.open("public/#{ Sooner.csv_file.nil? ? 'subscribers.csv' : Sooner.csv_file }", "a")
11
- file << "#{ email }\n"
11
+ file << "#{ name },#{ email }\n"
12
12
  file.close
13
13
  return true
14
14
  rescue Exception => e
@@ -1,11 +1,11 @@
1
- <h2>Add to subscriber List</h2>
1
+ <div id="sooner_subscriber">
2
+ <%= form_for @subscriber, :url => subscribers_path, :remote => true do |f| %>
3
+ <%= f.label :name %>
4
+ <%= f.text_field :name %>
5
+ <br />
6
+ <%= f.label :email %>
7
+ <%= f.text_field :email %>
2
8
 
3
- <%= form_for @subscriber, :url => subscribers_path do |f| %>
4
- <%= f.label :name %>
5
- <%= f.text_field :name %>
6
- <br />
7
- <%= f.label :email %>
8
- <%= f.text_field :email %>
9
-
10
- <%= f.submit "Subscribe" %>
11
- <% end %>
9
+ <%= f.submit "Subscribe" %>
10
+ <% end %>
11
+ </div>
@@ -1,7 +1,7 @@
1
1
  class SoonerInstallGenerator < Rails::Generators::Base
2
2
  include Rails::Generators::Migration
3
3
 
4
- desc "Creates a Sooner initializer and copy locale files to your application."
4
+ desc "Creates a Sooner initializer and migration to your application."
5
5
 
6
6
  def self.source_root
7
7
  @_sooner_source_root ||= File.expand_path("../templates", __FILE__)
@@ -30,10 +30,6 @@ class SoonerInstallGenerator < Rails::Generators::Base
30
30
  template "sooner.rb", "config/initializers/sooner.rb"
31
31
  end
32
32
 
33
- # def copy_locale
34
- # copy_file "../../../../config/locales/en.yml", "config/locales/sooner.en.yml"
35
- # end
36
-
37
33
  def show_readme
38
34
  readme "README"
39
35
  end
@@ -7,4 +7,17 @@ Some setup you must do manually if you haven't yet:
7
7
 
8
8
  root :to => "sooner/subscribers#new"
9
9
 
10
+ 2. Ensure you have defined javascript in app/views/layouts/application.html.erb
11
+
12
+ <%= javascript_include_tag :defaults %>
13
+ <!-- or -->
14
+ <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "jquery.rails.js" %>
15
+
16
+ <%= csrf_meta_tag %>
17
+
18
+ 3. Ensure you have flash messages in app/views/layouts/application.html.erb.
19
+ For example:
20
+
21
+ <p class="notice"><%= notice %></p>
22
+
10
23
  ===============================================================================
@@ -5,4 +5,9 @@ Sooner.setup do |config|
5
5
  config.db_store = true
6
6
  config.csv_store = true
7
7
  config.csv_file = "subscribers.csv"
8
- end
8
+
9
+ # Messages.
10
+ config.subscribed = 'Subscribed Successfully.'
11
+ config.already_subscribed = 'Already Subscribed.'
12
+ config.error_subscribed = 'Please Try to subscribe again.'
13
+ end
data/lib/sooner/rails.rb CHANGED
@@ -1,33 +1,5 @@
1
- #require 'devise/rails/routes'
2
- #require 'devise/rails/warden_compat'
3
-
4
- # Include UrlHelpers in ActionController and ActionView as soon as they are loaded.
5
- #ActiveSupport.on_load(:action_controller) { include Devise::Controllers::UrlHelpers }
6
- #ActiveSupport.on_load(:action_view) { include Devise::Controllers::UrlHelpers }
7
-
8
1
  module Sooner
9
2
  class Engine < ::Rails::Engine
10
3
  config.sooner = Sooner
11
-
12
- config.after_initialize do
13
- flash = [:successfull, :unsuccessful]
14
-
15
- translations = begin
16
- I18n.available_locales
17
- I18n.backend.send(:translations)
18
- rescue Exception => e # Do not care if something fails
19
- {}
20
- end
21
-
22
- translations.each do |locale, translations|
23
- keys = flash & (translations[:sooner][:sessions].keys) rescue []
24
-
25
- if keys.any?
26
- ActiveSupport::Deprecation.warn "The following I18n messages in 'devise.sessions' " <<
27
- "for locale '#{locale}' are deprecated: #{keys.to_sentence}. Please move them to " <<
28
- "'sooner.failure' instead."
29
- end
30
- end
31
- end
32
4
  end
33
5
  end
@@ -1,3 +1,3 @@
1
1
  module Sooner
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  end
data/lib/sooner.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  module Sooner
2
2
 
3
- # True values used to check params
4
- TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE']
5
-
6
3
  # Custom domain for cookies. Not set by default
7
4
  mattr_accessor :db_store
8
5
  @@db_store = true
@@ -19,6 +16,16 @@ module Sooner
19
16
  mattr_accessor :mailer_sender
20
17
  @@mailer_sender = nil
21
18
 
19
+ # Messages
20
+ mattr_accessor :subscribed
21
+ @@subscribed = 'Subscribed Successfully.'
22
+
23
+ mattr_accessor :already_subscribed
24
+ @@already_subscribed = 'Already Subscribed.'
25
+
26
+ mattr_accessor :error_subscribed
27
+ @@error_subscribed = 'Please Try to subscribe again.'
28
+
22
29
  # Default way to setup Sooner. Run rails generate sooner_install to create
23
30
  # a fresh initializer with all configuration values.
24
31
  def self.setup
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 6
9
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Shenouda Bertel
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-06-07 00:00:00 +03:00
17
+ date: 2010-06-08 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -33,12 +33,8 @@ files:
33
33
  - MIT-LICENSE
34
34
  - Rakefile
35
35
  - app/controllers/sooner/subscribers_controller.rb
36
- - app/views/sooner/subscribers/_subscribed.html.erb
37
36
  - app/views/sooner/subscribers/new.html.erb
38
- - app/views/sooner/subscribers/_already_subscribed.html.erb
39
- - app/views/sooner/subscribers/_unsubscribed.html.erb
40
37
  - app/models/sooner/subscriber.rb
41
- - config/locales/en.yml
42
38
  - config/routes.rb
43
39
  - lib/generators/sooner_install/templates/sooner.rb
44
40
  - lib/generators/sooner_install/templates/migration.rb
@@ -1 +0,0 @@
1
- <%= "Already Subscribed" %>
@@ -1 +0,0 @@
1
- <%= "Subscribed" %>
@@ -1 +0,0 @@
1
- <%= "UnSubscribed" %>
@@ -1,10 +0,0 @@
1
- en:
2
- errors:
3
- messages:
4
- not_found: "not found"
5
- already_confirmed: "was already confirmed"
6
- not_locked: "was not locked"
7
-
8
- sooner:
9
- succesfull: 'You need to sign in or sign up before continuing.'
10
- unsuccessfull: 'You have to confirm your account before continuing.'