Skip to content

Commit

Permalink
Update pkgindex plugins for themes site
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
  • Loading branch information
Kwpolska committed Feb 21, 2017
1 parent 2d5abe5 commit b7e5e92
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 11 deletions.
4 changes: 4 additions & 0 deletions site/README.md
@@ -0,0 +1,4 @@
This site requires:

* Nikola
* site-requirements.txt installed
1 change: 1 addition & 0 deletions site/conf.py
Expand Up @@ -37,6 +37,7 @@
PKGINDEX_CONFIG = {
'extension': '.plugin',
'versions_supported': [7],
'json_filename': 'plugins.json',
}

plugins_submenu = (
Expand Down
8 changes: 7 additions & 1 deletion v7/pkgindex/README.md
Expand Up @@ -9,4 +9,10 @@ Package indexes are sites like <https://plugins.getnikola.com/>. They provide
both a human-friendly interface (website), and a computer-friendly interface
(JSON file). The generated package indexes are compatible with Nikola’s plugin
and theme install features; however, they can be modified to work with any
other packaging system (with some Python code)
other packaging system (with some Python code modification).

Users
-----

* [Nikola Plugins](https://plugins.getnikola.com/) — uses default plugin set [(source)](https://github.com/getnikola/plugins/tree/master/site)
* [Nikola Themes](https://themes.getnikola.com/) — uses default plugin set and a custom plugin for screenshots and demos [(source)](https://github.com/getnikola/nikola-themes/tree/master/site)
3 changes: 3 additions & 0 deletions v7/pkgindex/conf.py.sample
Expand Up @@ -9,6 +9,8 @@ PKGINDEX_DIRS = {
# * dirname_as_title takes post title (package name) from directory name
# * parse_plugin_file parse .plugin file and other Nikola-specific data
# (used on plugins.getnikola.com)
# * parse_theme_info parse files related to Nikola themes
# (used on themes.getnikola.com)
# * add_category add category meta data (useful with functools.partial)
# You may add custom callables to those lists.
PKGINDEX_HANDLERS = {
Expand All @@ -22,6 +24,7 @@ PKGINDEX_HANDLERS = {
PKGINDEX_CONFIG = {
'extension': '.plugin',
'versions_supported': [7],
'json_filename': 'plugins.json',
}

# Required supporting config. You may change `.plugin` to anything else.
Expand Down
2 changes: 1 addition & 1 deletion v7/pkgindex/pkgindex.plugin
Expand Up @@ -8,6 +8,6 @@ MinVersion = 7.8.2

[Documentation]
Author = Chris Warrick
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Generate package indexes (meta-plugin)
2 changes: 1 addition & 1 deletion v7/pkgindex/pkgindex.py
Expand Up @@ -12,4 +12,4 @@
class PackageIndex(ConfigPlugin):
"""Generate package indexes (meta-plugin)."""

name = "pkgindex_scan"
name = "pkgindex"
2 changes: 1 addition & 1 deletion v7/pkgindex_compiler/pkgindex_compiler.plugin
Expand Up @@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick, Roberto Alsina
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Compile pages in package indexes
50 changes: 49 additions & 1 deletion v7/pkgindex_compiler/pkgindex_compiler.py
Expand Up @@ -139,13 +139,61 @@ def parse_plugin_file(post, pkg_dir, config):
return data


def parse_theme_info(post, pkg_dir, config):
theme = os.path.basename(pkg_dir)
data = {}
data['name'] = theme
data['tags'] = 'theme'
out_path = post.folder_relative + '/' + theme
demo_dir = config['demo_screenshots_map'].get(out_path, out_path)
data['previewimage'] = '/' + demo_dir + '.png'
data['previewimage_thumbnail'] = '/' + demo_dir + '.thumbnail.png'
data['demo_link'] = '/' + demo_dir + '/demo/'
conf_sample = os.path.join(pkg_dir, 'conf.py.sample')
engine = os.path.join(pkg_dir, 'engine')
parent = os.path.join(pkg_dir, 'parent')

if os.path.exists(conf_sample):
with io.open(conf_sample, 'r', encoding='utf-8') as f:
data['confpy'] = pygments.highlight(
f.read(),
PythonLexer(), utils.NikolaPygmentsHTML(theme + '_conf_sample', linenos=False))
else:
data['confpy'] = None

if os.path.exists(engine):
with io.open(engine, 'r', encoding='utf-8') as f:
data['engine'] = f.read().strip()
else:
data['engine'] = 'mako'

if os.path.exists(parent):
with io.open(parent, 'r', encoding='utf-8') as f:
data['parent'] = f.read().strip()
elif theme == 'base':
pass
else:
raise ValueError("Theme {0} has no parent.".format(theme))

data['chain'] = utils.get_theme_chain(theme, [os.path.dirname(pkg_dir), 'themes'])
data['chain'] = [os.path.basename(i) for i in reversed(data['chain'])]
data['bootswatch'] = (('bootstrap' in data['chain'] or
'bootstrap-jinja' in data['chain'] or
'bootstrap3-jinja' in data['chain'] or
'bootstrap3' in data['chain']) and
'bootstrap3-gradients' not in data['chain'])

return data


def add_category(post, pkg_dir, config, args):
return {'category': args}


BUILTIN_HANDLERS = {
'dirname_as_title': dirname_as_title,
'parse_plugin_file': parse_plugin_file,
'parse_theme_info': parse_theme_info,
'add_category': add_category
}

Expand Down Expand Up @@ -182,7 +230,7 @@ def read_metadata(self, post, file_metadata_regexp=None, unslugify_titles=False,
raise Exception("PKGINDEX_CONFIG not found")

pkg_dir = os.path.split(post.source_path)[0]
top_dir = os.path.dirname(pkg_dir)
top_dir = post.folder_relative
metadata = {'slug': os.path.basename(pkg_dir)}
for handler in self.site.config['PKGINDEX_HANDLERS'][top_dir]:
if isinstance(handler, tuple):
Expand Down
2 changes: 1 addition & 1 deletion v7/pkgindex_scan/pkgindex_scan.plugin
Expand Up @@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Scan packages for package indexes
19 changes: 17 additions & 2 deletions v7/pkgindex_scan/pkgindex_scan.py
Expand Up @@ -49,7 +49,7 @@ def scan(self):
if 'PKGINDEX_CONFIG' not in self.site.config:
return []
config = self.site.config['PKGINDEX_CONFIG']
plugin_compiler = self.site.get_compiler('sample' + config['extension'])
compiler = self.site.get_compiler('sample' + config['extension'])
if not self.site.quiet:
print("Scanning package index posts...", end='', file=sys.stderr)
timeline = []
Expand All @@ -68,7 +68,22 @@ def scan(self):
False,
self.site.MESSAGES,
template_name,
plugin_compiler
compiler
)
post.is_two_file = True
timeline.append(post)
self.site.pkgindex_entries[topdir].append(post)

if 'special_entries' in config:
for source_path, destination, template_name, topdir in config['special_entries']:
post = Post(
source_path,
self.site.config,
destination,
False,
self.site.MESSAGES,
template_name,
compiler
)
post.is_two_file = True
timeline.append(post)
Expand Down
2 changes: 1 addition & 1 deletion v7/pkgindex_zip/pkgindex_zip.plugin
Expand Up @@ -8,6 +8,6 @@ MinVersion = 7.8.1+

[Documentation]
Author = Chris Warrick
Version = 0.1.0
Version = 0.2.0
Website = https://plugins.getnikola.com/
Description = Generate ZIP (and JSON) files for package indexes
6 changes: 4 additions & 2 deletions v7/pkgindex_zip/pkgindex_zip.py
Expand Up @@ -80,6 +80,8 @@ def gen_tasks(self):
for post in posts:
directory = os.path.dirname(post.source_path)
pkg_name = os.path.basename(directory)
if pkg_name in self.kw['pkgindex_config'].get('zip_ignore', []):
continue
destination = os.path.join(
self.kw['output_folder'],
self.kw['pkgindex_dirs'][dir][0],
Expand All @@ -98,7 +100,7 @@ def gen_tasks(self):
# Get list of dependencies and files to zip
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(('.pyc', '.DS_Store')):
if file.endswith(('.pyc', '.DS_Store')) or file == '.git':
continue
zip_files.append((os.path.join(root, file),
os.path.join(root[d:], file)))
Expand All @@ -118,7 +120,7 @@ def gen_tasks(self):
destination = os.path.join(
self.kw['output_folder'],
self.kw['pkgindex_dirs'][dir][0],
'plugins.json'
self.kw['pkgindex_config']['json_filename']
)
yield utils.apply_filters({
'basename': self.name,
Expand Down

0 comments on commit b7e5e92

Please sign in to comment.