Refactoring
Esc
Start typing to search...
how to
On this page

Refactoring

Files in a documentation set depend on one another. When you rename a file, key, or element ID, references in other files must change too. The editor's refactoring commands update those references.

The rule that makes them safe

Every refactoring prints a plan and changes nothing. You read the plan, then run the same command again with --apply.

bash
dogsbay-xml rename-key product-name product --root .
dogsbay-xml rename-key product-name product --root . --apply

In the editor the same plan appears as a table you review before it runs.

Note

Two commands work the other way round. edit-map and edit-reltable write unless you pass --dry-run, and so does metadata-set. They are editors rather than refactorings.

Before you change anything

Ask what depends on it:

bash
dogsbay-xml where-used topics/installing-audacity.dita \
  --root . --map audacity-guide.ditamap

With --map, the report includes references that reach the file indirectly through a key, which are the ones a search would miss.

What each refactoring is for

Moving and renaming

CommandUse it when
rename-fileA file's name or location is wrong.
rename-keyA key's name is wrong, or you are aligning a naming scheme.
rename-element-idAn element ID is wrong and conrefs point at it.
rename-profile-valueA condition value changes, such as mac becoming macos.
delete-fileA file should go. It reports inbound references first, so you find out before rather than after.
retargetTwo files should become one: point every reference from one at the other.

Changing how content is referenced

CommandUse it when
keyifyA file is referenced by path in many places and should be a key.
inline-keyA key is not earning its indirection.
extract-conrefThe same content is repeated and should be reused from one place.
inline-conrefReused content should become a local copy again.
create-keydefYou want a text key, such as a product name, defined once.
merge-keydefsA map's closure defines the same key more than once and only the first can win.

Restructuring

CommandUse it when
split-topicA topic has grown into several. Each top-level section becomes a topic, and the map is updated to include them.

A worked example

This example turns a hardcoded product name into a key. It fixes one of the problems in the sample project.

  1. Define the key The key name and the text it resolves to are the two arguments; the map that receives the definition is an option.
    bash
    dogsbay-xml create-keydef product-name Audacity \
      --map keydefs-product.ditamap --apply
  2. Replace the hardcoded text as well --replace-in rewrites whole-word occurrences of the text under a root into key references, which is the part that would otherwise be a hundred manual edits.
    bash
    dogsbay-xml create-keydef product-name Audacity \
      --map keydefs-product.ditamap --replace-in topics
  3. Apply it Run the same command with --apply once the plan looks right.
  4. Check the result
    bash
    dogsbay-xml project-health . --map audacity-guide.ditamap

When a refactoring refuses

If a refactoring would create a broken reference, it reports the problem instead of making the change. Review the plan to find unsafe changes before they affect the output.