Class: Trackplot::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Trackplot::Generators::InstallGenerator
- Defined in:
- lib/generators/trackplot/install_generator.rb
Instance Method Summary collapse
Instance Method Details
#copy_stimulus_controller ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/trackplot/install_generator.rb', line 21 def copy_stimulus_controller return unless [:stimulus] dest = Rails.root.join("app/javascript/controllers/trackplot_controller.js") if File.exist?(dest) say "Stimulus controller already exists at #{dest}", :yellow else copy_file "trackplot_controller.js", dest say "Copied Stimulus controller to #{dest}", :green end end |
#detect_and_install_js ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/generators/trackplot/install_generator.rb', line 10 def detect_and_install_js if importmap? install_importmap elsif jsbundling? install_jsbundling else say "Could not detect JS setup (no config/importmap.rb or package.json found).", :red say "Please add `import \"trackplot\"` to your JavaScript entrypoint manually." end end |
#print_post_install ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/generators/trackplot/install_generator.rb', line 33 def print_post_install say "" say "Trackplot installed successfully!", :green say "" say "Quick start — add this to any ERB view:" say "" say ' <%= trackplot_chart([{month: "Jan", revenue: 100}, {month: "Feb", revenue: 200}]) do |c| %>' say " <% c.axis :x, data_key: :month %>" say " <% c.axis :y, format: :currency %>" say " <% c.line :revenue, curve: true %>" say " <% c.tooltip format: :currency %>" say " <% c.legend %>" say " <% end %>" say "" end |