Class: Charming::Generators::ViewGenerator

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

Overview

ViewGenerator implements ‘charming generate view NAME [ACTION]`. Writes a single view class file at `app/views/<name>/<action>_view.rb`. The action defaults to `show`.

Instance Method Summary collapse

Constructor Details

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

name is the resource name. args may contain a single action name (defaults to “show”).

Raises:



9
10
11
12
13
14
# File 'lib/charming/generators/view_generator.rb', line 9

def initialize(name, args, out:, destination:, force: false)
  super
  raise Error, "Usage: charming generate view NAME [ACTION]" if args.length > 1

  @action = args.fetch(0, "show")
end

Instance Method Details

#generateObject

Writes the view file to ‘app/views/<name>/<action>_view.rb`.



17
18
19
# File 'lib/charming/generators/view_generator.rb', line 17

def generate
  create_file(File.join("app", "views", name.snake_name, "#{action}_view.rb"), view)
end