daylerees / kurenai Goto Github PK
View Code? Open in Web Editor NEWKurenai is a document with metadata parsing library for PHP.
Home Page: https://kurenai.readme.io
License: MIT License
Kurenai is a document with metadata parsing library for PHP.
Home Page: https://kurenai.readme.io
License: MIT License
Here is the error:
Notice: Undefined offset: 1 in /vendor/daylerees/kurenai/src/Parser.php on line 58
I assume that is for a wrong use of list
php function.
This "package" can't be used in php 5.3 because the DocumentParser class uses "callable" type hint, that is present in php >= 5.4.
I manually removed the type hint to could use it in a production server, but if you don't want to support php 5.3 I'll recomment to add a "note" in the readme.md or add it to composer dependency.
(I'm Spanish, sorry for my English!)
Regards and thnaks for this package! ๐
Hi @daylerees,
It is very funny I was working on something similar and I just discovered your repository.
May I bring some suggestions?
When you parse the document for metadata, why don't you use use Symfony\Component\Yaml\Yaml;
and then something like Yaml::parse($metadata);
. With that we will end with a similar key
=> `value' (multidimensional) array and you bring the power of Yaml inside your package which means we can put even more structured metadata.
My code looks like the following.
---
title: foo
slug: bar
tags: [foo, bar, baz]
related:
- foo: bar
baz: doo
---
@
# My markdown content
@
Then I extract the content with:
/**
* Extract content inside delimiters.
*
* @param string $start
* @param string $end
* @return string Extracted content.
*
* @source
* http://www.bitrepository.com/extract-content-between-two-delimiters-with-php.html
*/
protected function extract_unit($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
return trim($str_three);
}
But I admit I feel stupid because in your code you don't even need to use delimiter for the markdown content... I will dig in your code to see how you do the magic.
Then, once I have extracted the content between ---
I simply parse it with: return Yaml::parse($this->extract_unit($content, '---', '---'));
and voila.
What do you think about it and the use of Yaml?
Have you considered writing an extended Laravel ViewFactory
, that would first parse all blade templates for metadata before handing the content back to Laravel for normal handling?
I can think of a number of cases where I might want to allow views to offer up some config, and access that in the controller.
public function myControllerFunction()
{
$view = view('my.page');
if($view->getMetadata()['foo'] == 'bar') {
doSomething();
}
return $view;
}
my/page.blade.php
:
{
"foo": "bar"
}
===
@extends('layouts.main')
@section('content')
The rest of my normal blade template
@endsection
On https://kurenai.readme.io/docs/parsing-documents it is written:
$document->getMetdata(); // Get document metadata as array.
There is a typo: getMetdata --> getMetadata
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.