Commits

Andrey Vlasovskikh committed 4a784c5

Added --safe option

Comments (0)

Files changed (8)

 
 * Some command-line flags
 
-    The following command-line flags are not supported: `--safe`, `--config`,
-    `--future`, `--lsi`, `--limit_posts`.
+    The following command-line flags are not supported: `--config`, `--future`,
+    `--lsi`, `--limit_posts`.
 
 * Some config options
 
-    The following `_config.yml` options are not supported: `safe`, `timezone`,
-    `future`, `lsi`, `limit_posts`.
+    The following `_config.yml` options are not supported: `timezone`, `future`,
+    `lsi`, `limit_posts`.
 
 
 Not in Obraz
 Options:
     -s --source=DIR         Source directory.
     -d --destination=DIR    Destination directory.
+    --safe                  Disable custom plugins.
 
     -w --watch              Watch for changes and rebuild.
     --drafts                Render posts in the _drafts folder.
         info('Source: {0}'.format(os.path.abspath(config['source'])))
         info('Destination: {0}'.format(os.path.abspath(config['destination'])))
 
-        load_plugins(source)
+        if not config.get('safe'):
+            load_plugins(source)
 
         if opts['build']:
             build(config)

test/data/plugins/src/_plugins/plugin1.py

+from __future__ import unicode_literals
+import csv
+import os
+import obraz
+
+
+@obraz.loader
+def load_capitals(path, config):
+    test1_site = config.get('test1', {})
+    capitals_filename = test1_site.get('capitals_filename', 'capitals.csv')
+    if path != capitals_filename:
+        return None
+    with open(os.path.join(config['source'], path), 'r') as fd:
+        reader = csv.reader(fd)
+        capitals = dict((country, capital) for capital, country in reader)
+    return {
+        'test1': {
+            'capitals': capitals,
+        }
+    }
+
+
+@obraz.processor
+def process_size(site):
+    for page in site.get('pages', {}):
+        page['size'] = len(page['content'])
+
+
+@obraz.generator
+def generate_capitals_count_file(site):
+    name = os.path.join(site['destination'], 'capitals_count.txt')
+    with open(name, 'wb') as fd:
+        capitals = site.get('test1', {}).get('capitals', {})
+        data = '{0}\n'.format(len(capitals)).encode('UTF-8')
+        fd.write(data)

test/data/plugins/src/_plugins/test1.py

-from __future__ import unicode_literals
-import csv
-import os
-import obraz
-
-
-@obraz.loader
-def load_capitals(path, config):
-    test1_site = config.get('test1', {})
-    capitals_filename = test1_site.get('capitals_filename', 'capitals.csv')
-    if path != capitals_filename:
-        return None
-    with open(os.path.join(config['source'], path), 'r') as fd:
-        reader = csv.reader(fd)
-        capitals = dict((country, capital) for capital, country in reader)
-    return {
-        'test1': {
-            'capitals': capitals,
-        }
-    }
-
-
-@obraz.processor
-def process_size(site):
-    for page in site.get('pages', {}):
-        page['size'] = len(page['content'])
-
-
-@obraz.generator
-def generate_capitals_count_file(site):
-    name = os.path.join(site['destination'], 'capitals_count.txt')
-    with open(name, 'wb') as fd:
-        capitals = site.get('test1', {}).get('capitals', {})
-        data = '{0}\n'.format(len(capitals)).encode('UTF-8')
-        fd.write(data)

test/data/safe/site/index.html

+<p>Hello, <code>--safe</code>.</p>

test/data/safe/src/_plugins/plugin1.py

+raise NotImplementedError('plugin is not working')

test/data/safe/src/index.md

+---
+---
+
+Hello, `--safe`.

test/test_obraz.py

 
     def test_no_drafts(self):
         self.do('no_drafts')
+
+    def test_safe(self):
+        self.do('safe', ['--safe'])