Class: Shipeasy::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Shipeasy::Generators::InstallGenerator
- Defined in:
- lib/generators/shipeasy/install/install_generator.rb
Overview
rails generate shipeasy:install
Scaffolds Shipeasy into a Rails app the Rails way:
- writes config/initializers/shipeasy.rb (the single Shipeasy.configure call)
- with --i18n, sets the public client key in that initializer AND injects
`<%= i18n_head_tags %>` into the application layout's <head>
- prints the keys / credentials next steps
The gem's Railties already auto-mount the anon-id Rack middleware and the i18n view helpers, so this generator never touches middleware wiring — it only creates the things an app must own: the initializer, the layout tag, and your keys.
Constant Summary collapse
- APP_LAYOUT =
"app/views/layouts/application.html.erb"
Instance Method Summary collapse
Instance Method Details
#create_initializer ⇒ Object
32 33 34 |
# File 'lib/generators/shipeasy/install/install_generator.rb', line 32 def create_initializer template "initializer.rb.tt", "config/initializers/shipeasy.rb" end |
#inject_layout_helpers ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/generators/shipeasy/install/install_generator.rb', line 36 def inject_layout_helpers return unless [:i18n] unless layout_exists? say_status :skip, "#{APP_LAYOUT} not found — add <%= i18n_head_tags %> to your <head> by hand", :yellow return end if layout_already_wired? say_status :identical, "#{APP_LAYOUT} already has i18n_head_tags", :blue return end # Insert just before the closing </head>, picking up its indentation. inject_into_file APP_LAYOUT, "<%= i18n_head_tags %>\n ", before: "</head>" end |
#print_next_steps ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/generators/shipeasy/install/install_generator.rb', line 53 def print_next_steps say "" say " Shipeasy installed → config/initializers/shipeasy.rb", :green say "" say " Next steps:" say " 1. Mint your keys: https://app.shipeasy.ai → Settings → SDK keys" say " 2. Provide them (pick one):" say " • ENV — set SHIPEASY_SERVER_KEY#{[:i18n] ? " and SHIPEASY_CLIENT_KEY" : ""}" say " • Rails credentials — bin/rails credentials:edit, then read" say " them from Rails.application.credentials in the initializer" if [:i18n] say " 3. i18n_head_tags is wired into your layout — run the Shipeasy" say " i18n install to create your en:prod profile, then translate." end say "" say " Read a flag anywhere per request:" say " Shipeasy::Client.new(current_user).get_flag(\"new_checkout\")" say "" say " Docs: https://docs.shipeasy.ai", :cyan say "" end |