Skip to content

Commit

Permalink
Add csv usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
ssonal committed Jul 14, 2017
1 parent 6f913b7 commit 944429b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
8 changes: 8 additions & 0 deletions examples/using-csv/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"browser": true
},
"globals": {
"graphql": false
}
}
3 changes: 3 additions & 0 deletions examples/using-csv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public
.cache
node_modules
3 changes: 3 additions & 0 deletions examples/using-csv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# using-csv

https://using-csv.gatsbyjs.org
22 changes: 22 additions & 0 deletions examples/using-csv/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
siteMetadata: {
title: `gatsby-example-using-csv`,
description: `Blazing-fast React.js static site generator`,
},
plugins: [
`gatsby-transformer-csv`,
{
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: `UA-93349937-2`,
},
},
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/data`,
name: `data`,
},
},
],
}
19 changes: 19 additions & 0 deletions examples/using-csv/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "using-csv",
"private": true,
"description": "Gatsby example site using using-csv",
"author": "Sonal Saldanha <[email protected]>",
"dependencies": {
"gatsby": "latest",
"gatsby-link": "latest",
"gatsby-plugin-google-analytics": "latest",
"gatsby-source-filesystem": "latest",
"gatsby-transformer-csv": "latest"
},
"license": "MIT",
"main": "n/a",
"scripts": {
"develop": "gatsby develop",
"build": "gatsby build"
}
}
27 changes: 27 additions & 0 deletions examples/using-csv/src/data/letters.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
letter,value
A,65
B,66
C,67
D,68
E,69
F,70
G,71
H,72
I,73
J,74
K,75
L,76
M,77
N,78
O,79
P,80
Q,81
R,82
S,83
T,84
U,85
V,86
W,87
X,88
Y,89
Z,90
44 changes: 44 additions & 0 deletions examples/using-csv/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from "react"

class IndexComponent extends React.Component {
render() {
const data = this.props.data.allLettersCsv.edges
return (
<div>
<table>
<thead>
<tr>
<th>Letter</th>
<th>ASCII Value</th>
</tr>
</thead>
<tbody>
{data.map((row,i) => (<tr key={`${row.node.value} ${i}`}>
<td>
{row.node.letter}
</td>
<td>
{row.node.value}
</td>
</tr>))}
</tbody>
</table>
</div>
)
}
}

export default IndexComponent

export const IndexQuery = graphql`
query IndexQuery {
allLettersCsv {
edges {
node {
letter
value
}
}
}
}
`

0 comments on commit 944429b

Please sign in to comment.