Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Themes 926 #654

Merged
merged 10 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fluffy-elephants-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wpmedia/text-output-block": patch
---

Added text output block
7 changes: 4 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ module.exports = {
overrides: [
{
files: ['*.test.js', '__mocks__/**'],
env: {
jest: true,
},

},
],
env: {
jest: true,
},
}
2 changes: 1 addition & 1 deletion blocks/sitemap-section-feature-block/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions blocks/text-output-block/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
3 changes: 3 additions & 0 deletions blocks/text-output-block/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Text Output Type

Used to generate text output
1 change: 1 addition & 0 deletions blocks/text-output-block/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
5 changes: 5 additions & 0 deletions blocks/text-output-block/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const base = require("../../jest/jest.config.base");

module.exports = {
...base,
};
1 change: 1 addition & 0 deletions blocks/text-output-block/output-types/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should match the snapshot 1`] = `"hello world"`;
19 changes: 19 additions & 0 deletions blocks/text-output-block/output-types/text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import PropTypes from 'prop-types'
import Consumer from 'fusion:consumer'

export function TextOutputType(children){
const generateText = (child) => {
if (Array.isArray(child)) return child.map(generateText).join('\n')
return child
}
return generateText(children)
};

TextOutputType.contentType = "text/plain";

TextOutputType.fallback = false;

TextOutputType.propTypes = {
children: PropTypes.node,
}
export default Consumer(TextOutputType)
20 changes: 20 additions & 0 deletions blocks/text-output-block/output-types/text.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* this is for mocking node env
* will not have window attribute, testing ssr
* https://jestjs.io/docs/en/configuration.html#testenvironment-string
* @jest-environment node
*/
// eslint-disable-next-line no-unused-vars
import Consumer from 'fusion:consumer'
import {TextOutputType} from "./text";

it('should match the snapshot', () => {
const videoSitemap = TextOutputType("hello world")
expect(videoSitemap).toMatchSnapshot()
})

it("should render array of children as plain text", () => {
const videoSitemap = TextOutputType(["hello world", "print output"])
expect(videoSitemap).toEqual("hello world\nprint output");
});

46 changes: 46 additions & 0 deletions blocks/text-output-block/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions blocks/text-output-block/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@wpmedia/text-output-block",
"version": "0.0.1",
"description": "Fusion News Theme text output block",
"main": "index.js",
"files": [
"output-types"
],
"license": "CC-BY-NC-ND-4.0",
"repository": {
"type": "git",
"url": "ssh://[email protected]/WPMedia/feed-components.git",
"directory": "blocks/text-output-block"
},
"publishConfig": {
"registry": "https://npm.pkg.github.com/",
"access": "public"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1",
"lint": "eslint --ext js --ext jsx features"
},
"devDependencies": {
"prop-types": "^15.7.2"
},
"gitHead": "83fb8d6685958d85ddbfcfbf01d9a5c864cd6c95"
}
Loading