show_message 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -19,7 +19,23 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- TODO: Write usage instructions here
22
+ Add this code where you want your error messages to be shown.
23
+
24
+ ```erb
25
+ <%= show_message %>
26
+ ```
27
+
28
+ Set a message in your controller.
29
+
30
+ ```ruby
31
+ class MyController
32
+
33
+ def test_function
34
+ flash[:error] = "Some Error Message"
35
+ end
36
+
37
+ end
38
+ ```
23
39
 
24
40
  ## Contributing
25
41
 
@@ -1,7 +1,8 @@
1
1
  <% data.each do |m| %>
2
- <div class="alert-box <%= m[:class] %> <%= "autohide" if options[:autohide] %>" style= "<%= (m != data.last) ? "margin-bottom:5px;" : "" %>">
2
+ <div class="alert-box <%= m[:class] %>" style= "<%= (m != data.last) ? "margin-bottom:5px;" : "" %>">
3
3
  <div class="message">
4
4
  <%= raw m[:message] %>
5
5
  </div>
6
6
  </div>
7
- <% end %>
7
+ <% end %>
8
+ <div style="margin-top:#{options[:space]}px;"></div>
@@ -1,3 +1,3 @@
1
1
  module ShowMessage
2
- VERSION = [0, 0, 1].join "."
2
+ VERSION = [0, 0, 2].join "."
3
3
  end
@@ -1,43 +1,42 @@
1
1
  module ShowMessage
2
2
  module ViewHelpers
3
3
 
4
- def show_message(options = {}, *args)
5
-
6
- options = {autohide: false}.merge!(options)
7
- if options[:id].present?
8
- class_mappings = {"success_#{options[:id]}".to_sym => "success", "error_#{options[:id]}".to_sym => "error", "warning_#{options[:id]}".to_sym => "warning", "info_#{options[:id]}".to_sym => "info"}
9
- flash_is_empty = false
10
- class_mappings.each_key do |k|
11
- flash_is_empty = false unless flash[k].nil?
12
- end
13
- return if flash_is_empty
14
- else
15
- class_mappings = {:success => "success", :error => "error", :warning => "warning", :info => "info"}
4
+ def show_message(options = {})
5
+
6
+ scope = options[:id]
7
+
8
+
9
+ if scope.present?
10
+ flash_is_empty = false
11
+ flash.keys.each do |k|
12
+ puts k.to_s.index(scope.to_s).present?
13
+ flash_is_empty = true unless k.to_s.index(scope.to_s).present?
16
14
  end
15
+ return if flash_is_empty
16
+ end
17
17
 
18
- data = []
19
18
 
20
- class_mappings.each_key do |k|
21
- if flash[k].kind_of?(Array)
22
- if flash[k]
23
- flash[k].each do |m|
24
- data << {:message => m, :class => class_mappings[k]}
25
- end
19
+ data = []
20
+
21
+ flash.each do |k, v|
22
+ f = flash[k]
23
+ if f.kind_of?(Array)
24
+ if f
25
+ f.each do |m|
26
+ data << {message: m, class: k.to_s.split("_").first}
26
27
  end
27
- else
28
- if flash[k]
29
- data << {:message => flash[k], :class => class_mappings[k]}
30
- end
31
- end
32
- end
33
- args.each do |k|
34
- data << k
28
+ end
29
+ else
30
+ if f
31
+ data << {message: v, class: k.to_s.split("_").first}
32
+ end
35
33
  end
36
- class_mappings.each_key { |k| flash[k] = nil }
37
34
 
38
- render partial: "show_message/show_message", locals: {data: data, options: options}
39
-
35
+ flash.discard(k)
40
36
  end
41
37
 
38
+ render partial: "show_message/show_message", locals: {data: data, options: options}
39
+ end
40
+
42
41
  end
43
42
  end
data/show_message.gemspec CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |spec|
7
7
  spec.version = ShowMessage::VERSION
8
8
  spec.authors = ["Jarrett Lusso"]
9
9
  spec.email = ["jarrett@graphicflash.com"]
10
- spec.description = %q{show-message makes it easy to output your flash[:success], flash[:error] or flash[:whatever] to the view using one simple helper.}
11
- spec.summary = %q{show-message makes it easy to output your flash[:success], flash[:error] or flash[:whatever] to the view using one simple helper.}
10
+ spec.description = %q{show_message makes it easy to output your flash[:success], flash[:error] or flash[:whatever] to the view using one simple helper.}
11
+ spec.summary = %q{show_message makes it easy to output your flash[:success], flash[:error] or flash[:whatever] to the view using one simple helper.}
12
12
  spec.homepage = "http://github.com/jclusso/show_message"
13
13
  spec.license = "MIT"
14
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: show_message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,7 @@ dependencies:
43
43
  - - '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- description: show-message makes it easy to output your flash[:success], flash[:error]
46
+ description: show_message makes it easy to output your flash[:success], flash[:error]
47
47
  or flash[:whatever] to the view using one simple helper.
48
48
  email:
49
49
  - jarrett@graphicflash.com
@@ -88,6 +88,6 @@ rubyforge_project:
88
88
  rubygems_version: 1.8.25
89
89
  signing_key:
90
90
  specification_version: 3
91
- summary: show-message makes it easy to output your flash[:success], flash[:error]
91
+ summary: show_message makes it easy to output your flash[:success], flash[:error]
92
92
  or flash[:whatever] to the view using one simple helper.
93
93
  test_files: []