Module: Udb::Helpers::TemplateHelpers

Includes:
WavedromUtil
Defined in:
lib/udb_helpers/backend_helpers.rb

Instance Method Summary collapse

Methods included from WavedromUtil

#fix_entities, #json_dump_with_hex_literals, #process_wavedrom

Instance Method Details

#anchor_for_non_isa_spec(name) ⇒ String

Returns An anchor for a UDB non-ISA specification documentation.

Parameters:

  • name (String)

    Name of the non-ISA specification

Returns:

  • (String)

    An anchor for a UDB non-ISA specification documentation



266
267
268
# File 'lib/udb_helpers/backend_helpers.rb', line 266

def anchor_for_non_isa_spec(name)
  "[[udb:doc:non_isa:#{name.sanitize}]]"
end

#anchor_for_udb_doc_cov_pt(org, id) ⇒ String

Have to use [[anchor]] instead of [#anchor] since only the former works when in a table cell.

Parameters:

  • org (String)

    Document organization of normative rules and test procedures (sep=separate chapters, combo=combined chapters, appendix=appendix)

  • id (String)

    ID of the normative rule

Returns:

  • (String)

    An anchor for a UDB normative rule documentation

Raises:

  • (ArgumentError)


259
260
261
262
# File 'lib/udb_helpers/backend_helpers.rb', line 259

def anchor_for_udb_doc_cov_pt(org, id)
  raise ArgumentError, "Unknown org value of '#{org}' for ID '#{id}'" unless org == "sep" || org == "combo" || org == "appendix"
  "[[udb:doc:cov_pt:#{org}:#{id.sanitize}]]"
end

#anchor_for_udb_doc_csr(name) ⇒ String

Returns An anchor for UDB CSR documentation.

Parameters:

  • name (String)

    Name of the CSR

Returns:

  • (String)

    An anchor for UDB CSR documentation



225
226
227
# File 'lib/udb_helpers/backend_helpers.rb', line 225

def anchor_for_udb_doc_csr(name)
  "[#udb:doc:csr:#{name.sanitize}]"
end

#anchor_for_udb_doc_csr_field(csr_name, field_name) ⇒ String

Returns An anchor for UDB CSR field documentation.

Parameters:

  • csr_name (String)

    Name of the CSR

  • field_name (String)

    Name of the CSR field

Returns:

  • (String)

    An anchor for UDB CSR field documentation



232
233
234
# File 'lib/udb_helpers/backend_helpers.rb', line 232

def anchor_for_udb_doc_csr_field(csr_name, field_name)
  "[#udb:doc:csr_field:#{csr_name.sanitize}:#{field_name.sanitize}]"
end

#anchor_for_udb_doc_ext(ext_name) ⇒ String

Returns An anchor for UDB extension documentation.

Parameters:

  • ext_name (String)

    Name of the extension

Returns:

  • (String)

    An anchor for UDB extension documentation



205
206
207
# File 'lib/udb_helpers/backend_helpers.rb', line 205

def anchor_for_udb_doc_ext(ext_name)
  "[#udb:doc:ext:#{ext_name.sanitize}]"
end

#anchor_for_udb_doc_ext_param(ext_name, param_name) ⇒ String

Returns An anchor for UDB parameter documentation.

Parameters:

  • ext_name (String)

    Name of the extension

  • param_name (String)

    Name of the parameter

Returns:

  • (String)

    An anchor for UDB parameter documentation



212
213
214
215
# File 'lib/udb_helpers/backend_helpers.rb', line 212

def anchor_for_udb_doc_ext_param(ext_name, param_name)
  check_no_periods(param_name)
  "[#udb:doc:ext_param:#{ext_name.sanitize}:#{param_name}]"
end

#anchor_for_udb_doc_idl_func(name) ⇒ String

Returns An anchor for an IDL function documentation.

Parameters:

  • name (String)

    Name of the function

Returns:

  • (String)

    An anchor for an IDL function documentation



251
252
253
# File 'lib/udb_helpers/backend_helpers.rb', line 251

def anchor_for_udb_doc_idl_func(name)
  "[#udb:doc:func:#{name.sanitize}]"
end

#anchor_for_udb_doc_inst(name) ⇒ String

Returns An anchor for UDB instruction documentation.

Parameters:

  • name (String)

    Name of the instruction

Returns:

  • (String)

    An anchor for UDB instruction documentation



219
220
221
# File 'lib/udb_helpers/backend_helpers.rb', line 219

def anchor_for_udb_doc_inst(name)
  "[#udb:doc:inst:#{name.sanitize}]"
end

#anchor_for_udb_doc_mmr(name) ⇒ String

Returns An anchor for UDB MMR documentation.

Parameters:

  • name (String)

    Name of the MMR

Returns:

  • (String)

    An anchor for UDB MMR documentation



238
239
240
# File 'lib/udb_helpers/backend_helpers.rb', line 238

def anchor_for_udb_doc_mmr(name)
  "[#udb:doc:mmr:#{name.sanitize}]"
end

#anchor_for_udb_doc_mmr_field(mmr_name, field_name) ⇒ String

Returns An anchor for UDB MMR field documentation.

Parameters:

  • mmr_name (String)

    Name of the MMR

  • field_name (String)

    Name of the MMR field

Returns:

  • (String)

    An anchor for UDB MMR field documentation



245
246
247
# File 'lib/udb_helpers/backend_helpers.rb', line 245

def anchor_for_udb_doc_mmr_field(mmr_name, field_name)
  "[#udb:doc:mmr_field:#{mmr_name.sanitize}:#{field_name.sanitize}]"
end

#anchor_inside_idl_inst_code(inst_name, id) ⇒ String

Returns An anchor inside IDL instruction code.

Parameters:

  • func_name (String)

    Name of the instruction

  • id (String)

    ID within the instruction code

Returns:

  • (String)

    An anchor inside IDL instruction code



273
274
275
# File 'lib/udb_helpers/backend_helpers.rb', line 273

def anchor_inside_idl_inst_code(inst_name, id)
  "[#idl:code:inst:#{inst_name.sanitize}:#{id.sanitize}]"
end

Returns A hyperlink into IDL instruction code.

Parameters:

  • func_name (String)

    Name of the instruction

  • id (String)

    ID within the instruction code

Returns:

  • (String)

    A hyperlink into IDL instruction code



194
195
196
# File 'lib/udb_helpers/backend_helpers.rb', line 194

def link_into_idl_inst_code(inst_name, id)
  "%%IDL_CODE_LINK%inst;#{inst_name.sanitize}.#{id.sanitize};#{inst_name}.#{id}%%"
end

Returns A hyperlink to a UDB certification normative rule (separate chapters for cov pts and test procs).

Parameters:

  • org (String)

    Organization of normative rules and test procedures (sep=separate chapters, combo=combined chapters, appendix=appendix)

  • id (String)

    ID of the normative rule

Returns:

  • (String)

    A hyperlink to a UDB certification normative rule (separate chapters for cov pts and test procs)

Raises:

  • (ArgumentError)


186
187
188
189
# File 'lib/udb_helpers/backend_helpers.rb', line 186

def link_to_udb_doc_cov_pt(org, id)
  raise ArgumentError, "Unknown org value of '#{org}' for ID '#{id}'" unless org == "sep" || org == "combo" || org == "appendix"
  "%%UDB_DOC_COV_PT_LINK%#{org};#{id.sanitize};#{id}%%"
end

Returns A hyperlink to UDB CSR documentation.

Parameters:

  • csr_name (String)

    Name of the CSR

Returns:

  • (String)

    A hyperlink to UDB CSR documentation



153
154
155
# File 'lib/udb_helpers/backend_helpers.rb', line 153

def link_to_udb_doc_csr(csr_name)
  "%%UDB_DOC_LINK%csr;#{csr_name.sanitize};#{csr_name}%%"
end

Returns A hyperlink to UDB CSR field documentation.

Parameters:

  • csr_name (String)

    Name of the CSR

  • field_name (String)

    Name of the CSR field

Returns:

  • (String)

    A hyperlink to UDB CSR field documentation



160
161
162
# File 'lib/udb_helpers/backend_helpers.rb', line 160

def link_to_udb_doc_csr_field(csr_name, field_name)
  "%%UDB_DOC_LINK%csr_field;#{csr_name}*#{field_name};#{csr_name}.#{field_name}%%"
end

Returns A hyperlink to UDB extension documentation.

Parameters:

  • ext_name (String)

    Name of the extension

Returns:

  • (String)

    A hyperlink to UDB extension documentation



132
133
134
# File 'lib/udb_helpers/backend_helpers.rb', line 132

def link_to_udb_doc_ext(ext_name)
  "%%UDB_DOC_LINK%ext;#{ext_name.sanitize};#{ext_name}%%"
end

Returns A hyperlink to UDB parameter documentation.

Parameters:

  • ext_name (String)

    Name of the extension

  • param_name (String)

    Name of the parameter

  • link_text (String)

    What to put in the link text (don’t assume param_name)

Returns:

  • (String)

    A hyperlink to UDB parameter documentation



140
141
142
143
# File 'lib/udb_helpers/backend_helpers.rb', line 140

def link_to_udb_doc_ext_param(ext_name, param_name, link_text)
  check_no_periods(param_name)
  "%%UDB_DOC_LINK%ext_param;#{ext_name.sanitize}.#{param_name};#{link_text}%%"
end

Returns A hyperlink to UDB IDL function documentation.

Parameters:

  • func_name (String)

    Name of the IDL function

Returns:

  • (String)

    A hyperlink to UDB IDL function documentation



179
180
181
# File 'lib/udb_helpers/backend_helpers.rb', line 179

def link_to_udb_doc_idl_func(func_name)
  "%%UDB_DOC_LINK%func;#{func_name.sanitize};#{func_name}%%"
end

Returns A hyperlink to UDB instruction documentation.

Parameters:

  • inst_name (String)

    Name of the instruction

Returns:

  • (String)

    A hyperlink to UDB instruction documentation



147
148
149
# File 'lib/udb_helpers/backend_helpers.rb', line 147

def link_to_udb_doc_inst(inst_name)
  "%%UDB_DOC_LINK%inst;#{inst_name.sanitize};#{inst_name}%%"
end

Returns A hyperlink to UDB MMR documentation.

Parameters:

  • mmr_name (String)

    Name of the MMR

Returns:

  • (String)

    A hyperlink to UDB MMR documentation



166
167
168
# File 'lib/udb_helpers/backend_helpers.rb', line 166

def link_to_udb_doc_mmr(mmr_name)
  "%%UDB_DOC_LINK%mmr;#{mmr_name.sanitize};#{mmr_name}%%"
end

Returns A hyperlink to UDB MMR field documentation.

Parameters:

  • mmr_name (String)

    Name of the MMR

  • field_name (String)

    Name of the MMR field

Returns:

  • (String)

    A hyperlink to UDB MMR field documentation



173
174
175
# File 'lib/udb_helpers/backend_helpers.rb', line 173

def link_to_udb_doc_mmr_field(mmr_name, field_name)
  "%%UDB_DOC_LINK%mmr_field;#{mmr_name.sanitize}.#{field_name.sanitize};#{mmr_name}.#{field_name}%%"
end

#partial(template_pname, inputs = {}) ⇒ String

Include a partial ERB template into a full ERB template.

Parameters:

  • template_pname (String)

    Path to template file relative to “backends” directory.

  • inputs (Hash<String, Object>) (defaults to: {})

    Input objects to pass into template

Returns:

  • (String)

    Result of ERB evaluation of the template file

Raises:

  • (ArgumentError)


106
107
108
109
110
111
112
113
114
# File 'lib/udb_helpers/backend_helpers.rb', line 106

def partial(template_pname, inputs = {})
  template_path = Pathname.new($root / "backends" / template_pname)
  raise ArgumentError, "Template '#{template_path} not found" unless template_path.exist?

  erb = ERB.new(template_path.read, trim_mode: "-")
  erb.filename = template_path.realpath.to_s

  erb.result(OpenStruct.new(inputs).instance_eval { binding })
end