scintillation 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -36,11 +36,7 @@ task :default => :spec
36
36
 
37
37
  require 'rake/rdoctask'
38
38
  Rake::RDocTask.new do |rdoc|
39
- if File.exist?('VERSION')
40
- version = File.read('VERSION')
41
- else
42
- version = ""
43
- end
39
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
40
 
45
41
  rdoc.rdoc_dir = 'rdoc'
46
42
  rdoc.title = "scintillation #{version}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
data/lib/scintillation.rb CHANGED
@@ -1,40 +1,63 @@
1
1
  module Scintillation
2
2
 
3
- module ControllerHelpers
3
+ def self.included(base)
4
+ base.include(Controller)
5
+ end
6
+
7
+ module Controller
4
8
  def self.included(base)
5
- base.helper_method(:messages)
6
- base.before_filter { |c| c.send(:flash).each { |t, m| c.messages.add(m, t) } }
9
+ base.extend(ClassMethods)
7
10
  end
8
11
 
9
- def messages
10
- @messages ||= Scintillation::SessionMessages.new(session)
12
+ module ClassMethods
13
+ def scintillate(options => {})
14
+ include InstanceMethods
15
+ ActionView::Base.send(:include, Scintillation::View)
16
+
17
+ # import flash messages
18
+ before_filter { |c| c.send(:flash).each { |t, m| c.messages.add(m, t) } }
19
+
20
+ helper_method :messages
21
+
22
+ define_method(:messages) do
23
+ @messages ||= Scintillation::SessionMessages.new(session, :scope => options[:scope])
24
+ end
25
+ end
11
26
  end
12
27
 
13
- def method_missing(method, *args, &block)
14
- if /^((\w+)_)?msg(_for_(\w+))?$/.match(method.to_s)
15
- messages.add(args[0], $2, $4)
16
- elsif /^((\w+)_)?msgs$/.match(method.to_s)
17
- messages.get($2)
18
- else
19
- super
28
+ module InstanceMethods
29
+ def method_missing(method, *args, &block)
30
+ if /^((\w+)_)?msg(_for_(\w+))?$/.match(method.to_s)
31
+ messages.add(args[0], $2, $4)
32
+ elsif /^((\w+)_)?msgs$/.match(method.to_s)
33
+ messages.get($2)
34
+ else
35
+ super
36
+ end
20
37
  end
21
38
  end
22
39
  end
23
40
 
24
41
  ##################################################
25
42
 
26
- module ViewHelpers
27
- def method_missing(method, *args, &block)
28
- if /^((\w+)_)?msgs$/.match(method.to_s)
29
- messages.get($2)
30
- else
31
- super
32
- end
43
+ module View
44
+ def self.included(base)
45
+ base.include(InstanceMethods)
33
46
  end
34
47
 
35
- def display_messages(msgs)
36
- unless msgs.empty?
37
- "<ul>\n " + msgs.map { |m| "<li class=\"#{m.tone}\">#{m}</li>" }.join("\n ") + "\n</ul>"
48
+ module InstanceMethods
49
+ def method_missing(method, *args, &block)
50
+ if /^((\w+)_)?msgs$/.match(method.to_s)
51
+ messages.get($2)
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ def display_messages(msgs)
58
+ unless msgs.empty?
59
+ "<ul>\n " + msgs.map { |m| "<li class=\"#{m.tone}\">#{m}</li>" }.join("\n ") + "\n</ul>"
60
+ end
38
61
  end
39
62
  end
40
63
  end
@@ -42,17 +65,22 @@ module Scintillation
42
65
  ##################################################
43
66
 
44
67
  class SessionMessages
45
- def initialize(session)
68
+ def initialize(session, options = {})
69
+ options.reverse_merge!(:scope => :messages)
46
70
  @session = session
47
- @session[:messages] ||= {}
71
+ @session_scope = options[:scope]
48
72
  @temp_msgs = {}
49
73
  end
50
74
 
75
+ def msgs
76
+ @session[@session_scope] ||= {}
77
+ end
78
+
51
79
  def add(obj, tone = nil, scope = nil)
52
- @session[:messages][scope.to_s] ||= []
80
+ msgs[scope.to_s] ||= []
53
81
 
54
82
  case obj
55
- when String, Symbol then @session[:messages][scope.to_s] << Scintillation::Message.new(obj, tone)
83
+ when String, Symbol then msgs[scope.to_s] << Scintillation::Message.new(obj, tone)
56
84
  when ActiveRecord::Errors then add(obj.full_messages, tone, scope)
57
85
  when Enumerable then obj.each { |o| add(o, tone, scope) }
58
86
  else add(obj.to_s, tone, scope)
@@ -60,7 +88,7 @@ module Scintillation
60
88
  end
61
89
 
62
90
  def get(scope = nil)
63
- @temp_msgs[scope.to_s] ||= (@session[:messages].delete(scope.to_s) || [])
91
+ @temp_msgs[scope.to_s] ||= (msgs.delete(scope.to_s) || [])
64
92
  end
65
93
  end
66
94
 
@@ -70,7 +98,7 @@ module Scintillation
70
98
 
71
99
  end
72
100
 
73
- if defined? Rails
101
+ if defined?(Rails)
74
102
  #a fix until they patch
75
103
  module ActionController
76
104
  class Base
@@ -82,6 +110,5 @@ if defined? Rails
82
110
  end
83
111
  end
84
112
 
85
- ActionController::Base.send(:include, Scintillation::ControllerHelpers)
86
- ActionView::Base.send(:include, Scintillation::ViewHelpers)
113
+ ActionController::Base.send(:include, Scintillation)
87
114
  end
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scintillation}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Austin Schneider"]
12
- s.date = %q{2009-10-16}
12
+ s.date = %q{2010-03-31}
13
13
  s.description = %q{A flash messages replacement}
14
14
  s.email = %q{soccer022483@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
31
31
  s.homepage = %q{http://gemcutter.org/gems/scintillation}
32
32
  s.rdoc_options = ["--charset=UTF-8"]
33
33
  s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.5}
34
+ s.rubygems_version = %q{1.3.6}
35
35
  s.summary = %q{A flash messages replacement}
36
36
  s.test_files = [
37
37
  "spec/scintillation_spec.rb",
@@ -51,3 +51,4 @@ Gem::Specification.new do |s|
51
51
  s.add_dependency(%q<rspec>, [">= 0"])
52
52
  end
53
53
  end
54
+
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scintillation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Austin Schneider
@@ -9,19 +14,21 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-16 00:00:00 -04:00
17
+ date: 2010-03-31 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  description: A flash messages replacement
26
33
  email: soccer022483@gmail.com
27
34
  executables: []
@@ -55,18 +62,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
62
  requirements:
56
63
  - - ">="
57
64
  - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
58
67
  version: "0"
59
- version:
60
68
  required_rubygems_version: !ruby/object:Gem::Requirement
61
69
  requirements:
62
70
  - - ">="
63
71
  - !ruby/object:Gem::Version
72
+ segments:
73
+ - 0
64
74
  version: "0"
65
- version:
66
75
  requirements: []
67
76
 
68
77
  rubyforge_project:
69
- rubygems_version: 1.3.5
78
+ rubygems_version: 1.3.6
70
79
  signing_key:
71
80
  specification_version: 3
72
81
  summary: A flash messages replacement