Class: Hanami::CLI::Generators::App::ViewContext Private

Inherits:
SliceContext show all
Defined in:
lib/hanami/cli/generators/app/view_context.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from SliceContext

#camelized_slice_name, #humanized_slice_name, #javascript_erb_tag, #stylesheet_erb_tag, #underscored_slice_name

Methods inherited from Context

#bundled_assets?, #bundled_views?, #camelized_app_name, #ctx, #generate_assets?, #hanami_assets_npm_package, #hanami_gem, #hanami_gem_version, #hanami_head?, #humanized_app_name, #ruby_omit_hash_values?, #underscored_app_name

Constructor Details

#initialize(inflector, app, slice, key) ⇒ ViewContext

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ViewContext.

Since:

  • 2.1.0



34
35
36
37
# File 'lib/hanami/cli/generators/app/view_context.rb', line 34

def initialize(inflector, app, slice, key)
  @key = key
  super(inflector, app, slice, nil)
end

Instance Attribute Details

#keyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



30
31
32
# File 'lib/hanami/cli/generators/app/view_context.rb', line 30

def key
  @key
end

Instance Method Details

#camelized_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



59
60
61
# File 'lib/hanami/cli/generators/app/view_context.rb', line 59

def camelized_name
  inflector.camelize(name)
end

#camelized_namespaceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



53
54
55
# File 'lib/hanami/cli/generators/app/view_context.rb', line 53

def camelized_namespace
  namespaces.map { inflector.camelize(_1) }.join(NAMESPACE_SEPARATOR)
end

#module_namespace_declarationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



77
78
79
80
81
# File 'lib/hanami/cli/generators/app/view_context.rb', line 77

def module_namespace_declaration
  namespaces.each_with_index.map { |token, i|
    "#{OFFSET}#{INDENTATION * i}module #{inflector.camelize(token)}"
  }.join($/)
end

#module_namespace_endObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



85
86
87
88
89
# File 'lib/hanami/cli/generators/app/view_context.rb', line 85

def module_namespace_end
  namespaces.each_with_index.map { |_, i|
    "#{OFFSET}#{INDENTATION * i}end"
  }.reverse.join($/)
end

#module_namespace_offsetObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



93
94
95
# File 'lib/hanami/cli/generators/app/view_context.rb', line 93

def module_namespace_offset
  "#{OFFSET}#{INDENTATION * namespaces.count}"
end

#nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



47
48
49
# File 'lib/hanami/cli/generators/app/view_context.rb', line 47

def name
  @name ||= key.split(KEY_SEPARATOR)[-1]
end

#namespacesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



41
42
43
# File 'lib/hanami/cli/generators/app/view_context.rb', line 41

def namespaces
  @namespaces ||= key.split(KEY_SEPARATOR)[..-2]
end

#underscored_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



71
72
73
# File 'lib/hanami/cli/generators/app/view_context.rb', line 71

def underscored_name
  inflector.underscore(name)
end

#underscored_namespaceObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



65
66
67
# File 'lib/hanami/cli/generators/app/view_context.rb', line 65

def underscored_namespace
  namespaces.map { inflector.underscore(_1) }
end