Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on #379. #380

Merged
merged 1 commit into from
Apr 28, 2017
Merged

Work on #379. #380

merged 1 commit into from
Apr 28, 2017

Conversation

mjordan
Copy link
Collaborator

@mjordan mjordan commented Apr 26, 2017

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
Copy link
Collaborator Author

mjordan commented Apr 26, 2017

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

@MarcusBarnes
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants