Welcome to mirror list, hosted at ThFree Co, Russian Federation.

expand.js « shortcode « admin « static - github.com/vjeantet/hugo-theme-docport.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e665254ddd60b0b8d9ec58f83c947f490224a89f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
CMS.registerEditorComponent({
  // Internal id of the component
  id: "expand",
  // Visible label
  label: "Expand",
  // Fields the user need to fill out when adding an instance of the component
  fields: [
  		{ label: 'Label', name: 'label', default:'Expand me !', widget: 'string' },
  		{ label: 'Text to expand', name: 'text', widget: 'markdown' }
  	],
  // Pattern to identify a block as being an instance of this component
  pattern: /^{{% expand "(\w+)" %}}(.*?){{% \/expand %}}/s,


  // Function to extract data elements from the regexp match
  fromBlock: function(match) {
    return {
      label: match[1],
      text: match[2]
    };
  },
  // Function to create a text block from an instance of this component
  toBlock: function(obj) {
    return '{{% expand "'+obj.label+'" %}}'+obj.text+'{{% /expand %}}';
  },
  // Preview output for this component. Can either be a string or a React component
  // (component gives better render performance)
  toPreview: function(obj) {
    return (
      '<strong> expand : '+obj.label+' -- '+obj.text+'</strong>'
    );
  }
});