From 42aae12e8af50f16dc336b6a98cb2a5181470b7a Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 27 Mar 2019 15:23:11 +0100 Subject: [PATCH] more parameter styling --- src/templates/Javadoc/Entities.jsx | 84 ++++++++++++++++++++++ src/templates/Javadoc/Entities.module.scss | 48 +++++++++++++ src/templates/Javadoc/index.jsx | 67 +---------------- src/templates/Javadoc/index.module.scss | 26 ------- 4 files changed, 133 insertions(+), 92 deletions(-) create mode 100644 src/templates/Javadoc/Entities.jsx create mode 100644 src/templates/Javadoc/Entities.module.scss diff --git a/src/templates/Javadoc/Entities.jsx b/src/templates/Javadoc/Entities.jsx new file mode 100644 index 00000000..a9270a8a --- /dev/null +++ b/src/templates/Javadoc/Entities.jsx @@ -0,0 +1,84 @@ +import React from 'react' +import slugify from 'slugify' +import { cleanPaths } from './utils' +import stylesDoc from '../Doc.module.scss' +import styles from './Entities.module.scss' + +const filterPropertyItems = (item, name) => { + let title + switch (name) { + case '@param': + title = 'Parameters' + break + case '@return': + title = 'Returns' + break + case '@throws': + title = 'Throws' + break + } + + return ( + <> + {item.filter(item => item.name === name).length > 0 && ( +

{title}

+ )} + {item + .filter(item => item.name === name) + .map((item, index) => { + if (item.name === '@param') { + const splitText = item.text.split(' ') + + return ( +
+ + {splitText[0]} + + + {splitText[2]} + +

{splitText[1]}

+
+ ) + } + + return
{item.text}
+ })} + + ) +} + +const Entities = ({ javadoc }) => { + return Object.entries(javadoc).map(([key, value]) => ( +
+

+ {cleanPaths(key)} +

+ +

{value[0][0].text}

+ + {value.map((item, index) => { + if (index === 0) return + + return ( +
+

Function Name

+ +

{item[0].text}

+ + {filterPropertyItems(item, '@param')} + {filterPropertyItems(item, '@return')} + {filterPropertyItems(item, '@throws')} +
+ ) + })} +
+ )) +} + +export default Entities diff --git a/src/templates/Javadoc/Entities.module.scss b/src/templates/Javadoc/Entities.module.scss new file mode 100644 index 00000000..946aeee8 --- /dev/null +++ b/src/templates/Javadoc/Entities.module.scss @@ -0,0 +1,48 @@ +@import 'variables'; + +.property { + padding: $spacer / 2; + border: 1px solid $brand-grey-lighter; + margin-bottom: $spacer; + border-radius: $border-radius; + + > p { + margin-bottom: $spacer; + } +} + +.subHeading { + font-size: $font-size-base; + border-bottom: 1px solid $brand-grey-lighter; + padding-bottom: $spacer / 4; + margin-bottom: $spacer / $line-height; + color: $brand-grey; +} + +.propertyName { + font-size: $font-size-large; + font-family: $font-family-monospace; + margin-bottom: $spacer / 2; + margin-top: 0; +} + +.parameter { + margin-top: $spacer / 4; + margin-bottom: $spacer / 2; +} + +.parameterType { + font-size: $font-size-small; + color: $brand-grey; + background: rgba($brand-blue, .2); + display: inline-block; + padding: 0 $spacer / 5; + border-radius: $border-radius; + vertical-align: middle; +} + +.param { + display: inline-block; + margin-right: $spacer / 4; + font-weight: 600; +} diff --git a/src/templates/Javadoc/index.jsx b/src/templates/Javadoc/index.jsx index 81a05115..7d57dd1f 100644 --- a/src/templates/Javadoc/index.jsx +++ b/src/templates/Javadoc/index.jsx @@ -2,7 +2,6 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { graphql } from 'gatsby' import Helmet from 'react-helmet' -import slugify from 'slugify' import Layout from '../../components/Layout' import Content from '../../components/Content' import HeaderSection from '../../components/HeaderSection' @@ -12,72 +11,8 @@ import SEO from '../../components/Seo' import stylesDoc from '../Doc.module.scss' import styles from './index.module.scss' +import Entities from './Entities' import Toc from './Toc' -import { cleanPaths } from './utils' - -const filterPropertyItems = (item, name) => { - let title - switch (name) { - case '@param': - title = 'Parameters' - break - case '@return': - title = 'Returns' - break - case '@throws': - title = 'Throws' - break - } - - return ( - <> - {item.filter(item => item.name === name).length > 0 && ( -

{title}

- )} - - {item - .filter(item => item.name === name) - .map((item, index) => ( -
- {item.text} -
- ))} - - ) -} - -const Entities = ({ javadoc }) => { - return Object.entries(javadoc).map(([key, value]) => ( -
-

- {cleanPaths(key)} -

- -

{value[0][0].text}

- - {value.map((item, index) => { - if (index === 0) return - - return ( -
-

Function Name

- -

{item[0].text}

- - {filterPropertyItems(item, '@param')} - {filterPropertyItems(item, '@return')} - {filterPropertyItems(item, '@throws')} -
- ) - })} -
- )) -} export default class JavadocTemplate extends Component { static propTypes = { diff --git a/src/templates/Javadoc/index.module.scss b/src/templates/Javadoc/index.module.scss index ac94e138..121cf527 100644 --- a/src/templates/Javadoc/index.module.scss +++ b/src/templates/Javadoc/index.module.scss @@ -1,31 +1,5 @@ @import 'variables'; -.property { - padding: $spacer / 2; - border: 1px solid $brand-grey-lighter; - margin-bottom: $spacer; - border-radius: $border-radius; - - > p { - margin-bottom: $spacer; - } -} - -.subHeading { - font-size: $font-size-base; - border-bottom: 1px solid $brand-grey-lighter; - padding-bottom: $spacer / 4; - margin-bottom: $spacer / 4; - color: $brand-grey; -} - -.propertyName { - font-size: $font-size-large; - font-family: $font-family-monospace; - margin-bottom: $spacer / 2; - margin-top: 0; -} - .namespace { font-size: $font-size-base; font-family: $font-family-monospace;