24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/talkable/generators/install_generator.rb', line 24
def inject_talkable_offer
inject_into_file "app/controllers/application_controller.rb", after: "class ApplicationController < ActionController::Base" do
<<-RUBY
before_action :load_talkable_offer
RUBY
end
inject_into_file "app/controllers/application_controller.rb", before: /^end/ do
<<-RUBY
protected
def load_talkable_offer
origin = Talkable.register_affiliate_member
@offer ||= origin.offer if origin
end
RUBY
end
empty_directory "app/views/shared/"
if erb?
copy_file "app/views/shared/_talkable_offer.html.erb", "app/views/shared/_talkable_offer.html.erb"
inject_into_file "app/views/layouts/application.html.erb", before: "</body>" do
"<%= render 'shared/talkable_offer', offer: @offer %>\n"
end
else
ext = template_lang
copy_file "app/views/shared/_talkable_offer.html.#{ext}", "app/views/shared/_talkable_offer.html.#{ext}"
gsub_file "app/views/layouts/application.html.#{ext}", /^(\s*)\=\s*yield\s*$/ do |line|
paddings = line.match(/(\s*)\=/)[1]
"#{line}#{paddings}= render 'shared/talkable_offer', offer: @offer\n"
end
end
end
|