module Google::Apis::Generator::TemplateHelpers

Helpers used in ERB templates

Public Instance Methods

block_comment(str, spaces_before = 0, spaces_after = 0) click to toggle source

Render a block comment

@param [String] str

Comment string

@param [Fixnum] spaces_before

Number of spaces to indent the comment hash

@param [Fixnum] spaces_after

Number of spaces to indent after the comment hash for subsequent lines

@return [String] formatted comment

# File lib/google/apis/generator/template.rb, line 47
def block_comment(str, spaces_before = 0, spaces_after = 0)
  return '' if str.nil?
  pre = ' ' * spaces_before
  post = ' ' * spaces_after
  lines = str.gsub(/([{}])/, '`').scan(/.{1,78}(?:\W|$)/).map(&:strip)
  lines.join("\n" + pre + '#' + post)
end
include(partial, context) click to toggle source

Include a partial inside a template.

@private @param [String] partial

Name of the template

@param [Hash] context

Context used to render

@return [String] rendered content

# File lib/google/apis/generator/template.rb, line 77
def include(partial, context)
  template = Template.new(sprintf('_%s.tmpl', partial))
  template.render(context)
end
indent(str, spaces) click to toggle source

Indent a block of text

@param [String] str

Content to indent

@param [Fixnum] spaces

Number of spaces to indent

@return [String] formatted content

# File lib/google/apis/generator/template.rb, line 62
def indent(str, spaces)
  pre = ' ' * spaces
  str = pre + str.split(/\n/).join("\n" + pre) + "\n"
  return str unless str.strip.empty?
  nil
end
to_path(module_name) click to toggle source

Get the include path for a ruby module/class

@param [String] module_name

Fully qualified module/class name

@return [String]

Path to file
# File lib/google/apis/generator/template.rb, line 34
def to_path(module_name)
  ActiveSupport::Inflector.underscore(module_name)
end