comparison piecrust/appconfig.py @ 663:3ceeca7bb71c

themes: Add support for a `--theme` argument to `chef`.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 01 Mar 2016 22:27:28 -0800
parents 25df894f9ab9
children 81d9c3a3a0b5
comparison
equal deleted inserted replaced
662:cbd5cdec0695 663:3ceeca7bb71c
27 message or ("No such configuration variant: %s" % 27 message or ("No such configuration variant: %s" %
28 variant_path)) 28 variant_path))
29 29
30 30
31 class PieCrustConfiguration(Configuration): 31 class PieCrustConfiguration(Configuration):
32 def __init__(self, paths=None, cache=None, values=None, validate=True): 32 def __init__(self, paths=None, cache=None, values=None, validate=True,
33 super(PieCrustConfiguration, self).__init__(values, validate) 33 theme_config=False):
34 super(PieCrustConfiguration, self).__init__()
34 self.paths = paths 35 self.paths = paths
35 self.cache = cache or NullCache() 36 self.cache = cache or NullCache()
36 self.fixups = [] 37 self.fixups = []
38 self.theme_config = theme_config
39 # Set the values after we set the rest, since our validation needs
40 # our attributes.
41 if values:
42 self.setAll(values, validate=validate)
37 43
38 def applyVariant(self, variant_path, raise_if_not_found=True): 44 def applyVariant(self, variant_path, raise_if_not_found=True):
39 variant = self.get(variant_path) 45 variant = self.get(variant_path)
40 if variant is None: 46 if variant is None:
41 if raise_if_not_found: 47 if raise_if_not_found:
110 values = {} 116 values = {}
111 117
112 # Add the loaded values to the default configuration. 118 # Add the loaded values to the default configuration.
113 values = merge_dicts(copy.deepcopy(default_configuration), values) 119 values = merge_dicts(copy.deepcopy(default_configuration), values)
114 120
121 # Set the theme site flag.
122 if self.theme_config:
123 values['site']['theme_site'] = True
124
115 # Figure out if we need to generate the configuration for the 125 # Figure out if we need to generate the configuration for the
116 # default content model. 126 # default content model.
117 sitec = values.setdefault('site', {}) 127 sitec = values.setdefault('site', {})
118 if ( 128 if (
119 ('sources' not in sitec and 129 ('sources' not in sitec and
157 values['site']['blogs'] = blogsc 167 values['site']['blogs'] = blogsc
158 168
159 is_only_blog = (len(blogsc) == 1) 169 is_only_blog = (len(blogsc) == 1)
160 for blog_name in blogsc: 170 for blog_name in blogsc:
161 blog_cfg = get_default_content_model_for_blog( 171 blog_cfg = get_default_content_model_for_blog(
162 blog_name, is_only_blog, values) 172 blog_name, is_only_blog, values,
173 theme_site=self.theme_config)
163 values = merge_dicts(blog_cfg, values) 174 values = merge_dicts(blog_cfg, values)
164 175
165 dcm = get_default_content_model(values) 176 dcm = get_default_content_model(values)
166 values = merge_dicts(dcm, values) 177 values = merge_dicts(dcm, values)
167 178
197 'slugify_mode': 'encode', 208 'slugify_mode': 'encode',
198 'themes_sources': [DEFAULT_THEME_SOURCE], 209 'themes_sources': [DEFAULT_THEME_SOURCE],
199 'cache_time': 28800, 210 'cache_time': 28800,
200 'enable_debug_info': True, 211 'enable_debug_info': True,
201 'show_debug_info': False, 212 'show_debug_info': False,
202 'use_default_content': True 213 'use_default_content': True,
214 'theme_site': False
203 }), 215 }),
204 'baker': collections.OrderedDict({ 216 'baker': collections.OrderedDict({
205 'no_bake_setting': 'draft', 217 'no_bake_setting': 'draft',
206 'workers': None, 218 'workers': None,
207 'batch_size': None 219 'batch_size': None
254 }) 266 })
255 }) 267 })
256 }) 268 })
257 269
258 270
259 def get_default_content_model_for_blog(blog_name, is_only_blog, values): 271 def get_default_content_model_for_blog(
272 blog_name, is_only_blog, values, theme_site=False):
260 posts_fs = values['site']['posts_fs'] 273 posts_fs = values['site']['posts_fs']
261 blog_cfg = values.get(blog_name, {}) 274 blog_cfg = values.get(blog_name, {})
262 275
263 if is_only_blog: 276 if is_only_blog:
264 url_prefix = '' 277 url_prefix = ''
287 'tag_url', 300 'tag_url',
288 url_prefix + values['site']['tag_url']).lstrip('/') 301 url_prefix + values['site']['tag_url']).lstrip('/')
289 category_url = '/' + blog_cfg.get( 302 category_url = '/' + blog_cfg.get(
290 'category_url', 303 'category_url',
291 url_prefix + values['site']['category_url']).lstrip('/') 304 url_prefix + values['site']['category_url']).lstrip('/')
305
306 tags_taxonomy = 'pages:%s_tag.%%ext%%' % tax_page_prefix
307 category_taxonomy = 'pages:%s_category.%%ext%%' % tax_page_prefix
308 if not theme_site:
309 tags_taxonomy += ';theme_pages:_tag.%ext%'
310 category_taxonomy += ';theme_pages:_category.%ext%'
292 311
293 return collections.OrderedDict({ 312 return collections.OrderedDict({
294 'site': collections.OrderedDict({ 313 'site': collections.OrderedDict({
295 'sources': collections.OrderedDict({ 314 'sources': collections.OrderedDict({
296 blog_name: collections.OrderedDict({ 315 blog_name: collections.OrderedDict({
302 'data_type': 'blog', 321 'data_type': 'blog',
303 'items_per_page': items_per_page, 322 'items_per_page': items_per_page,
304 'date_format': date_format, 323 'date_format': date_format,
305 'default_layout': default_layout, 324 'default_layout': default_layout,
306 'taxonomy_pages': collections.OrderedDict({ 325 'taxonomy_pages': collections.OrderedDict({
307 'tags': ('pages:%s_tag.%%ext%%;' 326 'tags': tags_taxonomy,
308 'theme_pages:_tag.%%ext%%' % 327 'categories': category_taxonomy
309 tax_page_prefix),
310 'categories': ('pages:%s_category.%%ext%%;'
311 'theme_pages:_category.%%ext%%' %
312 tax_page_prefix)
313 }) 328 })
314 }) 329 })
315 }), 330 }),
316 'routes': [ 331 'routes': [
317 { 332 {
414 raise ConfigurationError("There are no sources defined.") 429 raise ConfigurationError("There are no sources defined.")
415 if not isinstance(v, dict): 430 if not isinstance(v, dict):
416 raise ConfigurationError("The 'site/sources' setting must be a " 431 raise ConfigurationError("The 'site/sources' setting must be a "
417 "dictionary.") 432 "dictionary.")
418 433
419 # Add the theme page source if no sources were defined in the theme 434 theme_site = values['site']['theme_site']
420 # configuration itself. 435 if not theme_site:
421 has_any_theme_source = False 436 # Add the theme page source if no sources were defined in the theme
422 for sn, sc in v.items(): 437 # configuration itself.
423 if sc.get('realm') == REALM_THEME: 438 has_any_theme_source = False
424 has_any_theme_source = True 439 for sn, sc in v.items():
425 break 440 if sc.get('realm') == REALM_THEME:
426 if not has_any_theme_source: 441 has_any_theme_source = True
427 v['theme_pages'] = { 442 break
428 'theme_source': True, 443 if not has_any_theme_source:
429 'fs_endpoint': 'pages', 444 v['theme_pages'] = {
430 'data_endpoint': 'site/pages', 445 'theme_source': True,
431 'item_name': 'page', 446 'fs_endpoint': 'pages',
432 'realm': REALM_THEME} 447 'ignore_missing_dir': True,
433 values['site']['routes'].append({ 448 'data_endpoint': 'site/pages',
434 'url': '/%path:slug%', 449 'item_name': 'page',
435 'source': 'theme_pages', 450 'realm': REALM_THEME}
436 'func': 'pcurl(slug)'}) 451 values['site']['routes'].append({
452 'url': '/%path:slug%',
453 'source': 'theme_pages',
454 'func': 'pcurl(slug)'})
437 455
438 # Sources have the `default` scanner by default, duh. Also, a bunch 456 # Sources have the `default` scanner by default, duh. Also, a bunch
439 # of other default values for other configuration stuff. 457 # of other default values for other configuration stuff.
440 reserved_endpoints = set(['piecrust', 'site', 'page', 'route', 458 reserved_endpoints = set(['piecrust', 'site', 'page', 'route',
441 'assets', 'pagination', 'siblings', 459 'assets', 'pagination', 'siblings',