Common Numbering API

Last modified by Manuel Leduc on 2024/12/04 16:08

cogProvides common operations to support the numbering of content elements. For instance, the definition of shared CSS files.
TypeJAR
CategoryAPI
Developed by

Manuel Leduc, Michael Hamann

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1
Compatibility

14.10+

Installable with the Extension Manager

Description

Provides common operations to support the numbering of content elements. For instance, the definition of shared CSS files.

This extension is only for developers.

Developers

CSS Counter Provider

This role is used to provide CSS counters that needs to be initialized at the root of the page content.
Is it currently implemented by figures and headings numbering.

/**
 * @since 1.10.3
 */


@Role
@Unstable
public interface CSSCountersProvider
{
   /**
     * @param locale the current locale
     * @return a set of selectors, and their rules
     */

    Set<String> selectors(Locale locale);

   /**
     * Similar to {@link #selectors(Locale)} but with for a {@code @supports (counter-set:nh1) {}} media query. By
     * default, reuse the results of {@link #selectors(Locale)}.
     *
     * @param locale the current locale
     * @return the selectors wrapped in a media query
     */

   default Set<String> selectorsCounterSet(Locale locale)
   {
       return selectors(locale);
   }
}

Script Service

Generate the CSS

$services.numbered.common.css returns a string of the CSS initializing the counters provided by CSSCountersProvider components.

#set ($locale = $services.localization.getCurrentLocale())
$services.numbered.common.css($locale)

Insert the CSS

This method needs to be called whenever the counters initialization CSS needs to be loaded in the page (i.e., when at least one kind of content numbering is activated).
Each kind of content numbering extension is in charge of calling insertCSS. But, insertCSS takes core of only loading the required CSS once for the whole page, even if it is called several times.

#set ($locale = $services.localization.getCurrentLocale())
#set ($discard = $services.numbered.common.insertCSS($locale))

Prerequisites & Installation Instructions

We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager).

You can also use the manual method which involves dropping the JAR file and all its dependencies into the WEB-INF/lib folder and restarting XWiki.

Dependencies

Dependencies for this extension (org.xwiki.contrib.numbered.content:application-numbered-content-common-api 1.10.3):

Get Connected