immosquare-extensions 0.1.24 → 0.1.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-extensions/application_record.rb +15 -0
- data/lib/immosquare-extensions/railtie.rb +6 -3
- data/lib/immosquare-extensions/version.rb +1 -1
- data/lib/immosquare-extensions.rb +11 -1
- metadata +3 -3
- data/lib/immosquare-extensions/helpers/preview_mailer_helper.rb +0 -207
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0553e2e647c71c0afd72090399cbdc933659fde01e8daf8f7ff0a75fbfd8c333
|
4
|
+
data.tar.gz: 64e97c458e494e7c1651532c24dec6ba017b69d010190acd5bf27bb9f639a1c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 263bc2dc0631004a0f0e20c7b24728833dd63d6ca1c280f6adf269e36c871c612c75173099e4afba2cc7cf335826e069d9be01c8277a8de59fd2664c41e95e7f
|
7
|
+
data.tar.gz: 626f8fab96fe0b7cbc1b394b43e8cd93bf626da03f436a6426e1eea460c660eff143cad2e3654cc00433ecf53724a2bdc49ab17f94e37056ef702c1ac9262fa7
|
@@ -0,0 +1,15 @@
|
|
1
|
+
|
2
|
+
module ImmosquareExtensions
|
3
|
+
module ApplicationRecord
|
4
|
+
##============================================================##
|
5
|
+
## On ajoute une méthode dig pour pouvoir accéder à des
|
6
|
+
## attributs imbriqués sans avoir à vérifier si les objets
|
7
|
+
## user.dig(:user_profile, :user_card_type, :slug)
|
8
|
+
##============================================================##
|
9
|
+
def dig(*keys)
|
10
|
+
keys.reduce(self) do |obj, key|
|
11
|
+
obj.respond_to?(key) ? obj.send(key) : nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -3,9 +3,12 @@ require "rails"
|
|
3
3
|
module ImmosquareExtensions
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
|
6
|
-
initializer "immosquare_extensions.
|
7
|
-
ActiveSupport.on_load(:
|
8
|
-
|
6
|
+
initializer "immosquare_extensions.active_record" do
|
7
|
+
ActiveSupport.on_load(:active_record) do
|
8
|
+
##============================================================##
|
9
|
+
## Pour ajouter des méthodes à ActiveRecord::Base
|
10
|
+
##============================================================##
|
11
|
+
ActiveRecord::Base.include(ImmosquareExtensions::ApplicationRecord)
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
@@ -1,9 +1,19 @@
|
|
1
|
+
##============================================================##
|
2
|
+
## Shared Methods (Need to be loaded first)
|
3
|
+
##============================================================##
|
1
4
|
require_relative "immosquare-extensions/shared_methods"
|
5
|
+
|
6
|
+
##============================================================##
|
7
|
+
## Extensions
|
8
|
+
##============================================================##
|
9
|
+
require_relative "immosquare-extensions/application_record"
|
2
10
|
require_relative "immosquare-extensions/array"
|
3
11
|
require_relative "immosquare-extensions/file"
|
4
12
|
require_relative "immosquare-extensions/hash"
|
5
13
|
require_relative "immosquare-extensions/string"
|
6
|
-
|
14
|
+
##============================================================##
|
15
|
+
## Rails
|
16
|
+
##============================================================##
|
7
17
|
require_relative "immosquare-extensions/railtie" if defined?(Rails)
|
8
18
|
|
9
19
|
module ImmosquareExtensions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immosquare-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IMMO SQUARE
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_utils
|
@@ -35,10 +35,10 @@ extensions: []
|
|
35
35
|
extra_rdoc_files: []
|
36
36
|
files:
|
37
37
|
- lib/immosquare-extensions.rb
|
38
|
+
- lib/immosquare-extensions/application_record.rb
|
38
39
|
- lib/immosquare-extensions/array.rb
|
39
40
|
- lib/immosquare-extensions/file.rb
|
40
41
|
- lib/immosquare-extensions/hash.rb
|
41
|
-
- lib/immosquare-extensions/helpers/preview_mailer_helper.rb
|
42
42
|
- lib/immosquare-extensions/railtie.rb
|
43
43
|
- lib/immosquare-extensions/shared_methods.rb
|
44
44
|
- lib/immosquare-extensions/string.rb
|
@@ -1,207 +0,0 @@
|
|
1
|
-
module ImmosquareExtensions
|
2
|
-
module PreviewMailerHelper
|
3
|
-
##============================================================##
|
4
|
-
## Inspired by:
|
5
|
-
## https://github.com/rails/rails/blob/main/railties/lib/rails/templates/rails/mailers/email.html.erb
|
6
|
-
## -------------
|
7
|
-
## Here concact with "#{}" is not working, so used
|
8
|
-
## "data:application/octet-stream;charset=utf-8;base64,"+Base64.encode64(a.body.to_s)
|
9
|
-
##============================================================##
|
10
|
-
def display_email_header_infos(email)
|
11
|
-
ApplicationController.render(
|
12
|
-
:layout => false,
|
13
|
-
:locals => {
|
14
|
-
:email => email,
|
15
|
-
:formats => get_email_formats(email),
|
16
|
-
:locales => I18n.available_locales.map do |locale|
|
17
|
-
{
|
18
|
-
:name => locale,
|
19
|
-
:url => url_for(:mailer_locale => locale, :part => params[:part].presence),
|
20
|
-
:css_class => (params[:mailer_locale].present? && params[:mailer_locale] == locale.to_s) || (params[:mailer_locale].blank? && I18n.locale == locale) ? "" : "text-body"
|
21
|
-
}
|
22
|
-
end
|
23
|
-
},
|
24
|
-
:inline => <<~HTML
|
25
|
-
<header>
|
26
|
-
<table>
|
27
|
-
<% if email.respond_to?(:smtp_envelope_from) && Array(email.from) != Array(email.smtp_envelope_from) %>
|
28
|
-
<tr>
|
29
|
-
<th>SMTP-From:</th>
|
30
|
-
<td><%= email.smtp_envelope_from %></td>
|
31
|
-
</tr>
|
32
|
-
<% end %>
|
33
|
-
|
34
|
-
<% if email.respond_to?(:smtp_envelope_to) && email.to != email.smtp_envelope_to %>
|
35
|
-
<tr>
|
36
|
-
<th>SMTP-To:</th>
|
37
|
-
<td><%= email.smtp_envelope_to %></td>
|
38
|
-
</tr>
|
39
|
-
<% end %>
|
40
|
-
|
41
|
-
<tr>
|
42
|
-
<th>From:</th>
|
43
|
-
<td><%= email.header["from"] %></td>
|
44
|
-
</tr>
|
45
|
-
|
46
|
-
<% if email.reply_to %>
|
47
|
-
<tr>
|
48
|
-
<th>Reply-To:</th>
|
49
|
-
<td><%= email.header["reply-to"] %></td>
|
50
|
-
</tr>
|
51
|
-
<% end %>
|
52
|
-
|
53
|
-
<tr>
|
54
|
-
<th>To:</th>
|
55
|
-
<td><%= email.header["to"] %></td>
|
56
|
-
</tr>
|
57
|
-
|
58
|
-
<% if email.cc %>
|
59
|
-
<tr>
|
60
|
-
<th>CC:</th>
|
61
|
-
<td><%= email.header["cc"] %></td>
|
62
|
-
</tr>
|
63
|
-
<% end %>
|
64
|
-
|
65
|
-
<% if email.bcc %>
|
66
|
-
<tr>
|
67
|
-
<th>BCC:</th>
|
68
|
-
<td><%= email.header["bcc"] %></td>
|
69
|
-
</tr>
|
70
|
-
<% end %>
|
71
|
-
|
72
|
-
<tr>
|
73
|
-
<th>Date:</th>
|
74
|
-
<td><%= Time.current.rfc2822 %></td>
|
75
|
-
</tr>
|
76
|
-
|
77
|
-
<tr>
|
78
|
-
<th>Subject:</th>
|
79
|
-
<td><%= email.subject %></td>
|
80
|
-
</tr>
|
81
|
-
|
82
|
-
<tr>
|
83
|
-
<th>Formats:</th>
|
84
|
-
<td>
|
85
|
-
<% formats.each do |format| %>
|
86
|
-
<%= link_to(format[:name], format[:url], :class => "text-decoration-none hover-primary" + " " + format[:css_class]) %>
|
87
|
-
<%= content_tag(:span, " | ") unless format == formats.last %>
|
88
|
-
<% end %>
|
89
|
-
</td>
|
90
|
-
</tr>
|
91
|
-
|
92
|
-
<% if locales.size > 1 %>
|
93
|
-
<tr>
|
94
|
-
<th>Locale:</th>
|
95
|
-
<td>
|
96
|
-
<% locales.each do |locale| %>
|
97
|
-
<%= link_to(locale[:name], locale[:url], :class => "text-decoration-none hover-primary" + " " + locale[:css_class]) %>
|
98
|
-
<%= content_tag(:span, " | ") unless locale == locales.last %>
|
99
|
-
<% end %>
|
100
|
-
</td>
|
101
|
-
</tr>
|
102
|
-
<% end %>
|
103
|
-
|
104
|
-
<% if !(email.attachments.nil? || email.attachments.empty?) %>
|
105
|
-
<tr>
|
106
|
-
<th>Attachments:</th>
|
107
|
-
<td>
|
108
|
-
<% email.attachments.each do |a| %>
|
109
|
-
<% filename = a.respond_to?(:original_filename) ? a.original_filename : a.filename %>
|
110
|
-
<%= link_to filename, "data:application/octet-stream;charset=utf-8;base64,"+Base64.encode64(a.body.to_s), download: filename %>
|
111
|
-
<% end %>
|
112
|
-
</td>
|
113
|
-
</tr>
|
114
|
-
<% end %>
|
115
|
-
|
116
|
-
<% if !(email.header_fields.nil? || email.header_fields.empty?) %>
|
117
|
-
<tr>
|
118
|
-
<th class="align-top">Headers:</th>
|
119
|
-
<td>
|
120
|
-
<details>
|
121
|
-
<summary>Show all headers</summary>
|
122
|
-
<table>
|
123
|
-
<% email.header_fields.each do |field| %>
|
124
|
-
<tr>
|
125
|
-
<th><%= field.name %>:</th>
|
126
|
-
<td><%= field.value %></td>
|
127
|
-
</tr>
|
128
|
-
<% end %>
|
129
|
-
</table>
|
130
|
-
</details>
|
131
|
-
</td>
|
132
|
-
</tr>
|
133
|
-
<% end %>
|
134
|
-
</table>
|
135
|
-
</header>
|
136
|
-
HTML
|
137
|
-
)
|
138
|
-
end
|
139
|
-
|
140
|
-
def display_email_preview(email)
|
141
|
-
begin
|
142
|
-
formats = get_email_formats(email)
|
143
|
-
part_format = formats.find {|f| f[:selected] }
|
144
|
-
part_type = Mime::Type.lookup(part_format[:content_type])
|
145
|
-
|
146
|
-
raise("No email part found for content type: #{part_format[:content_type]}") if !(part = find_part(email, part_type))
|
147
|
-
|
148
|
-
body = part.respond_to?(:decoded) ? part.decoded : part
|
149
|
-
part_format[:name] == "html" ? body.html_safe : simple_format(body)
|
150
|
-
rescue StandardError => e
|
151
|
-
"Error displaying email: #{e.message}"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
private
|
156
|
-
|
157
|
-
|
158
|
-
##============================================================##
|
159
|
-
## find_first_mime_type is a method from the Mail gem for module
|
160
|
-
## Mail Message
|
161
|
-
## ----------------
|
162
|
-
## https://github.com/mikel/mail/blob/master/lib/mail/message.rb#L1938
|
163
|
-
##============================================================##
|
164
|
-
def find_preferred_part(email, *formats)
|
165
|
-
formats.each do |format|
|
166
|
-
if (part = email.find_first_mime_type(format))
|
167
|
-
return part
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
email if formats.any? {|f| email.mime_type == f }
|
172
|
-
end
|
173
|
-
|
174
|
-
##============================================================##
|
175
|
-
## find_part use the find_first_mime_type method from the Mail
|
176
|
-
## gem for module Mail Message
|
177
|
-
##============================================================##
|
178
|
-
def find_part(email, format)
|
179
|
-
if (part = email.find_first_mime_type(format))
|
180
|
-
part
|
181
|
-
elsif email.mime_type == format
|
182
|
-
email
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
##============================================================##
|
187
|
-
## Return email formats
|
188
|
-
##============================================================##
|
189
|
-
def get_email_formats(email)
|
190
|
-
part = find_preferred_part(email, Mime[:html], Mime[:text])
|
191
|
-
formats = []
|
192
|
-
formats =
|
193
|
-
if email.html_part && email.text_part
|
194
|
-
selected = params[:part].present? && params[:part] == "text" ? "text" : "html"
|
195
|
-
[
|
196
|
-
{:name => "html", :content_type => "text/html", :url => url_for(:part => "html", :mailer_locale => params[:mailer_locale].presence), :selected => selected == "html", :css_class => selected == "html" ? "" : "text-body"},
|
197
|
-
{:name => "text", :content_type => "text/plain", :url => url_for(:part => "text", :mailer_locale => params[:mailer_locale].presence), :selected => selected == "text", :css_class => selected == "text" ? "" : "text-body"}
|
198
|
-
]
|
199
|
-
elsif part
|
200
|
-
data = part.content_type.split(";").first.split("/").last
|
201
|
-
[
|
202
|
-
{:name => data, :content_type => "text/#{data}", :url => url_for(:part => data, :mailer_locale => params[:mailer_locale].presence), :selected => true, :css_class => ""}
|
203
|
-
]
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|