-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59f7377
commit 4acf10b
Showing
10 changed files
with
184 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
table { | ||
border-collapse: collapse; | ||
} | ||
|
||
table, | ||
td { | ||
padding: 5px 7px; | ||
border: 1px solid var(--color-border); | ||
} | ||
|
||
tr:first-child td { | ||
background: var(--color-border); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function render(fileContent) { | ||
// Create HTML table | ||
const previewDiv = document.getElementById("csv-preview"); | ||
const tableElement = document.createElement("table"); | ||
previewDiv.append(tableElement); | ||
|
||
function appendRows(rows) { | ||
const rowElements = rows | ||
.map(row => `<tr>${row.map(column => `<td>${column}</td>`).join("\n")}</tr>`) | ||
.join("\n"); | ||
tableElement.innerHTML = rowElements; | ||
} | ||
|
||
// Parse CSV | ||
Papa.parse(fileContent, { | ||
worker: true, | ||
chunk: results => appendRows(results.data), | ||
}); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> | ||
|
||
<link rel="stylesheet" type="text/css" href="../minireset.min.css" /> | ||
<link rel="stylesheet" type="text/css" href="../shared.css" /> | ||
<link rel="stylesheet" type="text/css" href="./csv-main.css" /> | ||
</head> | ||
|
||
<body> | ||
<div id="csv-preview"></div> | ||
|
||
<script src="csv-papaparse.min.js"></script> | ||
<script src="csv-main.js"></script> | ||
<script> | ||
const fileContent = `id,first_name,last_name,email,gender | ||
1,First name 1,Last name 1,[email protected],Male | ||
2,First name 2,Last name 2,[email protected],Female | ||
3,First name 3,Last name 3,[email protected],Male | ||
4,First name 4,Last name 4,[email protected],Female`; | ||
render(fileContent); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import Foundation | ||
import JavaScriptCore | ||
import os.log | ||
|
||
class CodeRenderer: Renderer { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Foundation | ||
import os.log | ||
|
||
class CsvRenderer: Renderer { | ||
private let cssUrl = Bundle.main.url(forResource: "csv-main", withExtension: "css") | ||
private let papaParsejsUrl = Bundle.main.url( | ||
forResource: "csv-papaparse.min", | ||
withExtension: "js" | ||
) | ||
private let renderjsUrl = Bundle.main.url(forResource: "csv-main", withExtension: "js") | ||
|
||
override func getStylesheets() -> [Stylesheet] { | ||
var stylesheets = super.getStylesheets() | ||
if let cssUrl = cssUrl { | ||
stylesheets.append(Stylesheet(url: cssUrl)) | ||
} else { | ||
os_log("Could not find main CSV stylesheet", type: .error) | ||
} | ||
return stylesheets | ||
} | ||
|
||
override func getHtml() -> String { | ||
"<div id=\"csv-preview\"></div>" | ||
} | ||
|
||
override func getScripts() -> [Script] { | ||
var scripts = super.getScripts() | ||
|
||
// Papa Parse library (parses CSV files) | ||
if let papaParsejsUrl = papaParsejsUrl { | ||
scripts.append(Script(url: papaParsejsUrl)) | ||
} else { | ||
os_log("Could not find Papa Parse script", type: .error) | ||
} | ||
|
||
// Render script (generates HTML table from parsed CSV) | ||
if let renderjsUrl = renderjsUrl { | ||
scripts.append(Script(url: renderjsUrl)) | ||
} else { | ||
os_log("Could not find CSV render script", type: .error) | ||
} | ||
|
||
// Main script (calls render function with file content) | ||
scripts.append(Script(content: """ | ||
const fileContent = `\(fileContent.replacingOccurrences(of: "`", with: "\\`"))`; | ||
render(fileContent); | ||
""")) | ||
|
||
return scripts | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters