summaryrefslogtreecommitdiffstats
path: root/nikola/plugins
diff options
context:
space:
mode:
authorLibravatarAgustin Henze <tin@sluc.org.ar>2013-02-27 09:13:24 -0300
committerLibravatarAgustin Henze <tin@sluc.org.ar>2013-02-27 09:13:24 -0300
commit878ba1152ebc64a4a2609d23c9e400a6111db642 (patch)
tree7672c12a59dbab1864606109e4f2b1dd7534043c /nikola/plugins
parenta40930043121a4b60de8526d58417761a54ab718 (diff)
Imported Upstream version 5.3upstream/5.3
Diffstat (limited to 'nikola/plugins')
-rw-r--r--nikola/plugins/__init__.py1
-rw-r--r--nikola/plugins/command_build.py11
-rw-r--r--nikola/plugins/command_new_post.py4
-rw-r--r--nikola/plugins/task_create_bundles.py49
-rw-r--r--nikola/plugins/task_render_galleries.py11
-rw-r--r--nikola/plugins/task_render_listings.py12
-rw-r--r--nikola/plugins/task_render_sources.py1
7 files changed, 69 insertions, 20 deletions
diff --git a/nikola/plugins/__init__.py b/nikola/plugins/__init__.py
index b1de7f1..2d9b1b2 100644
--- a/nikola/plugins/__init__.py
+++ b/nikola/plugins/__init__.py
@@ -1,3 +1,4 @@
from __future__ import absolute_import
from . import command_import_wordpress # NOQA
+from . import command_build # NOQA
diff --git a/nikola/plugins/command_build.py b/nikola/plugins/command_build.py
index 29d4c9d..8a1de5f 100644
--- a/nikola/plugins/command_build.py
+++ b/nikola/plugins/command_build.py
@@ -38,8 +38,10 @@ class CommandBuild(Command):
"""Build the site using doit."""
# FIXME: this is crap, do it right
- with tempfile.NamedTemporaryFile(suffix='.py', delete=False) as dodo:
- dodo.write(b'''
+ with tempfile.NamedTemporaryFile(suffix='.py', delete=False) as self.dodo:
+ self.dodo.write(b'''
+import sys
+sys.path.insert(0, '.')
from doit.reporter import ExecutedOnlyReporter
DOIT_CONFIG = {
'reporter': ExecutedOnlyReporter,
@@ -53,12 +55,13 @@ SITE = Nikola(**conf.__dict__)
def task_render_site():
return SITE.gen_tasks()
''')
- dodo.flush()
+ self.dodo.flush()
first = args[0] if args else None
if first in ('auto', 'clean', 'forget', 'ignore', 'list', 'run'):
cmd = first
args = args[1:]
else:
cmd = 'run'
- os.system('doit %s -f %s -d . %s' % (cmd, dodo.name,
+ os.system('doit %s -f %s -d . %s' % (cmd, self.dodo.name,
''.join(args)))
+ os.unlink(self.dodo.name)
diff --git a/nikola/plugins/command_new_post.py b/nikola/plugins/command_new_post.py
index a5715de..9b6397b 100644
--- a/nikola/plugins/command_new_post.py
+++ b/nikola/plugins/command_new_post.py
@@ -110,9 +110,11 @@ class CommandNewPost(Command):
print("-----------------\n")
if title is None:
print("Enter title: ", end='')
+ # WHY, PYTHON3???? WHY?
+ sys.stdout.flush()
title = sys.stdin.readline()
else:
- print("Title: ", title)
+ print("Title:", title)
if isinstance(title, bytes):
title = title.decode(sys.stdin.encoding)
title = title.strip()
diff --git a/nikola/plugins/task_create_bundles.py b/nikola/plugins/task_create_bundles.py
index d024636..95f10c2 100644
--- a/nikola/plugins/task_create_bundles.py
+++ b/nikola/plugins/task_create_bundles.py
@@ -51,6 +51,8 @@ class BuildBundles(LateTask):
'output_folder': self.site.config['OUTPUT_FOLDER'],
'cache_folder': self.site.config['CACHE_FOLDER'],
'theme_bundles': get_theme_bundles(self.site.THEMES),
+ 'themes': self.site.THEMES,
+ 'files_folders': self.site.config['FILES_FOLDERS'],
}
def build_bundle(output, inputs):
@@ -74,8 +76,11 @@ class BuildBundles(LateTask):
for name, files in kw['theme_bundles'].items():
output_path = os.path.join(kw['output_folder'], name)
dname = os.path.dirname(name)
- file_dep = [os.path.join('output', dname, fname) for fname in
- files]
+ file_dep = [get_asset_path(
+ os.path.join(dname, fname), kw['themes'], kw['files_folders'])
+ for fname in files
+ ]
+ file_dep = filter(None, file_dep) # removes missing files
task = {
'file_dep': file_dep,
'basename': str(self.name),
@@ -95,6 +100,46 @@ class BuildBundles(LateTask):
}
+def get_asset_path(path, themes, files_folders={'files': ''}):
+ """Checks which theme provides the path with the given asset,
+ and returns the "real" path to the asset, relative to the
+ current directory.
+
+ If the asset is not provided by a theme, then it will be checked for
+ in the FILES_FOLDERS
+
+ >>> get_asset_path('assets/css/rst.css', ['site','default'])
+ 'nikola/data/themes/default/assets/css/rst.css'
+
+ >>> get_asset_path('assets/css/theme.css', ['site','default'])
+ 'nikola/data/themes/site/assets/css/theme.css'
+
+ >>> get_asset_path('nikola.py',['site','default'],{'nikola':''})
+ 'nikola/nikola.py'
+
+ >>> get_asset_path('nikola/nikola.py',['site','default'],{'nikola':'nikola'})
+ 'nikola/nikola.py'
+
+ """
+ for theme_name in themes:
+ candidate = os.path.join(
+ utils.get_theme_path(theme_name),
+ path
+ )
+ if os.path.isfile(candidate):
+ return os.path.relpath(candidate, os.getcwd())
+ for src, rel_dst in files_folders.items():
+ candidate = os.path.join(
+ src,
+ os.path.relpath(path, rel_dst)
+ )
+ if os.path.isfile(candidate):
+ return os.path.relpath(candidate, os.getcwd())
+
+ # whatever!
+ return None
+
+
def get_theme_bundles(themes):
"""Given a theme chain, return the bundle definitions."""
bundles = {}
diff --git a/nikola/plugins/task_render_galleries.py b/nikola/plugins/task_render_galleries.py
index 7fe1501..e69a457 100644
--- a/nikola/plugins/task_render_galleries.py
+++ b/nikola/plugins/task_render_galleries.py
@@ -91,6 +91,7 @@ class Galleries(Task):
output_gallery = os.path.dirname(os.path.join(
kw["output_folder"], self.site.path("gallery", gallery_name,
None)))
+ output_name = os.path.join(output_gallery, "index.html")
if not os.path.isdir(output_gallery):
yield {
'basename': str('render_galleries'),
@@ -126,15 +127,10 @@ class Galleries(Task):
pass
# List of sub-galleries
- folder_list = [x.split(os.sep)[-2] + os.sep for x in
+ folder_list = [x.split(os.sep)[-2] for x in
glob.glob(os.path.join(gallery_path, '*') + os.sep)]
- crumbs = gallery_path.split(os.sep)[:-1]
- crumbs.append(os.path.basename(gallery_name))
- # TODO: write this in human
- paths = ['/'.join(['..'] * (len(crumbs) - 1 - i)) for i in
- range(len(crumbs[:-1]))] + ['#']
- crumbs = list(zip(paths, crumbs))
+ crumbs = utils.get_crumbs(gallery_path)
image_list = [x for x in image_list if "thumbnail" not in x]
# Sort by date
@@ -213,7 +209,6 @@ class Galleries(Task):
'uptodate': [utils.config_changed(kw)],
}
- output_name = os.path.join(output_gallery, "index.html")
context = {}
context["lang"] = kw["default_lang"]
context["title"] = os.path.basename(gallery_path)
diff --git a/nikola/plugins/task_render_listings.py b/nikola/plugins/task_render_listings.py
index 6d1d853..a899f10 100644
--- a/nikola/plugins/task_render_listings.py
+++ b/nikola/plugins/task_render_listings.py
@@ -22,6 +22,8 @@
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+from __future__ import unicode_literals, print_function
+
import os
from pygments import highlight
@@ -60,14 +62,16 @@ class Listings(Task):
lineanchors=utils.slugify(f),
anchorlinenos=True))
title = os.path.basename(in_name)
- crumbs = out_name.split(os.sep)[1:-1] + [title]
+ print("CRUMBSINOUT", in_name, out_name)
+ #crumbs = out_name.split(os.sep)[1:-1] + [title]
# TODO: write this in human
- paths = ['/'.join(['..'] * (len(crumbs) - 2 - i)) for i in
- range(len(crumbs[:-2]))] + ['.', '#']
+ #paths = ['/'.join(['..'] * (len(crumbs) - 2 - i)) for i in
+ #range(len(crumbs[:-2]))] + ['.', '#']
+ crumbs = utils.get_crumbs(os.path.relpath(out_name, kw['output_folder']), is_file=True)
context = {
'code': code,
'title': title,
- 'crumbs': zip(paths, crumbs),
+ 'crumbs': crumbs,
'lang': kw['default_lang'],
'description': title,
}
diff --git a/nikola/plugins/task_render_sources.py b/nikola/plugins/task_render_sources.py
index bce8d69..529e68e 100644
--- a/nikola/plugins/task_render_sources.py
+++ b/nikola/plugins/task_render_sources.py
@@ -58,7 +58,6 @@ class Sources(Task):
lang, post.source_ext()))
source = post.source_path
if source.endswith('.html'):
- print("Avoiting to render source of .html page")
continue
if lang != kw["default_lang"]:
source_lang = source + '.' + lang