Rename YamlFrontmatter to just Frontmatter

This commit is contained in:
Joseph Earl 2017-04-09 19:32:33 +01:00
parent a2e8602fdd
commit dc313d157b
3 changed files with 21 additions and 21 deletions

View File

@ -1,11 +1,11 @@
import YAMLFrontmatter from '../yaml-frontmatter';
import Frontmatter from '../frontmatter';
const YamlFrontmatterFormatter = new YAMLFrontmatter();
const FrontmatterFormatter = new Frontmatter();
describe('YAMLFrontmatter', () => {
describe('Frontmatter', () => {
it('should parse YAML with --- delimiters', () => {
expect(
YamlFrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
FrontmatterFormatter.fromFile('---\ntitle: YAML\ndescription: Something longer\n---\nContent')
).toEqual(
{
title: 'YAML',
@ -17,7 +17,7 @@ describe('YAMLFrontmatter', () => {
it('should parse YAML with ---yaml delimiters', () => {
expect(
YamlFrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent')
FrontmatterFormatter.fromFile('---yaml\ntitle: YAML\ndescription: Something longer\n---\nContent')
).toEqual(
{
title: 'YAML',
@ -29,7 +29,7 @@ describe('YAMLFrontmatter', () => {
it('should overwrite any body param in the front matter', () => {
expect(
YamlFrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent')
FrontmatterFormatter.fromFile('---\ntitle: The Title\nbody: Something longer\n---\nContent')
).toEqual(
{
title: 'The Title',
@ -40,7 +40,7 @@ describe('YAMLFrontmatter', () => {
it('should parse TOML with +++ delimiters', () => {
expect(
YamlFrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
FrontmatterFormatter.fromFile('+++\ntitle = "TOML"\ndescription = "Front matter"\n+++\nContent')
).toEqual(
{
title: 'TOML',
@ -52,7 +52,7 @@ describe('YAMLFrontmatter', () => {
it('should parse TOML with ---toml delimiters', () => {
expect(
YamlFrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent')
FrontmatterFormatter.fromFile('---toml\ntitle = "TOML"\ndescription = "Something longer"\n---\nContent')
).toEqual(
{
title: 'TOML',
@ -64,7 +64,7 @@ describe('YAMLFrontmatter', () => {
it('should parse JSON with { } delimiters', () => {
expect(
YamlFrontmatterFormatter.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent')
FrontmatterFormatter.fromFile('{\n"title": "The Title",\n"description": "Something longer"\n}\nContent')
).toEqual(
{
title: 'The Title',
@ -76,7 +76,7 @@ describe('YAMLFrontmatter', () => {
it('should parse JSON with ---json delimiters', () => {
expect(
YamlFrontmatterFormatter.fromFile('---json\n{\n"title": "The Title",\n"description": "Something longer"\n}\n---\nContent')
FrontmatterFormatter.fromFile('---json\n{\n"title": "The Title",\n"description": "Something longer"\n}\n---\nContent')
).toEqual(
{
title: 'The Title',
@ -88,7 +88,7 @@ describe('YAMLFrontmatter', () => {
it('should stringify YAML with --- delimiters', () => {
expect(
YamlFrontmatterFormatter.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' })
FrontmatterFormatter.toFile({ body: 'Some content\nOn another line', tags: ['front matter', 'yaml'], title: 'YAML' })
).toEqual(
[
'---',

View File

@ -1,32 +1,32 @@
import YAML from './yaml';
import JSONFormatter from './json';
import YAMLFrontmatter from './yaml-frontmatter';
import Frontmatter from './frontmatter';
const yamlFormatter = new YAML();
const jsonFormatter = new JSONFormatter();
const YamlFrontmatterFormatter = new YAMLFrontmatter();
const FrontmatterFormatter = new Frontmatter();
function formatByType(type) {
// Right now the only type is "editorialWorkflow" and
// we always returns the same format
return YamlFrontmatterFormatter;
return FrontmatterFormatter;
}
export function formatByExtension(extension) {
return {
yml: yamlFormatter,
json: jsonFormatter,
md: YamlFrontmatterFormatter,
markdown: YamlFrontmatterFormatter,
html: YamlFrontmatterFormatter,
}[extension] || YamlFrontmatterFormatter;
md: FrontmatterFormatter,
markdown: FrontmatterFormatter,
html: FrontmatterFormatter,
}[extension] || FrontmatterFormatter;
}
function formatByName(name) {
return {
yaml: yamlFormatter,
frontmatter: YamlFrontmatterFormatter,
}[name] || YamlFrontmatterFormatter;
frontmatter: FrontmatterFormatter,
}[name] || FrontmatterFormatter;
}
export function resolveFormat(collectionOrEntity, entry) {

View File

@ -7,7 +7,7 @@ preliminaries(true);
yamlParser(true);
tomlParser(true);
export default class YAMLFrontmatter {
export default class Frontmatter {
fromFile(content) {
const result = preliminaries.parse(content);
const data = result.data;