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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. <prolog>
  13. <metadata>
  14. <keywords>
  15. <indexterm><xmlelement>require</xmlelement></indexterm>
  16. <indexterm>HTML<indexterm>custom plug-in</indexterm></indexterm>
  17. <indexterm>HTML<indexterm>CSS</indexterm></indexterm>
  18. <indexterm>CSS<indexterm>HTML transforms</indexterm></indexterm>
  19. </keywords>
  20. </metadata>
  21. </prolog>
  22. <taskbody>
  23. <context>
  24. <p>This scenario walks through the process of creating a very simple plug-in
  25. (<codeph>com.example.html5-custom-css</codeph>) that creates a new transformation type:
  26. <option>html5-custom-css</option>. </p>
  27. <p>The <option>html5-custom-css</option> transformation includes a custom CSS file and sets four parameters to
  28. integrate the custom stylesheet in the generated HTML5 output. These parameter settings make the following
  29. changes:</p>
  30. <ul>
  31. <li>
  32. <p>Specify the <filepath>css</filepath> subfolder of the plug-in as the source directory for custom CSS with
  33. <parmname>args.cssroot</parmname>.</p></li>
  34. <li>
  35. <p>Specify the name of the custom CSS file with <parmname>args.css</parmname>.</p>
  36. <p>The value of this parameter tells DITA-OT to use the <filepath>custom.css</filepath> file provided by the
  37. plug-in.</p></li>
  38. <li>
  39. <p>Ensure that the CSS file is copied to the output directory by setting <parmname>args.copycss</parmname> to
  40. <option>yes</option>.</p></li>
  41. <li>
  42. <p>Set the destination path for CSS files in the output folder with <parmname>args.csspath</parmname>.</p>
  43. <p>CSS files are copied to the root level of the output folder by default. Setting this parameter places CSS
  44. files in a dedicated <filepath>css</filepath> subfolder.</p></li>
  45. </ul>
  46. <p>All four parameters are set in the Ant script (<filepath>build_html5-custom-css.xml</filepath>).</p>
  47. </context>
  48. <steps>
  49. <step>
  50. <cmd>In the <filepath>plugins</filepath> directory, create a directory named
  51. <filepath>com.example.html5-custom-css</filepath>.</cmd>
  52. </step>
  53. <step>
  54. <cmd>In the new <filepath>com.example.html5-custom-css</filepath> directory, create a plug-in configuration file
  55. (<filepath>plugin.xml</filepath>) that declares the new <option>html5-custom-css</option> transformation and
  56. its dependencies.</cmd>
  57. <stepxmp>
  58. <fig>
  59. <title>Sample <filepath>plugin.xml</filepath> file</title>
  60. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-custom-css/plugin.xml"/></codeblock>
  61. </fig>
  62. <note>This plug-in will extend the default HTML5 transformation, so the <xmlelement>require</xmlelement>
  63. element explicitly defines <filepath>org.dita.html5</filepath> as a dependency.</note>
  64. </stepxmp>
  65. </step>
  66. <step>
  67. <cmd>In the <filepath>com.example.html5-custom-css</filepath> directory, create a subdirectory named
  68. <filepath>css</filepath>.</cmd>
  69. </step>
  70. <step>
  71. <cmd>In the new <filepath>css</filepath> subdirectory, create a file named <filepath>custom.css</filepath> with
  72. your custom CSS rules.</cmd>
  73. <stepxmp>
  74. <fig>
  75. <title>Sample <filepath>custom.css</filepath> file</title>
  76. <codeblock outputclass="language-css normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-custom-css/css/custom.css"/></codeblock>
  77. </fig>
  78. <note type="tip">When you first create the plug-in, you may want to include a rule in your custom stylesheet
  79. that makes it readily apparent when the custom styles are applied (the example above will change body text
  80. to “red”). Once you have verified that the plug-in works as intended, replace the placeholder rule with your
  81. own custom styles.</note>
  82. </stepxmp>
  83. </step>
  84. <step>
  85. <cmd>In the <filepath>com.example.html5-custom-css</filepath> root directory, add an Ant script
  86. (<filepath>build_html5-custom-css.xml</filepath>) to define the transformation type.</cmd>
  87. <stepxmp>
  88. <fig>
  89. <title>Sample build file: <filepath>build_html5-custom-css.xml</filepath></title>
  90. <codeblock outputclass="language-xml normalize-space show-line-numbers show-whitespace"><coderef href="../samples/plugins/com.example.html5-custom-css/build_html5-custom-css.xml"/></codeblock>
  91. </fig>
  92. </stepxmp>
  93. </step>
  94. </steps>
  95. <result>
  96. <note type="tip">The files for this sample plug-in are included in the DITA-OT installation directory under
  97. <filepath>docsrc/samples/plugins/com.example.html5-custom-css/</filepath> and on
  98. <xref href="https://github.com/dita-ot/docs/tree/develop/samples/plugins/com.example.html5-custom-css"
  99. format="html" scope="external">GitHub</xref>.</note>
  100. <p>The plug-in directory has the following layout and files:</p>
  101. <codeblock>com.example.html5-custom-css
  102. ├── build_html5-custom-css.xml
  103. ├── css
  104. │   └── custom.css
  105. └── plugin.xml</codeblock>
  106. </result>
  107. <postreq>
  108. <ol>
  109. <li>Run <filepath conref="../resources/conref-task.dita#ID/dita-cmd"/>
  110. <parmname>--install</parmname> to install the plug-in and make the <option>html5-custom-css</option>
  111. transformation available.</li>
  112. <li>Build output with the new transformation type to verify that the plug-in works as intended.
  113. <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>
  114. </li>
  115. <li>Refine the styles in your <filepath>custom.css</filepath> file as necessary.</li>
  116. </ol>
  117. </postreq>
  118. </taskbody>
  119. </task>