Class: Playwright::CLI::Template

Inherits:
Object
  • Object
show all
Includes:
Utils::Display
Defined in:
lib/playwright/cli/template.rb

Constant Summary collapse

InvalidTemplate =
Class.new(StandardError)
SIMPLE_TYPE =
:simple
SIMPLE_TEMPLATE =
'simple_script_template.erb'
EXPANDED_TYPE =
:expanded
EXPANDED_TEMPLATE =
'expanded_script_template.erb'
SUBCOMMAND_TYPE =
:subcommand
SUBCOMMAND_TEMPLATE =
'version_subcommand_template.erb'
README_TYPE =
:readme
README_TEMPLATE =
'script_readme_template.erb'
SHELL_SCRIPT_TYPE =
:shell_script,
SHELL_SCRIPT_TEMPLATE = 'launch_script_template.erb'
TEMPLATE_MAP =
{
  SIMPLE_TYPE => SIMPLE_TEMPLATE,
  EXPANDED_TYPE => EXPANDED_TEMPLATE,
  SUBCOMMAND_TYPE => SUBCOMMAND_TEMPLATE,
  README_TYPE => README_TEMPLATE,
  SHELL_SCRIPT_TYPE => SHELL_SCRIPT_TEMPLATE
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Display

#display

Constructor Details

#initialize(name:, out_file:, type: SIMPLE_TYPE, klass_name: nil, values: {}) ⇒ Template

Returns a new instance of Template.



35
36
37
38
39
40
41
# File 'lib/playwright/cli/template.rb', line 35

def initialize(name:, out_file:, type: SIMPLE_TYPE, klass_name: nil, values: {})
  @script_name = name
  @out_file = out_file
  @template_file = Playwright::CLI::TEMPLATES_PATH.join TEMPLATE_MAP[type]
  @klass_name = klass_name
  @values = values
end

Instance Attribute Details

#out_fileObject (readonly)

Returns the value of attribute out_file.



10
11
12
# File 'lib/playwright/cli/template.rb', line 10

def out_file
  @out_file
end

#script_nameObject (readonly)

Returns the value of attribute script_name.



10
11
12
# File 'lib/playwright/cli/template.rb', line 10

def script_name
  @script_name
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/playwright/cli/template.rb', line 10

def type
  @type
end

#valuesObject (readonly)

Returns the value of attribute values.



10
11
12
# File 'lib/playwright/cli/template.rb', line 10

def values
  @values
end

Instance Method Details

#klass_nameObject



43
44
45
# File 'lib/playwright/cli/template.rb', line 43

def klass_name
  @klass_name || @script_name.gsub('.rb', '').split(/[A-Z\-\_\/]/).map(&:capitalize).join
end

#renderObject



31
32
33
# File 'lib/playwright/cli/template.rb', line 31

def render(*args)
  new(*args).render
end

#valObject



54
55
56
# File 'lib/playwright/cli/template.rb', line 54

def val
  values
end