html-customization-plugin-bundle-css.dita 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <task id="custom-html-plugin-bundle-css">
  5. <title>Bundling CSS in a custom HTML plug-in</title>
  6. <titlealts>
  7. <navtitle>Bundling custom CSS</navtitle>
  8. </titlealts>
  9. <shortdesc>You can create a DITA-OT plug-in that provides a custom stylesheet with the typography and colors that
  10. define your corporate identity. Coworkers can install this plug-in to ensure consistent HTML output across projects
  11. without having to copy the stylesheet to each project.</shortdesc>
  12. <taskbody>
  13. <context>
  14. <p>This scenario walks through the process of creating a very simple plug-in
  15. (<codeph>com.example.html5.custom.css</codeph>) that creates a new transformation type:
  16. <option>html5-custom-css</option>. </p>
  17. <p>The <option>html5-custom-css</option> transformation includes a custom CSS file and sets three parameters to
  18. integrate the custom stylesheet in the generated HTML5 output. These parameter settings make the following
  19. changes:</p>
  20. <ul>
  21. <li>
  22. <p>Specify the name of the custom .css file with <parmname>args.css</parmname>.</p>
  23. <p>The value of this parameter tells DITA-OT to use the custom .css file provided by the plug-in.</p></li>
  24. <li>
  25. <p>Ensure that the custom .css file is copied to the output directory by setting
  26. <parmname>args.copycss</parmname> to <option>yes</option>.</p></li>
  27. <li>
  28. <p>Set the relative path for .css files in the output folder with <parmname>args.csspath</parmname>.</p>
  29. <p>CSS files are copied to the root level of the output folder by default. Setting this parameter places CSS
  30. files in a dedicated subfolder.</p></li>
  31. </ul>
  32. <p>All three parameters are set in the Ant script (<filepath>build.xml</filepath>).</p>
  33. </context>
  34. <steps>
  35. <step>
  36. <cmd>In the <filepath>plugins</filepath> directory, create a directory named
  37. <filepath>com.example.html5.custom.css</filepath>.</cmd>
  38. </step>
  39. <step>
  40. <cmd>In the new <filepath>com.example.html5.custom.css</filepath> directory, create a plug-in configuration file
  41. (<filepath>plugin.xml</filepath>) that declares the new <option>html5-custom-css</option> transformation and
  42. its dependencies.</cmd>
  43. <stepxmp>
  44. <fig>
  45. <title>Sample <filepath>plugin.xml</filepath> file</title>
  46. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  47. <i>&lt;!-- This plug-in extends DITA-OT HTML5 processing with a custom CSS file. --&gt;</i>
  48. &lt;plugin id="com.example.html5.custom.css"&gt;
  49. <b>&lt;require plugin="org.dita.html5"/&gt;</b>
  50. <b>&lt;feature extension="dita.conductor.transtype.check" value="html5-custom-css"/&gt;</b>
  51. &lt;feature extension="dita.conductor.target.relative" file="build.xml"/&gt;
  52. &lt;/plugin&gt;</codeblock>
  53. </fig>
  54. <note>This plug-in will extend the default HTML5 transformation, so the <xmlelement>require</xmlelement>
  55. element explicitly defines <filepath>org.dita.html5</filepath> as a dependency.</note>
  56. </stepxmp>
  57. </step>
  58. <step>
  59. <cmd>In the <filepath>com.example.html5.custom.css</filepath> directory, create a subdirectory named
  60. <filepath>css</filepath>.</cmd>
  61. </step>
  62. <step>
  63. <cmd>In the new <filepath>css</filepath> subdirectory, create a file named <filepath>custom.css</filepath> with
  64. your custom CSS rules.</cmd>
  65. <stepxmp>
  66. <fig>
  67. <title>Sample <filepath>custom.css</filepath> file</title>
  68. <codeblock><i>/* These custom styles extend or override DITA Open Toolkit default styles. */</i>
  69. body {
  70. color: red
  71. }
  72. </codeblock>
  73. </fig>
  74. <note type="tip">When you first create the plug-in, you may want to include a rule in your custom stylesheet
  75. that makes it readily apparent when the custom styles are applied (the example above will change body text
  76. to “red”). Once you have verified that the plug-in works as intended, replace the placeholder rule with your
  77. own custom styles.</note>
  78. </stepxmp>
  79. </step>
  80. <step>
  81. <cmd>Add an Ant script (<filepath>build.xml</filepath>) to define the transformation type.</cmd>
  82. <stepxmp>
  83. <fig>
  84. <title>Sample <filepath>build.xml</filepath> file</title>
  85. <codeblock>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
  86. <i>&lt;!-- This plug-in extends DITA-OT HTML5 processing with a custom CSS file. --&gt;</i>
  87. &lt;project name="com.example.html5.custom.css"&gt;
  88. &lt;target name="dita2html5-custom-css"&gt;
  89. &lt;antcall target="dita2html5"&gt;
  90. <i>&lt;!-- Custom .css file used to style output --&gt;</i>
  91. <b>&lt;param name="args.css" value="${dita.plugin.com.example.html5.custom.css.dir}/css/custom.css"/&gt;</b>
  92. <i>&lt;!-- Copy the custom .css file to the output directory --&gt;</i>
  93. &lt;param name="args.copycss" value="yes"/&gt;
  94. <i>&lt;!-- Location of the copied .css file relative to the output --&gt;</i>
  95. &lt;param name="args.csspath" value="css"/&gt;
  96. &lt;/antcall&gt;
  97. &lt;/target&gt;
  98. &lt;/project&gt;</codeblock>
  99. </fig>
  100. </stepxmp>
  101. </step>
  102. </steps>
  103. <result>
  104. <p>The new plug-in directory has the following layout and files:</p>
  105. <codeblock>com.example.html5.custom.css
  106. ├── build.xml
  107. ├── css
  108. │ └── custom.css
  109. └── plugin.xml</codeblock>
  110. </result>
  111. <postreq>
  112. <ol>
  113. <li>Run <filepath conref="../resources/conref-task.dita#ID/dita-cmd"/>
  114. <parmname>--install</parmname> to install the plug-in and make the <option>html5-custom-css</option>
  115. transformation available.</li>
  116. <li>Build output with the new transformation type to verify that the plug-in works as intended.
  117. <codeblock><filepath conref="../resources/conref-task.dita#ID/dita-cmd"/> <parmname>--input</parmname>=<varname>my.ditamap</varname> <parmname>--format</parmname>=<option>html5-custom-css</option></codeblock>
  118. </li>
  119. <li>Refine the styles in your <filepath>custom.css</filepath> file as necessary.</li>
  120. </ol>
  121. </postreq>
  122. </taskbody>
  123. </task>