easy_flash 0.0.0 → 0.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.
@@ -1,3 +1,3 @@
1
1
  module EasyFlash
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  end
data/lib/easy_flash.rb CHANGED
@@ -2,7 +2,102 @@ module EasyFlash
2
2
  require 'easy_flash/engine'
3
3
  require 'easy_flash/version'
4
4
 
5
- def self.message?
6
- puts "Flash Message Method!!"
5
+ def self.message?
6
+ Rails.logger.debug()
7
+ puts "Flash Message Method!!"
8
+ end
9
+
10
+ def self.flash_helper(instance_variable = nil)
11
+
12
+ Rails.logger.debug("------------- flash helper method from easy flash gem ---------------------")
13
+ Rails.logger.debug(instance_variable.inspect)
14
+ fl = ''
15
+
16
+ if instance_variable && instance_variable.errors.any?
17
+ fl += "<div class='error'>"
18
+ fl += "<h2>#{pluralize(instance_variable.errors.count, "error")} prohibited this form from being submitted:</h2>"
19
+ fl += "<ul>"
20
+ instance_variable.errors.full_messages.each do |error|
21
+ fl += "<li>#{error}</li>"
22
+ end
23
+ fl += "</ul></div>"
24
+ else
25
+ f_names = [:error, :notice, :warning, :message]
26
+
27
+ for name in f_names
28
+ unless flash[name].nil? || flash[name].empty?
29
+ fl += "<div class='#{name}'><ul>"
30
+
31
+ # if it is an array, print each element
32
+ if flash[name].is_a?(Array)
33
+ Rails.logger.debug("Yes, it is an array")
34
+ flash[name].each do |message|
35
+ fl += "<li>#{message}</li>"
36
+ end
37
+ else #if it is a single value, print that
38
+ Rails.logger.debug(flash[name])
39
+ fl += "<li>#{flash[name]}</li>"
40
+ end
41
+
42
+ fl += "</ul></div>"
43
+ end
44
+ flash[name] = nil
45
+ end
46
+ end
47
+
48
+ fl = "<div class =\"custom_helper_flash\">" + fl + "</div>" unless fl.empty?
49
+
50
+ fl.html_safe
51
+
52
+ #rescue
53
+ # ""
54
+ end
55
+
56
+ def self.set_error(error)
57
+ if flash[:error].nil?
58
+ flash[:error] = error
59
+ else
60
+ flash[:error] << error
7
61
  end
62
+ end
63
+
64
+ def self.set_notice(notice)
65
+ if flash[:notice].nil?
66
+ flash[:notice] = notice
67
+ else
68
+ flash[:notice] << notice
69
+ end
70
+ end
71
+
72
+ def self.set_warning(warning)
73
+ if flash[:warning].nil?
74
+ flash[:warning] = warning
75
+ else
76
+ flash[:warning] << warning
77
+ end
78
+ end
79
+
80
+ def self.set_message(message)
81
+ if flash[:message].nil?
82
+ flash[:message] = message
83
+ else
84
+ flash[:message] << message
85
+ end
86
+ end
87
+
88
+ def self.empty_error()
89
+ flash[:error] = nil
90
+ end
91
+
92
+ def self.empty_notice()
93
+ flash[:notice] = nil
94
+ end
95
+
96
+ def self.empty_warning()
97
+ flash[:warning] = nil
98
+ end
99
+
100
+ def self.empty_message()
101
+ flash[:message] = nil
102
+ end
8
103
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: