Total Complexity | 12 |
Total Lines | 84 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | 1 | require 'render_anywhere' |
|
4 | 1 | class Base |
|
5 | 1 | class RenderingController < RenderAnywhere::RenderingController |
|
6 | 1 | layout false |
|
7 | |||
8 | 1 | def default_url_options |
|
9 | 1 | ActionMailer::Base.default_url_options || {} |
|
10 | end |
||
11 | end |
||
12 | |||
13 | 1 | include RenderAnywhere |
|
14 | 1 | extend Textris::Delay::Sidekiq |
|
15 | |||
16 | 1 | class << self |
|
17 | 1 | def deliveries |
|
18 | 1 | ::Textris::Delivery::Test.deliveries |
|
19 | end |
||
20 | |||
21 | 1 | def with_defaults(options) |
|
22 | 16 | defaults.merge(options) |
|
23 | end |
||
24 | |||
25 | 1 | def defaults |
|
26 | 34 | @defaults ||= superclass.respond_to?(:defaults) ? superclass.defaults.dup : {} |
|
27 | end |
||
28 | |||
29 | 1 | protected |
|
30 | |||
31 | 1 | def default(options) |
|
32 | 8 | defaults.merge!(options) |
|
33 | end |
||
34 | |||
35 | 1 | private |
|
36 | |||
37 | 1 | def method_missing(method_name, *args) |
|
38 | 5 | self.new(method_name, *args).call_action |
|
39 | end |
||
40 | end |
||
41 | |||
42 | 1 | def initialize(action, *args) |
|
43 | 17 | @action = action |
|
44 | 17 | @args = args |
|
45 | end |
||
46 | |||
47 | 1 | def call_action |
|
48 | 16 | send(@action, *@args) |
|
49 | end |
||
50 | |||
51 | 1 | def render_content |
|
52 | 1 | set_instance_variables_for_rendering |
|
53 | |||
54 | 1 | render(:template => template_name, :formats => ['text'], :locale => @locale) |
|
55 | end |
||
56 | |||
57 | 1 | protected |
|
58 | |||
59 | 1 | def text(options = {}) |
|
60 | 13 | @locale = options[:locale] || I18n.locale |
|
61 | |||
62 | 13 | options = self.class.with_defaults(options) |
|
63 | 13 | options.merge!( |
|
64 | :texter => self.class, |
||
65 | :action => @action, |
||
66 | :args => @args, |
||
67 | :content => options[:body].is_a?(String) ? options[:body] : nil, |
||
68 | :renderer => self) |
||
69 | |||
70 | 13 | ::Textris::Message.new(options) |
|
71 | end |
||
72 | |||
73 | 1 | private |
|
74 | |||
75 | 1 | def template_name |
|
76 | 1 | class_name = self.class.to_s.underscore.sub('texter/', '') |
|
77 | 1 | action_name = @action |
|
78 | |||
79 | 1 | "#{class_name}/#{action_name}" |
|
80 | end |
||
81 | |||
82 | 1 | def set_instance_variables_for_rendering |
|
83 | 1 | instance_variables.each do |var| |
|
84 | 2 | set_instance_variable(var.to_s.sub('@', ''), instance_variable_get(var)) |
|
85 | end |
||
86 | end |
||
87 | end |
||
88 | end |
||
89 |