MarcusBarnes / mik

The Move to Islandora Kit is an extensible PHP command-line tool for converting source content and metadata into packages suitable for importing into Islandora (or other digital repository and preservations systems).
GNU General Public License v3.0
34 stars 11 forks source link

Work on #379. #380

Closed mjordan closed 7 years ago

mjordan commented 7 years ago

Github issue: (#379)

What does this Pull Request do?

Moves the custom Twig filter TwigTruncate code to a utility class so it can be shared across metadatamanipulators and metadataparsers that use Twig templates.

What's new?

Adds a new MIK utility class, src/utilities/MikTwigExtension.php, that is used within metadatamanipulators and metadataparsers like this:

$truncate_filter = new \Twig_SimpleFilter('TwigTruncate', 'mik\utilities\MikTwigExtension::TwigTruncate');
$twig->addFilter($truncate_filter);

The custom TwigTruncate filter is then available in metadatamanipulators and metadataparsers using logic like this:

{% if Title|length < 30 %}
  <titleInfo>
     <title>{{ Title }}</title>
  </titleInfo>
{% else %}
  <titleInfo>
     <title>{{ Title|TwigTruncate(30) }}</title>
  </titleInfo>
{% endif %}

How should this be tested?

Since this branch makes it possible to share code between a metadata parser and a metadata manipulator, we should test both.

  1. Unzip the attached configuration and data files.
  2. Check out the issue-379 branch and run composer dump-autoload or equivalent.
  3. Test the Templated metadata parser first by running ./mik -c issue_379_parser.ini. Output files will be in /tmp/issue_379_output.
  4. image01.xml, image05.xml, and image05.xml will have titles that have been truncated at the word boundary closest to 30 characters (refer to the input file issue_379_metadata.csv to confirm this is the case).
  5. Delete the /tmp/issue_379_output and /tmp/issue_379_temp directories.
  6. Test the InsertXmlFromTemplate metadata manipulator first by running ./mik -c issue_379_manipulator.ini. Output files will be in /tmp/issue_379_output.
  7. image01.xml, image05.xml, and image05.xml will have titles that have been truncated at the word boundary closest to 30 characters (refer to the input file issue_379_metadata.csv to confirm this is the case).

issue_379.zip

Additional Notes

We should start a Cookbook entry that documents all of the MIK-specific Twig extenstions (currently there is only one).

Interested parties

@MarcusBarnes

mjordan commented 7 years ago

First draft of the Cookbook entry is at https://github.com/MarcusBarnes/mik/wiki/Cookbook:-MIK's-custom-Twig-extensions.

MarcusBarnes commented 7 years ago

Tested and appears to function as described. Thank you @mjordan.