Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: MeirKriheli/statirator
base: 632ebab8da
...
head fork: MeirKriheli/statirator
compare: 057e74806f
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  .gitignore
@@ -6,3 +6,4 @@
bin/
develop-eggs/
parts/
+test_site
View
6 statirator/commands.py
@@ -22,7 +22,7 @@ def init(args):
languages=args.languages)
site.create()
-def _site_site_from_config():
+def _site_from_config():
sys.path.append(os.path.abspath(os.getcwd()))
from config import site
@@ -34,8 +34,8 @@ def generate(args):
should be run from site's root (location of config.py)"""
- site = _site_site_from_config()
- site.compile()
+ site = _site_from_config()
+ site.generate()
def serve(args):
"""Serve the site"""
View
24 statirator/main.py
@@ -1,4 +1,5 @@
import argparse
+import logging
from . import commands
def create_options():
@@ -7,22 +8,27 @@ def create_options():
parser = argparse.ArgumentParser(
'Staitrator - Static multilingual site and blog generator')
+ log_level_choices = ['error', 'info', 'debug', 'none']
+ parser.add_argument('--logging', choices=log_level_choices,
+ default='info',
+ help='Log level [Default: %(default)s]. "none" won\'t touch logging')
+
sub_parsers = parser.add_subparsers(help='Sub Commands help')
init = sub_parsers.add_parser('init', help='Initiate a new site')
init.add_argument('directory', help='Target directory')
init.add_argument('-n', '--name', default='Default site',
- help='Site name and title [default: %(default)s]')
+ help='Site name and title [Default: %(default)s]')
init.add_argument('-c', '--site_class', default='statirator.site.Html5Site',
- help='The base class for the site [default: %(default)s]')
+ help='The base class for the site [Default: %(default)s]')
init.add_argument('-s', '--source', default='source',
- help="Site's source directory [default: %(default)s]")
+ help="Site's source directory [Default: %(default)s]")
init.add_argument('-b', '--build', default='build',
- help="Site's build directory [default: %(default)s]")
+ help="Site's build directory [Default: %(default)s]")
init.add_argument('-l', '--languages', nargs='*', dest='languages',
default=['he', 'en'], help='Supported languages.'
- ' [default: %(default)s]')
+ ' [Default: %(default)s]')
init.set_defaults(func=commands.init)
@@ -35,10 +41,18 @@ def create_options():
return parser
+def setup_logging(args):
+ if args.logging == 'none':
+ return
+
+ root_logger = logging.getLogger()
+ root_logger.setLevel(getattr(logging, args.logging.upper()))
+
def main():
parser = create_options()
args = parser.parse_args()
+ setup_logging(args)
args.func(args)
if __name__ == '__main__':
View
86 statirator/site.py
@@ -1,11 +1,13 @@
"Site definition"
import os
+import re
import sys
-import shutil
import logging
import urllib.request
import urllib.error
+import zipfile
+import tempfile
from collections import defaultdict, deque
from jinja2 import Template
@@ -89,7 +91,7 @@ def walk_site(self):
if not asset.startswith(to_ignore):
yield os.path.relpath(root, self.source), asset
- def compile(self):
+ def generate(self):
"""Compiles the site from source to build dir"""
self.db = defaultdict(deque)
@@ -100,59 +102,59 @@ def compile(self):
class Html5Site(Site):
"""Basic Html5 site . Create:
+ - zurb foundation
- Basic _site.html template
- - Modernizr
- - normalize.css
"""
- NORMALIZE = 'https://raw.github.com/necolas/normalize.css/master/normalize.css'
+ FOUNDATION = 'http://foundation.zurb.com/files/foundation-download-2.2.zip'
def create(self):
"""Extra create elements"""
super(Html5Site, self).create()
- self.get_css()
- self.create_js()
- self.copy_templates()
-
- def get_css(self):
- "create the css dir, and download normalize"
-
- logging.info('Creating css directory')
- css_dir = os.path.join(self.root, self.source, 'css')
-
- os.makedirs(css_dir)
-
- logging.info('Getting normalize.css')
+ self.get_zurb_foundation()
+ def get_zurb_foundation(self):
+ logging.info('Getting zurb foundation')
try:
- normalize = urllib.request.urlopen(self.NORMALIZE)
- with open(os.path.join(css_dir, 'normalize.css'), 'w') as css_file:
- css_file.write(normalize.read().decode('utf-8'))
+ archive_req = urllib.request.urlopen(self.FOUNDATION)
+ archive_file = tempfile.TemporaryFile()
+ archive_file.write(archive_req.read())
+ logging.info('extracting zurb foundation')
+ with zipfile.ZipFile(archive_file) as foundation:
+ foundation.extractall(self.source)
+ self.customize_foundation()
except urllib.error.HTTPError as e:
- logging.error("Error getting normalize.css: {0}".format(e))
-
- def create_js(self):
- """Create js and download modernizr"""
+ logging.error("Error getting zurb foundation: {0}".format(e))
- logging.info('Creating js directory')
- js_dir = os.path.join(self.root, self.source, 'js')
+ def customize_foundation(self):
+ logging.info('Converting foundation to jinja templates')
- os.makedirs(js_dir)
-
- logging.info('Copying modernizr.js')
- modernizr = os.path.join(self.source_templates_dir, 'html5',
- 'modernizr.js')
- shutil.copy(modernizr, js_dir)
-
- def copy_templates(self):
- """Create dir and copy initial html templates"""
-
- logging.info('Creating _templates dir and copying templates')
- target_dir = os.path.join(self.root, self.source, '_templates')
+ # create the templates dir
+ target_dir = os.path.join(self.source, '_templates')
os.makedirs(target_dir)
- source_dir = os.path.join(self.source_templates_dir, 'html5')
-
- shutil.copy(os.path.join(source_dir, 'site.html'), target_dir)
+ index = os.path.join(self.source, 'index.html')
+ # read index.html
+ with open(index) as index_html:
+ orig_content = index_html.read()
+
+ template_content = orig_content.replace('lang="en"',
+ 'lang="{{ LANGUAGE_CODE }}" dir="{{ LANGUAGE_DIR }}"')
+
+ template_content = re.sub('<title>[^<]+<',
+ '<title>{% block title %}{% endblock %} - {{ site.name }}<', template_content)
+ template_content = re.sub(r'<!-- container -->.*?<!-- container -->',
+ '{% block content %}{% endblock %}', template_content, re.S)
+
+ parts = re.split(r'\s*<!-- container -->\s*', template_content)
+ parts[1:2] = [
+ '\t<header><h1>{{ site.name }}</h1></header>',
+ '{% block content %}{% endblock %}',
+ '\t<footer>Generated with Statirator</footer>'
+ ]
+ template_content = '\n'.join(parts)
+
+ with open(os.path.join(target_dir, 'site.html'), 'w') as site_tmpl:
+ site_tmpl.write(template_content)
View
1  statirator/templates/html5/site.html
@@ -14,4 +14,3 @@
<footer>footer goes here</footer>
</body>
</html>
-

No commit comments for this range

Something went wrong with that request. Please try again.