Sha256: 192580768dc3c966386e27538eedb3d0121e2e19a60b98399f8f5b31430c3938
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
# frozen_string_literal: true require_relative "./slice_context" require "dry/files/path" module Hanami module CLI module Generators module App class ActionContext < SliceContext def initialize(inflector, app, slice, controller, action) @controller = controller @action = action super(inflector, app, slice, nil) end def camelized_controller_name controller.map do |token| inflector.camelize(token) end.join(NAMESPACE_SEPARATOR) end def camelized_action_name inflector.camelize(action) end def underscored_controller_name controller.map do |token| inflector.underscore(token) end end def underscored_action_name inflector.underscore(action) end def module_controller_declaration controller.each_with_index.map do |token, i| "#{OFFSET}#{INDENTATION * i}module #{inflector.camelize(token)}" end.join($/) end def module_controller_end controller.each_with_index.map do |_, i| "#{OFFSET}#{INDENTATION * i}end" end.reverse.join($/) end def module_controller_offset "#{OFFSET}#{INDENTATION * controller.count}" end def template_path Dry::Files::Path["slices", underscored_slice_name, "templates", *underscored_controller_name, "#{underscored_action_name}.html.erb"] end private NAMESPACE_SEPARATOR = "::" private_constant :NAMESPACE_SEPARATOR INDENTATION = " " private_constant :INDENTATION OFFSET = INDENTATION * 2 private_constant :OFFSET attr_reader :controller attr_reader :action end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems