Class: Charming::Generators::ScreenGenerator

Inherits:
AppFileGenerator show all
Defined in:
lib/charming/generators/screen_generator.rb

Overview

ScreenGenerator implements ‘charming generate screen NAME`. Writes a complete vertical slice for a new screen: a state class, a controller with a `show` action, a view, matching spec files, and inserts a route into `config/routes.rb` and a command entry into `ApplicationController` for the command palette.

Instance Method Summary collapse

Constructor Details

#initialize(name, args, out:, destination:, force: false) ⇒ ScreenGenerator

name is the resource name. args is unused (raises Error when non-empty).

Raises:



11
12
13
14
# File 'lib/charming/generators/screen_generator.rb', line 11

def initialize(name, args, out:, destination:, force: false)
  super
  raise Error, "Usage: charming generate screen NAME" if args.any?
end

Instance Method Details

#generateObject

Writes the state, controller, view, and three spec files, then inserts a route and a command-palette entry.



18
19
20
21
22
23
24
25
26
27
# File 'lib/charming/generators/screen_generator.rb', line 18

def generate
  create_file(state_path, state)
  create_file(controller_path, controller)
  create_file(view_path, view)
  create_file(spec_state_path, spec_state)
  create_file(spec_controller_path, spec_controller)
  create_file(spec_view_path, spec_view)
  insert_route
  insert_command
end