hiccdown 2.0.0 → 2.1.0
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.
- checksums.yaml +4 -4
- data/lib/hiccdown/railtie.rb +72 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1ae3d02c78a930cc0d388da9d13d88fc67d68ab4f6b1ea31f41be18419bf529b
|
|
4
|
+
data.tar.gz: 4a18f799e8ffb85e9cea100c843574ba40b6494db1bf4ff1342da747b8b783b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a878b5897666b0974502b7aaa4b3e27bb9c8feeb219e83ac1b88faf5807836a861ddc6a67fd1c960f0acea8e3fd62f003a1f4498209d7c89de5643078c2cb1aa
|
|
7
|
+
data.tar.gz: 501de623740915248afa4d2a56bb8074ae715a6edddc0c41b441c290e8a47f9833890e8df39f1dc0e85c530a9b89f721c4634d269f9da842a5ed110005b3cc67
|
data/lib/hiccdown/railtie.rb
CHANGED
|
@@ -11,6 +11,14 @@ module Hiccdown
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
initializer 'hiccdown.action_mailer' do
|
|
16
|
+
ActiveSupport.on_load(:action_mailer) do
|
|
17
|
+
# Prepended, since ActionMailer::Base defines the methods it overrides
|
|
18
|
+
prepend MailerRendering
|
|
19
|
+
include LayoutRendering
|
|
20
|
+
end
|
|
21
|
+
end
|
|
14
22
|
end
|
|
15
23
|
|
|
16
24
|
# An action's helper method's result, which the controller computes before
|
|
@@ -98,6 +106,70 @@ module Hiccdown
|
|
|
98
106
|
alias_method :virtual_path, :identifier
|
|
99
107
|
end
|
|
100
108
|
|
|
109
|
+
# Stands in for an email's HTML template, as `<Mailer>Helper#<action>`,
|
|
110
|
+
# which Rails renders like a template file, layout and all.
|
|
111
|
+
class Template
|
|
112
|
+
def self.for path, name
|
|
113
|
+
helper_module = "#{path.camelize}Helper".safe_constantize
|
|
114
|
+
|
|
115
|
+
if helper_module.is_a?(Module) && helper_module.instance_methods(false).include?(name.to_sym)
|
|
116
|
+
new(helper_module, name)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def initialize helper_module, name
|
|
121
|
+
@helper_module = helper_module
|
|
122
|
+
@name = name
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def render view, _locals, &_block
|
|
126
|
+
Hiccdown.to_html(@helper_module.instance_method(@name).bind_call(view)).html_safe
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def format
|
|
130
|
+
:html
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def identifier
|
|
134
|
+
"#{@helper_module.name}##{@name}"
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
alias_method :virtual_path, :identifier
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# A mailer's helper is named after it, like a controller's, so the HTML
|
|
141
|
+
# part of `UserMailer#welcome` comes from `UserMailerHelper#welcome`, if it
|
|
142
|
+
# has one. Templates in other formats, such as text, still come from files.
|
|
143
|
+
module MailerRendering
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
def each_template paths, name, &block
|
|
147
|
+
template = hiccdown_template(paths, name)
|
|
148
|
+
return super unless template
|
|
149
|
+
|
|
150
|
+
others = lookup_context.find_all(name, paths).reject { |t| t.format == :html }
|
|
151
|
+
[template, *others].uniq(&:format).each(&block)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# As in `mail { |format| format.html }`, which renders the action by name.
|
|
155
|
+
def render *args
|
|
156
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
|
157
|
+
name = options[:action] || args.first
|
|
158
|
+
|
|
159
|
+
if (name.is_a?(String) || name.is_a?(Symbol)) && !name.to_s.include?('/') &&
|
|
160
|
+
lookup_context.formats.first == :html &&
|
|
161
|
+
(template = hiccdown_template(_prefixes, name.to_s))
|
|
162
|
+
super(template: template, formats: [:html], **options.except(:action))
|
|
163
|
+
else
|
|
164
|
+
super
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def hiccdown_template paths, name
|
|
169
|
+
Array(paths).lazy.filter_map { |path| Template.for(path, name) }.first
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
101
173
|
module LayoutRendering
|
|
102
174
|
private
|
|
103
175
|
|