text_message_rails 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 7ed8db9bab0015b9afb253c1c295348b76fcfd14
4
- data.tar.gz: c0707f4cc5528b0ed36f942f0fb98ce14ec1f767
3
+ metadata.gz: 61f00a8c0971b843dbdeae388b1dba6cc4f44a37
4
+ data.tar.gz: 66b743b50f707d7bf04114f42a472433b8990f60
5
5
  SHA512:
6
- metadata.gz: 5f386a532342730dc6372235cfa660c2d4d096b15719ab193126f1d0f80bef1f2735661cc372ac1b963370fd23d35cb8c9113050c4d86fa88be1a5d56119c5ac
7
- data.tar.gz: 29d47f73dcef3bf0115c281288d0ed9ab0fd47a8ecfdef9fdf3d97e2884ace798a6bc0535b0dba32ec50836034f13de4d4dfbd6c1263e34b24bf4e6633879f19
6
+ metadata.gz: a8808ff498efa8a2bb5e45e7d18d32086f934cb7864c50880acbab6cd773d3b40411b6eb1dd46cb19840d041fdb622c1295df33f413cc4bc7dae61c74a9d2266
7
+ data.tar.gz: 4d5ff71644396b4a1c744cacb31aad987e9c3912797457af47b69a2435fd14cda13730c93db2e789e43ce8ed5fddf7d6a5f77b4757a1addc6457def3fab5432e
@@ -27,13 +27,16 @@ module TextMessage
27
27
  # Defines #render_to_body, needed by #render.
28
28
  include ::TextMessage::Rendering
29
29
 
30
+ attr_reader :params
31
+
30
32
  # Instanciate a new TextMessage object.
31
33
  #
32
34
  # Then calls +method_name+ with the given +args+.
33
- def initialize(method_name, *args)
35
+ def initialize(method_name, *params)
34
36
  @recipients = []
37
+ @params = params
35
38
  super()
36
- process(method_name, *args)
39
+ process(method_name, *params)
37
40
  end
38
41
 
39
42
  # Basic Recipients handling
@@ -42,6 +45,10 @@ module TextMessage
42
45
  @recipients = recipients || []
43
46
  end
44
47
 
48
+ def delivery
49
+ TextMessage::Delivery.new(self, action_name, *params)
50
+ end
51
+
45
52
  class << self
46
53
 
47
54
  def default_url_options=(options)
@@ -11,8 +11,13 @@ module TextMessage
11
11
  # By providing a +TextMessage::Base+ subclass +text_message_class+, a method name to call
12
12
  # +text_message_method+ and a set of arguments to this method +args+, we allow
13
13
  # for lazy processing of the text_message action.
14
- def initialize(text_message_class, text_message_method, *args)
15
- @text_message_class = text_message_class.kind_of?(Class) ? text_message_class : text_message_class.constantize
14
+ def initialize(text_message_controller, text_message_method, *args)
15
+ if text_message_controller.kind_of?(TextMessage::Controller)
16
+ @obj = text_message_controller
17
+ @text_message_class = @obj.class
18
+ else
19
+ @text_message_class = text_message_controller.kind_of?(Class) ? text_message_controller : text_message_controller.constantize
20
+ end
16
21
  @text_message_method = text_message_method
17
22
  @args = args
18
23
  end
@@ -24,7 +29,7 @@ module TextMessage
24
29
 
25
30
  # computes the body of the TextMessage
26
31
  def body
27
- renderer.render(view_context, template: "#{templates_dir}/#{@text_message_method}")
32
+ @body ||= renderer.render(view_context, template: "#{templates_dir}/#{@text_message_method}")
28
33
  end
29
34
 
30
35
  # The name of the templates which holds the templates.
@@ -33,7 +38,7 @@ module TextMessage
33
38
  # TextMessageDemo.new.templates_dir => "text_message demo"
34
39
  # # so for exemple TextMessageDemo#toto will lookup for text_message_demo/toto{.text.erb}
35
40
  def templates_dir
36
- @text_message_class.to_s.underscore
41
+ @text_message_class.name.to_s.underscore
37
42
  end
38
43
 
39
44
  end
@@ -6,6 +6,7 @@ module TextMessage
6
6
  # Defivers a TextMessage
7
7
  def deliver_now!
8
8
  @text_message_class.deliver_text_message(self)
9
+ @obj.response_body = body
9
10
  end
10
11
 
11
12
  # Posts a ActionJob job to call +deliver_now!+ later
@@ -17,7 +17,11 @@ module TextMessage
17
17
 
18
18
  # Use custom rendeing class with helpers loaded
19
19
  def view_context # :nodoc:
20
- @view_context ||= TemplateContext.new(renderer, view_assigns, self)
20
+ @view_context ||= if defined?(ApplicationController)
21
+ ApplicationController.view_context_class.new(renderer, view_assigns, self)
22
+ else
23
+ TemplateContext.new(renderer, view_assigns, self)
24
+ end
21
25
  end
22
26
 
23
27
  # Simple out-of-the box ActionView::Renderer
@@ -28,20 +32,22 @@ module TextMessage
28
32
 
29
33
  #
30
34
  # Private class to render provide rendering context with helpers
35
+ # (when there is no ApplicationController: rails API etc.)
31
36
  #
32
37
 
33
38
  class TemplateContext < ActionView::Base #:nodoc:
34
39
  # Load route helpers
35
40
  include Rails.application.routes.url_helpers
36
- # load tag helpers (link_to ...)
41
+ # load tag helpers (link_to ...) and all relevant default helpers
37
42
  include ActionView::Helpers::TagHelper
43
+ include ActionView::Helpers::DateHelper
44
+ include ActionView::Helpers::NumberHelper
45
+ include ActionView::Helpers::TextHelper
46
+ include ActionView::Helpers::TranslationHelper
38
47
 
39
48
  # Default options for urls
40
49
  def default_url_options
41
- TextMessage::Controller.default_url_options.merge({
42
- #action: action_name,
43
- #controller: controller.class.name.underscore
44
- })
50
+ TextMessage::Controller.default_url_options
45
51
  end
46
52
  end
47
53
 
@@ -1,3 +1,3 @@
1
1
  module TextMessage
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text_message_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aurélien Noce