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

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