Class: Faultline::Generators::CustomizeGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/faultline/customize_generator.rb

Instance Method Summary collapse

Instance Method Details

#display_post_installObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/generators/faultline/customize_generator.rb', line 88

def display_post_install
  return unless generate_all?

  say ""
  say "Faultline customization files generated!", :green
  say ""
  say "Generated files:"
  say "  - app/views/layouts/faultline/application.html.erb (host-app layout)"
  say "  - app/views/faultline/logged_exceptions/index.html.erb"
  say "  - app/views/faultline/logged_exceptions/_exceptions.html.erb"
  say "  - app/views/faultline/logged_exceptions/_show.html.erb"
  say "  - app/javascript/controllers/faultline_controller.js"
  say ""
  say "Next steps:"
  say "  1. Edit the layout to match your host app's navigation"
  say "  2. If using Tailwind, add to your CSS source paths:"
  say '     @source "path/to/faultline/app/views/**/*.erb";'
  say "  3. Run: bin/rails stimulus:manifest:update"
  say ""
end

#generate_initializer_patchesObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/faultline/customize_generator.rb', line 59

def generate_initializer_patches
  return unless generate_all? || options[:initializer_only]

  append_to_file "config/initializers/faultline.rb" do
    "\n# --- Faultline Customize Generator Patches ---\n" \
    "\n" \
    "# Make host app helpers available in faultline views.\n" \
    "# Uncomment the helpers your app defines:\n" \
    "# Faultline::LoggedExceptionsController.helper HeroiconHelper\n" \
    "# Faultline::LoggedExceptionsController.helper ApplicationHelper\n" \
    "\n" \
    "# Fix for Rails 8.1+: params_filters must return plain hashes.\n" \
    "# This is applied automatically by the gem (v0.5.1+).\n" \
    "# Uncomment below if needed:\n" \
    "# Faultline::LoggedExceptionsController.class_eval do\n" \
    "#   private\n" \
    "#   def params_filters\n" \
    "#     result = {}\n" \
    "#     result[:q] = params[:q].to_unsafe_h if params[:q].present?\n" \
    "#     result[:query] = params[:query] if params[:query].present?\n" \
    "#     result[:date_ranges_filter] = params[:date_ranges_filter] if params[:date_ranges_filter].present?\n" \
    "#     result[:exception_names_filter] = params[:exception_names_filter] if params[:exception_names_filter].present?\n" \
    "#     result[:controller_actions_filter] = params[:controller_actions_filter] if params[:controller_actions_filter].present?\n" \
    "#     result\n" \
    "#   end\n" \
    "# end\n"
  end
end

#generate_layoutObject



30
31
32
33
34
35
# File 'lib/generators/faultline/customize_generator.rb', line 30

def generate_layout
  return unless generate_all? || options[:layout_only]

  template "views/layouts/faultline/application.html.erb",
           "app/views/layouts/faultline/application.html.erb"
end

#generate_stimulusObject



50
51
52
53
54
55
56
57
# File 'lib/generators/faultline/customize_generator.rb', line 50

def generate_stimulus
  return unless generate_all? || options[:stimulus_only]

  template "javascript/controllers/faultline_controller.js",
           "app/javascript/controllers/faultline_controller.js"

  run "bin/rails stimulus:manifest:update", capture: true if File.exist?("bin/rails")
end

#generate_viewsObject



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/faultline/customize_generator.rb', line 37

def generate_views
  return unless generate_all? || options[:views_only]

  template "views/faultline/logged_exceptions/index.html.erb",
           "app/views/faultline/logged_exceptions/index.html.erb"

  template "views/faultline/logged_exceptions/_exceptions.html.erb",
           "app/views/faultline/logged_exceptions/_exceptions.html.erb"

  template "views/faultline/logged_exceptions/_show.html.erb",
           "app/views/faultline/logged_exceptions/_show.html.erb"
end