Class: Talkable::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Talkable::InstallGenerator
- Defined in:
- lib/talkable/generators/install_generator.rb
Instance Method Summary collapse
- #add_initializer ⇒ Object
- #add_invite_controller ⇒ Object
- #ask_config_values ⇒ Object
- #inject_talkable_offer ⇒ Object
Instance Method Details
#add_initializer ⇒ Object
15 16 17 |
# File 'lib/talkable/generators/install_generator.rb', line 15 def add_initializer template "config/initializers/talkable.rb", "config/initializers/talkable.rb" end |
#add_invite_controller ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/talkable/generators/install_generator.rb', line 56 def add_invite_controller ext = template_lang copy_file "app/controllers/invite_controller.rb", "app/controllers/invite_controller.rb" copy_file "app/views/invite/show.html.#{ext}", "app/views/invite/show.html.#{ext}" route "get '/invite' => 'invite#show'" end |
#ask_config_values ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/talkable/generators/install_generator.rb', line 7 def ask_config_values @site_slug = ask("Your Talkable site slug:") @api_key = ask("Your Talkable API Key:") if yes?('Do you have a custom domain? [Y/n]') @server = ask("Your custom domain [#{Talkable::Configuration::DEFAULT_SERVER}]:") end end |
#inject_talkable_offer ⇒ Object
19 20 21 22 23 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 |
# File 'lib/talkable/generators/install_generator.rb', line 19 def inject_talkable_offer inject_into_file "app/controllers/application_controller.rb", after: "protect_from_forgery with: :exception" do "\n before_action :load_talkable_offer\n" end inject_into_file "app/controllers/application_controller.rb", before: /^end/ do " protected\n\n def load_talkable_offer\norigin = Talkable.register_affiliate_member\n@offer ||= origin.offer if origin\n end\n" 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 |