immosquare-extensions 0.1.25 → 0.1.26

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba51ed41c3634406db205a26151c6cda8219a982126e4dae21042982c2084214
4
- data.tar.gz: bdc036cfdcc9a66e18db188482d0d4a61ed49829e64ccccde39df5932f9bfd78
3
+ metadata.gz: 0553e2e647c71c0afd72090399cbdc933659fde01e8daf8f7ff0a75fbfd8c333
4
+ data.tar.gz: 64e97c458e494e7c1651532c24dec6ba017b69d010190acd5bf27bb9f639a1c9
5
5
  SHA512:
6
- metadata.gz: 2da7574722a68408c77651bbeaf8cc1489ba4973c4aa947a06ac107aa46992946cf53df46754ee3a03ad800b047f95862b83e230b909a052a0bad1f3933ae064
7
- data.tar.gz: 69d36d4d563c8afddc27b0ba41dd4edc243b16693222970ff5c78f4f36b9c2ee41ced5a9751427e49be453d374da12a82745d78467b87f81c63a0b8286b80a87
6
+ metadata.gz: 263bc2dc0631004a0f0e20c7b24728833dd63d6ca1c280f6adf269e36c871c612c75173099e4afba2cc7cf335826e069d9be01c8277a8de59fd2664c41e95e7f
7
+ data.tar.gz: 626f8fab96fe0b7cbc1b394b43e8cd93bf626da03f436a6426e1eea460c660eff143cad2e3654cc00433ecf53724a2bdc49ab17f94e37056ef702c1ac9262fa7
@@ -3,18 +3,14 @@ require "rails"
3
3
  module ImmosquareExtensions
4
4
  class Railtie < Rails::Railtie
5
5
 
6
- initializer "immosquare_extensions.action_view" do
7
- ActiveSupport.on_load(:action_view) do
8
- include ImmosquareExtensions::PreviewMailerHelper
9
- end
10
- end
11
-
12
6
  initializer "immosquare_extensions.active_record" do
13
7
  ActiveSupport.on_load(:active_record) do
8
+ ##============================================================##
9
+ ## Pour ajouter des méthodes à ActiveRecord::Base
10
+ ##============================================================##
14
11
  ActiveRecord::Base.include(ImmosquareExtensions::ApplicationRecord)
15
12
  end
16
13
  end
17
14
 
18
-
19
15
  end
20
16
  end
@@ -1,3 +1,3 @@
1
1
  module ImmosquareExtensions
2
- VERSION = "0.1.25".freeze
2
+ VERSION = "0.1.26".freeze
3
3
  end
@@ -11,17 +11,10 @@ require_relative "immosquare-extensions/array"
11
11
  require_relative "immosquare-extensions/file"
12
12
  require_relative "immosquare-extensions/hash"
13
13
  require_relative "immosquare-extensions/string"
14
-
15
- ##============================================================##
16
- ## Helpers
17
- ##============================================================##
18
- require_relative "immosquare-extensions/helpers/preview_mailer_helper"
19
-
20
14
  ##============================================================##
21
15
  ## Rails
22
16
  ##============================================================##
23
17
  require_relative "immosquare-extensions/railtie" if defined?(Rails)
24
18
 
25
-
26
19
  module ImmosquareExtensions
27
20
  end
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.25
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-08-22 00:00:00.000000000 Z
11
+ date: 2024-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_utils
@@ -39,7 +39,6 @@ files:
39
39
  - lib/immosquare-extensions/array.rb
40
40
  - lib/immosquare-extensions/file.rb
41
41
  - lib/immosquare-extensions/hash.rb
42
- - lib/immosquare-extensions/helpers/preview_mailer_helper.rb
43
42
  - lib/immosquare-extensions/railtie.rb
44
43
  - lib/immosquare-extensions/shared_methods.rb
45
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