Skip to content
Browse files

Added Flash helper.

  • Loading branch information...
1 parent 10031f7 commit 3d4c391ca203c034214f42cc33132c7cd158c95f @DAddYE DAddYE committed
View
2 README.rdoc
@@ -29,4 +29,4 @@ In your Padrino project edit:
# app.rb
class MyApp < Padrino::Application
register Padrino::Contrib::ExceptionNotifier
- end
+ end
View
11 lib/padrino-contrib.rb
@@ -8,6 +8,15 @@ module Contrib
module Helpers
autoload :AssetsCompressor, 'padrino-contrib/helpers/assets_compressor.rb'
autoload :JQuery, 'padrino-contrib/helpers/jquery.rb'
+ autoload :Flash, 'padrino-contrib/helpers/flash.rb'
end # Helpers
end # Contrib
-end # Padrino
+end # Padrino
+
+if defined?(ActiveRecord)
+ Dir[File.join(File.expand_path('../', __FILE__), '/padrino-contrib/orm/active_record/**/*.rb')].each { |d| require d }
+end
+
+if defined?(MongoMapper)
+ Dir[File.join(File.expand_path('../', __FILE__), '/padrino-contrib/orm/mongo_mapper/**/*.rb')].each { |d| require d }
+end
View
6 lib/padrino-contrib/auto_locale.rb
@@ -22,7 +22,7 @@ module Helpers
# This reload the page changing the I18n.locale
#
def switch_to_lang(lang)
- request.path_info.sub(/\/#{I18n.locale}/, "/#{lang}") if options.locales.include?(lang)
+ request.path_info.sub(/\/#{I18n.locale}/, "/#{lang}") if settings.locales.include?(lang)
end
end # Helpers
@@ -31,10 +31,10 @@ def self.registered(app)
app.extend ClassMethods
app.set :locales, [:en]
app.before do
- if request.path_info =~ /^\/(#{options.locales.join('|')})\b/
+ if request.path_info =~ /^\/(#{settings.locales.join('|')})\b/
I18n.locale = $1.to_sym
else
- I18n.locale = options.locales[0]
+ I18n.locale = settings.locales[0]
not_found if request.path_info !~ /^\/?$/
end
end
View
10 lib/padrino-contrib/exception_notifier.rb
@@ -20,11 +20,11 @@ module Contrib
module ExceptionNotifier
def self.registered(app)
- app.set :exceptions_subject, "Exception"
- app.set :exceptions_to, "errors@localhost.local"
- app.set :exceptions_from, "foo@bar.local"
- app.set :exceptions_layout, :layout
- app.set :redmine, {}
+ app.set :exceptions_subject, "Exception" unless app.respond_to?(:exceptions_subject)
+ app.set :exceptions_to, "errors@localhost.local" unless app.respond_to?(:exceptions_to)
+ app.set :exceptions_from, "foo@bar.local" unless app.respond_to?(:exceptions_from)
+ app.set :exceptions_layout, :layout unless app.respond_to?(:exceptions_layout)
+ app.set :redmine, {} unless app.respond_to?(:redmine)
app.error 500 do
boom = env['sinatra.error']
body = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n ")
View
2 lib/padrino-contrib/flash_session.rb
@@ -34,4 +34,4 @@ def call(env)
end
end # FlashSession
end # Contrib
-end # Padrino
+end # Padrino
View
2 lib/padrino-contrib/helpers/assets_compressor.rb
@@ -148,4 +148,4 @@ def find_last_modified(file)
end # AssetsCompressor
end # Helpers
end # Contrib
-end # Padrino
+end # Padrino
View
32 lib/padrino-contrib/helpers/flash.rb
@@ -0,0 +1,32 @@
+module Padrino
+ module Contrib
+ module Helpers
+ ##
+ # Dead simple version of rack-flash.
+ # You still use flash without session, but remember that
+ # they can't work after a redirect.
+ #
+ # ==== Usage:
+ #
+ # register Padrino::Contrib::Helpers::Flash
+ #
+ module Flash
+ def self.register(app)
+ app.before { @_flash, session[:_flash] = session[:_flash], nil if settings.sessions? && session[:_flash] }
+ app.helpers InstanceMethods
+ end
+
+ module InstanceMethods
+ def flash
+ @_flash ||= {}
+ end
+
+ def redirect(uri, *args)
+ session[:_flash] = @_flash if settings.sessions? && flash.present?
+ super(uri, *args)
+ end
+ end
+ end # Flash
+ end # Helpers
+ end # Contrib
+end # Padrino
View
2 lib/padrino-contrib/helpers/jquery.rb
@@ -59,4 +59,4 @@ def javascript_include_tag_jquery(options={})
end # JQuery
end # Helpers
end # Contrib
-end # Padrino
+end # Padrino
View
2 lib/padrino-contrib/orm/active_record/permalink.rb
@@ -38,7 +38,7 @@ def generate_permalink
end
end # InstanceMethods
end # Permalink
- end # Ar
+ end # ActiveRecord
end # Orm
end # Contrib
end # Padrino
View
2 lib/padrino-contrib/orm/active_record/permalink_i18n.rb
@@ -56,7 +56,7 @@ def generate_permalinks
end
end # InstanceMethods
end # PemalinkI18n
- end # Ar
+ end # ActiveRecord
end # Orm
end # Contrib
end # Padrino
View
7 lib/padrino-contrib/orm/active_record/textile.rb
@@ -1,5 +1,3 @@
-require 'RedCloth'
-
module Padrino
module Contrib
module Orm
@@ -18,6 +16,7 @@ module ActiveRecord
module Textile
module ClassMethods
def has_textile(*fields)
+ require 'RedCloth'
include InstanceMethods
options = fields.extract_options!
options.reverse_merge!(:internal_links => :blog)
@@ -52,8 +51,8 @@ def generate_textile
end
end
end # InstanceMethods
- end # Permalink
- end # Ar
+ end # Textile
+ end # ActiveRecord
end # Orm
end # Contrib
end # Padrino
View
6 lib/padrino-contrib/orm/active_record/translate.rb
@@ -35,9 +35,9 @@ def method_missing(method_name, *arguments)
super
end
end # InstanceMethods
- end # ArTranslate
- end # Ar
+ end # Translate
+ end # ActiveRecord
end # Orm
end # Contrib
end # Padrino
-::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Translate::ClassMethods)
+::ActiveRecord::Base.extend(Padrino::Contrib::Orm::ActiveRecord::Translate::ClassMethods)
View
2 lib/padrino-contrib/orm/mongo_mapper/permalink.rb
@@ -47,7 +47,7 @@ def generate_permalink
end
end # InstanceMethods
end # Permalink
- end # Mm
+ end # MongoMapper
end # Orm
end # Contrib
end # Padrino
View
2 lib/padrino-contrib/orm/mongo_mapper/search.rb
@@ -32,7 +32,7 @@ def search(text, options={})
end
end
end # Permalink
- end # Mm
+ end # MongoMapper
end # Orm
end # Contrib
end # Padrino
View
2 spec/autoload_spec.rb
@@ -18,4 +18,4 @@
it(klass) { eval("#{klass}").should be_true }
end
-end
+end
View
2 spec/spec_helper.rb
@@ -1,3 +1,3 @@
require 'rubygems' unless defined?(Gem)
require 'rspec' unless defined?(RSpec)
-require 'padrino-contrib'
+require 'padrino-contrib'

0 comments on commit 3d4c391

Please sign in to comment.
Something went wrong with that request. Please try again.