@data-visuals/create 7.4.6 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-visuals/create",
3
- "version": "7.4.6",
3
+ "version": "7.6.0",
4
4
  "description": "Create graphics and features the Data Visuals way.",
5
5
  "scripts": {
6
6
  "build:docs": "doctoc README.md --github",
@@ -10,8 +10,9 @@
10
10
  font-weight: $font-weight-bold;
11
11
  font-size: to-rem(18);
12
12
  line-height: $line-height-title;
13
- margin-bottom: $gutter-half;
14
13
  text-align: left;
14
+ max-width: 41.5rem;
15
+ margin: 0 auto $gutter-half;
15
16
  }
16
17
 
17
18
  .graphic-category {
@@ -28,12 +29,15 @@
28
29
  .graphic-prose {
29
30
  font-size: to-rem(14);
30
31
  line-height: $line-height-body;
31
- margin-bottom: $gutter-half;
32
+ max-width: 41.5rem;
33
+ margin: 0 auto $gutter-half;
32
34
  }
33
35
 
34
36
  .graphic-footer {
35
37
  color: $color-grey;
36
38
  font-size: to-rem(12);
39
+ max-width: 41.5rem;;
40
+ margin: 0 auto $gutter-half;
37
41
  }
38
42
 
39
43
  .graphic-footer li {
@@ -2,6 +2,7 @@
2
2
  const { clearConsole, series } = require('../utils');
3
3
 
4
4
  // tasks
5
+ const parseFigma2html = require('../tasks/parse-figma2html');
5
6
  const api = require('../tasks/api');
6
7
  const clean = require('../tasks/clean');
7
8
  const serve = require('../tasks/serve');
@@ -9,7 +10,7 @@ const serve = require('../tasks/serve');
9
10
  async function develop() {
10
11
  clearConsole();
11
12
 
12
- const runner = series([clean, api, serve]);
13
+ const runner = series([parseFigma2html, clean, api, serve]);
13
14
 
14
15
  await runner();
15
16
  }
@@ -0,0 +1,116 @@
1
+ const colors = require('ansi-colors');
2
+ const fs = require('fs-extra');
3
+ const extract = require('extract-zip');
4
+
5
+ // internal
6
+ const paths = require('../paths');
7
+ const { resolve } = require('path');
8
+
9
+ // functions
10
+ const moveHtml = filename => {
11
+ // move the .html file in the app/templates directory
12
+ fs.renameSync(
13
+ 'workspace/' + filename + '.html',
14
+ 'app/templates/figma2html-output/' + filename + '.html'
15
+ );
16
+ };
17
+
18
+ const moveImages = filename => {
19
+ // move the image files in the app/assets/figma2html/FILENAME directory
20
+ const imagesPath = 'workspace/assets/figma2html/' + filename;
21
+ fs.readdir(imagesPath, (err, images) => {
22
+ images.forEach(image => {
23
+ console.log('moving ' + image + '...');
24
+ fs.renameSync(
25
+ imagesPath + '/' + image,
26
+ 'app/assets/figma2html/' + filename + '/' + image
27
+ );
28
+ });
29
+ });
30
+ };
31
+
32
+ const moveFiles = filename => {
33
+ console.log('Now moving the figma2html files...');
34
+
35
+ // check if there's app/templates/figma2html-output directory
36
+ const templatesPath = 'app/templates/figma2html-output';
37
+ try {
38
+ fs.accessSync(templatesPath);
39
+ } catch (err) {
40
+ fs.mkdirSync(templatesPath, err => {
41
+ if (err) {
42
+ console.log(err);
43
+ } else {
44
+ console.log('created figma2html-output directory!');
45
+ }
46
+ });
47
+ } finally {
48
+ moveHtml(filename);
49
+ }
50
+
51
+ // check if there's app/assets/figma2html directory
52
+ const assetsPath = 'app/assets/figma2html/';
53
+
54
+ try {
55
+ fs.accessSync(assetsPath);
56
+ console.log('figma2html directory already exists!');
57
+ } catch (err) {
58
+ fs.mkdirSync(assetsPath, err => {
59
+ if (err) {
60
+ console.log(err);
61
+ } else {
62
+ console.log('created new figma2html directory!');
63
+ }
64
+ });
65
+ } finally {
66
+ // create app/assets/figma2html/FILENAME directory
67
+ try {
68
+ fs.accessSync(assetsPath + filename);
69
+ console.log('app/assets/figma2html/' + filename + ' already exists!');
70
+ } catch (err) {
71
+ fs.mkdirSync(assetsPath + filename, err => {
72
+ if (err) {
73
+ console.log(err);
74
+ } else {
75
+ console.log('created figma2html/FILENAME directory!');
76
+ }
77
+ });
78
+ }
79
+ moveImages(filename);
80
+ }
81
+ };
82
+
83
+ const extractZip = async file => {
84
+ // extract the zip file
85
+ try {
86
+ console.log('Unzipping ' + colors.magentaBright(file) + '...');
87
+ await extract(
88
+ resolve('workspace/' + file),
89
+ // save the extracted zip file in the workspace directory
90
+ { dir: resolve('workspace') }
91
+ );
92
+ console.log(colors.magentaBright(file) + ' Extraction completed');
93
+ } catch (err) {
94
+ // handle any errors
95
+ } finally {
96
+ // get the file name
97
+ const filename = file.replace('.zip', '');
98
+ // then move files
99
+ moveFiles(filename);
100
+ }
101
+ };
102
+
103
+ module.exports = () => {
104
+ // check if a zip file exists in the workspace directory
105
+ fs.readdir('workspace', (err, files) => {
106
+ files.forEach(file => {
107
+ if (file.includes('assets')) {
108
+ // remove old assets files
109
+ fs.rmSync(file, { recursive: true, force: true });
110
+ } else if (file.includes('.zip')) {
111
+ // extract the zip file
112
+ extractZip(file);
113
+ }
114
+ });
115
+ });
116
+ };
@@ -12,7 +12,7 @@
12
12
  {% set graphicData = data.data %}
13
13
 
14
14
  {# used by the CMS #}
15
- {# if this is an ai2html graphic, fill out these variables #}
15
+ {# if this is an ai2html or figma2html graphic, fill out these variables #}
16
16
  {% set graphicTitle = context.headline %}
17
17
  {% set graphicCaption = '' %}
18
18
  {# graphicAltText is used by the CMS for accessibility #}
@@ -27,19 +27,23 @@
27
27
  {# data-graphic signifies that this can be embedded in the CMS #}
28
28
  <div class="app" data-graphic>
29
29
  {# data-title is used to grab the title in the CMS #}
30
- <h1 class="graphic-title" data-title>{{ context.headline | widont or 'The only member-supported, digital-first, nonpartisan media organization' | widont }}</h1>
30
+ <h1 class="graphic-title" data-title>{{ context.headline | widont or "The only member-supported, digital-first, nonpartisan media organization" | widont }}</h1>
31
31
  {# data-caption is used to grab the caption in the CMS #}
32
- <span data-caption>{{ prose(context.prose, context, graphicData) }}</span>
32
+ <div class="graphic-prose"><span data-caption>{{ prose(context.prose, context, graphicData) | widont or "Graphics chatter goes here" | widont }}</span></div>
33
33
 
34
34
  {# add name of your ai2html file here #}
35
35
  {# {% set ai2html = "" %}
36
36
  {% include "ai2html-output/" + ai2html + ".html" %} #}
37
37
 
38
+ {# add name of your figma2html file here #}
39
+ {# {% set figma2html = "" %}
40
+ {% include "figma2html-output/" + figma2html + ".html" %} #}
41
+
38
42
  {# data-source and data-credit are also used in the CMS #}
39
43
  <ul class="graphic-footer">
40
- {% if context.note %}<li>Note: <span data-note>{{ context.note }}</span></li>{% endif %}
41
- {% if context.source %}<li>Source: <span data-source>{{ context.source }}</span></li>{% endif %}
42
- {% if context.credit %}<li>Credit: <span data-credit>{{ context.credit }}</span></li>{% endif %}
44
+ {% if context.note %}<li>Note: <span data-note>{{ context.note | widont or "Graphics note goes here" | widont }}</span></li>{% endif %}
45
+ {% if context.source %}<li>Source: <span data-source>{{ context.source | widont or "Graphics source goes here" | widont }}</span></li>{% endif %}
46
+ {% if context.credit %}<li>Credit: <span data-credit>{{ context.credit or "YOUR NAME" }}</span></li>{% endif %}
43
47
  </ul>
44
48
  </div>
45
49
  {% endblock content %}