Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adc9119

Browse files
committed
add support for custom yml format
1 parent eb1474a commit adc9119

File tree

5 files changed

+62
-32
lines changed

5 files changed

+62
-32
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ upload:
1111
test:
1212
nosetests
1313
cd element/standalone/skeleton && nosetests
14+
cd docs && sphinx-build -nW -b html -d _build/doctrees . _build/html
1415

1516
install:
1617
pip install -r requirements_test.txt
@@ -20,7 +21,7 @@ doc:
2021
cd docs && sphinx-build -nW -b html -d _build/doctrees . _build/html
2122

2223
dev:
23-
cd element/standalone/skeleton && python start.py tornado:start --verbose -d --bind element.vagrant:5000
24+
cd element/standalone/skeleton && python start.py tornado:start --verbose -d --bind element.vagrant
2425

2526
prod:
2627
cd element/standalone/skeleton && python start.py tornado:start -np 8

docs/managers/filesystem.rst

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
.. note::
2-
3-
This documentation is under construction, more to come soon
4-
5-
6-
71
Filesystem
82
==========
93

104
Features
115
~~~~~~~~
126

13-
- Insert here the different feature available for this plugin
7+
- Load contents from a yaml file
148

159
Configuration
1610
~~~~~~~~~~~~~
1711

18-
- Insert the yaml configuration for the DI
12+
There is no configuration option.
13+
14+
15+
Usage
16+
~~~~~
17+
18+
You can create a yaml file with the following structure:
1919

2020
.. code-block:: yaml
2121
22-
element.plugins.cache:
23-
cache_control:
24-
- { "path": "^.*\\.(txt|jpg|png|gif|xls|doc|docx)$", "Cache-Control": ['public', 's-maxage=14212800']}
25-
- { "path": "^(blog|gallery).*", "Cache-Control": ['public', 's-maxage=3600']}
26-
- { "path": "^.*\\.rss", "Cache-Control": ['public', 's-maxage=3600']}
27-
- { "path": "^contact.*", "Cache-Control": ['private', 'must-revalidate']}
28-
- { "path": "^/$", "Cache-Control": ['public', 's-maxage=3600']}
22+
title: Inline Content
23+
type: blog.post
24+
tags: ['red', 'yellow']
25+
26+
----
27+
## my title
28+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean rutrum diam
29+
lectus, eget ultricies purus. Suspendisse pellentesque enim ullamcorper libero
30+
adipiscing vulputate.
2931
30-
Events
31-
~~~~~~
32+
## section 1
33+
Curabitur velit ipsum, sagittis volutpat porta at, imperdiet at risus. Donec ipsum nunc,
34+
commodo ut laoreet sed, mollis eu dolor. Praesent iaculis, nisl a laoreet elementum,
35+
odio lacus aliquam risus, et aliquam turpis metus vestibulum dolor.
3236
33-
- List event or entry points for this plugin
37+
Maecenas venenatis nulla in metus egestas sollicitudin. Donec convallis sodales
38+
massa, ac feugiat mauris tincidunt vel. Fusce eu leo vel nisi faucibus luctus.
3439
35-
Architecture
36-
~~~~~~~~~~~~
3740
38-
- Provide information about how the feature is implemented
41+
.. note::
42+
43+
As you notice the file is not a valid yaml file, all the data after the ``----`` separator will be available in the ``content`` field of the node object

element/loaders.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import os, yaml
1+
import os, yaml, re
22
import element
33

4+
45
class NodeLoader(object):
56
pass
67

@@ -41,7 +42,21 @@ def supports(self, path):
4142
return path[-3:] == 'yml' and os.path.isfile(path)
4243

4344
def load(self, path):
44-
return yaml.load(open(path, 'r'))
45+
content = open(path, 'r').read()
46+
47+
data = re.split("\n----\n", content, 2)
48+
49+
print data, len(data)
50+
51+
if len(data) > 1:
52+
content = data[0]
53+
54+
node = yaml.load(content)
55+
56+
if len(data) > 2:
57+
node['content'] = data[1]
58+
59+
return node
4560

4661
def save(self, path, data):
4762
yaml.safe_dump(data, file(path, 'w'),

tests/manager/test_fs.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,14 @@ def tearDown(self):
3232

3333

3434
def test_build_references(self):
35-
self.assertEquals(4, len(self.fs.files))
35+
self.assertEquals(5, len(self.fs.files))
3636

3737
expected = {
3838
'eacacfab-74cf-6c8d-5e393165': 'feeds',
3939
'50093cac-fdc1-5ba6-6f12d44e': 'feeds/all.rss',
4040
'fca0ea55-c21b-186e-fe6924a5': 'sonata_small.png',
41-
'c3e6be59-3448-0daa-be2dd043': '2013/my-post-content'
41+
'c3e6be59-3448-0daa-be2dd043': '2013/my-post-content',
42+
'fa3b5e88-acfb-fc73-90125d9e': '2013/inline-content',
4243
}
4344

4445
self.assertEquals(expected, self.fs.files)
@@ -70,14 +71,14 @@ def test_exists(self):
7071

7172
def test_find(self):
7273
cases = [
73-
({}, 4),
74-
({'type': 'blog.post'}, 1),
74+
({}, 5),
75+
({'type': 'blog.post'}, 2),
7576
({'type': 'fake'}, 0),
76-
({'type': 'fake', 'types': ['blog.post']}, 1),
77-
({'types': ['blog.post', 'fake']}, 1),
78-
({'types': [], 'tags': ['red', 'yellow']}, 1),
77+
({'type': 'fake', 'types': ['blog.post']}, 2),
78+
({'types': ['blog.post', 'fake']}, 2),
79+
({'types': [], 'tags': ['red', 'yellow']}, 2),
7980
({'types': [], 'tags': ['red', 'yellow', 'brown']}, 0),
80-
({'types': [], 'tags': []}, 4)
81+
({'types': [], 'tags': []}, 5)
8182
]
8283

8384
for kwarg, expected in cases:

tests/test_loaders.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def test_init(self):
2020

2121
self.assertIsNotNone(node['content'])
2222

23+
def test_load_inline(self):
24+
node = self.loader.load("%s/2013/inline-content.yml" % self.path)
25+
26+
27+
28+
2329
class InlineLoaderTest(unittest.TestCase):
2430

2531
def setUp(self):
@@ -38,3 +44,5 @@ def test_load(self):
3844

3945
self.assertEquals('hello', node['type'])
4046
self.assertEquals('salut', node['id'])
47+
48+

0 commit comments

Comments
 (0)