Skip to content

Commit

Permalink
Added support for multiple lines in the values.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoylen committed Jan 29, 2021
1 parent 4cfbf2e commit 126896a
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 453 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ doc/api/

# macOS files
.DS_Store

# Examples that won't be checked in

example/output-exclude-other.html
example/output-include-hidden.html
example/output-no-template.html
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

- Updated template syntax: commands start with _ and comments with #.
- Changed unused properties to other or hidden properties.
- Fixed handling of line endings in CSV files.
- Fixed handling of differnt line endings in CSV files.
- Output notes in the HTML.
- Added support for multiple lines in the values.

## 1.0.0

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ Rows for template items contain up to four columns, representing:
- enumeration; and
- notes.

The notes will be displayed in the properties section of the HTML.

The notes can contain multiple lines. If the field in the CSV starts
and ends with a double-quote, there can be new line characters (0x0A)
inside the value. Alternatively, the Unicode _line separator_
character (U+2028) can also be used.

The order in which the template items appear in the template is the
order in which they are shown in the record.

Expand Down
14 changes: 7 additions & 7 deletions bin/csv2html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class Config {
..addOption(_oParamOutput,
abbr: 'o', help: 'output file', valueHelp: 'FILE')
..addFlag(_oParamExcludeOther,
abbr: 'e', help: 'exclude other properties (_OTHER)')
abbr: 'e', negatable: false, help: 'exclude other properties (_OTHER)')
..addFlag(_oParamIncludeHidden,
abbr: 'i', help: 'include hidden properties (_HIDE)')
abbr: 'i', negatable: false, help: 'include hidden properties (_HIDE)')
..addFlag(_oParamVersion,
help: 'display version information and exit', negatable: false)
..addFlag(_oParamQuiet,
Expand All @@ -56,7 +56,7 @@ class Config {

// ignore: avoid_as
if (results[_oParamHelp] as bool) {
stdout.write('Usage: $_name [options]\n${parser.usage}\n');
stdout.write('Usage: $_name [options] csv_data_file\n${parser.usage}\n');
exit(0);
}

Expand Down Expand Up @@ -149,14 +149,14 @@ void main(List<String> arguments) {

final defaultTitle = p.split(config.dataFilename).last;

RecordTemplate template;
Template template;

final tName = config.templateFilename;
if (tName != null) {
final f = File(tName);
template = RecordTemplate.load(f.readAsStringSync());
template = Template.load(f.readAsStringSync());
} else {
template = RecordTemplate(data);
template = Template(data);
}

// Output destination
Expand All @@ -169,7 +169,7 @@ void main(List<String> arguments) {
final fmt = Formatter(template,
excludeOther: config.excludeOther, includeHidden: config.includeHidden);

final warnings = fmt.toHtml(data, defaultTitle, out,
final warnings = fmt.toHtml(data, defaultTitle, _version, out,
timestamp: File(config.dataFilename).lastModifiedSync());

// Show warnings
Expand Down
6 changes: 3 additions & 3 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ help:
@echo " all - run csv2html to generate example HTML files"
@echo " clean - delete all generated HTML files"

OUTPUTS=output.html \
EXTRA=\
output-include-hidden.html \
output-exclude-other.html \
output-no-template.html

all: ${OUTPUTS}
all: output.html ${EXTRA}

output.html: template.csv data.csv
../bin/csv2html.dart -o $@ -t template.csv data.csv
Expand All @@ -25,4 +25,4 @@ output-no-template.html: data.csv
../bin/csv2html.dart -o $@ data.csv

clean:
rm -f ${OUTPUTS}
rm -f ${EXTRA}
24 changes: 12 additions & 12 deletions example/data.csv
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
id,givenname,surname,displayname,street,city,state,social_security
0,John,Valuk,John Valuk,,,,1234567890
1,John,Emdall,John Emdall,,,,1234567891
2,John,Gant,John Gant,,,,1234567892
3,John,Parker,John Parker,,,,1234567893
4,John,Barnett,John Barnett,,,CA,1234567894
5,John,Bigboote,John Bigboote,1 Yoyodyne Drive,Trenton,NJ,1234567895
6,John,Whorfin,John Whorfin,,,,1234567896
7,John,Ya Ya,John Ya Ya,1 Yoyodyne Drive,Trenton,NJ,1234567897
8,John,O'Connor,John O'Connor,1 Yoyodyne Drive,Trenton,NJ,1234567898
9,John,Gomez,John Gomez,1 Yoyodyne Drive,Trenton,NJ,1234567899
10,John,Smallberries,John Smallberries,1 Yoyodyne Drive,Trenton,NJ,1234567900
givenname,surname,displayname,street,city,state,social_security
John,Valuk,John Valuk,,,,1234567890
John,Emdall,John Emdall,,,,1234567891
John,Gant,John Gant,,,,1234567892
John,Parker,John Parker,,,,1234567893
John,Barnett,John Barnett,,,CA,1234567894
John,Bigboote,John Bigboote,1 Yoyodyne Drive,Trenton,NJ,1234567895
John,Whorfin,John Whorfin,,,,1234567896
John,Ya Ya,John Ya Ya,1 Yoyodyne Drive,Trenton,NJ,1234567897
John,O'Connor,John O'Connor,1 Yoyodyne Drive,Trenton,NJ,1234567898
John,Gomez,John Gomez,1 Yoyodyne Drive,Trenton,NJ,1234567899
John,Smallberries,John Smallberries,1 Yoyodyne Drive,Trenton,NJ,1234567900

Loading

0 comments on commit 126896a

Please sign in to comment.