Skip to content

Commit

Permalink
implemented use_cdn=True and use_bundles=False. Still some issues, li…
Browse files Browse the repository at this point in the history
…ke requiring webassets when not using it, maybe template error syntaes
  • Loading branch information
ralsina committed May 5, 2015
1 parent 802258a commit f83ebd5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
26 changes: 8 additions & 18 deletions nikola/data/themes/bootstrap3-jinja/templates/base_helper.tmpl
Expand Up @@ -74,20 +74,14 @@ lang="{{ lang }}">
{% endif %}
<script src="/assets/js/all.js"></script>
{% else %}
{% if use_cdn %}
FOO
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
{% else %}
<script src="/assets/js/jquery.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/moment-with-locales.min.js"></script>
<script src="/assets/js/fancydates.js"></script>
{% endif %}
<script src="/assets/js/jquery.colorbox-min.js"></script>
<script src="{{ cdn_url('jquery', use_cdn, '/assets/js/jquery.min.js') }}"></script>
<script src="{{ cdn_url('twitter-bootstrap', use_cdn, '/assets/js/bootstrap.min.js') }}"></script>
<script src="{{ cdn_url('moment.js::moment-with-locales.min.js', use_cdn, '/assets/js/moment-with-locales.min.js') }}"></script>
<script src="{{ cdn_url('fancydates.js', use_cdn, '/assets/js/fancydates.js') }}"></script>
<script src="{{ cdn_url('jquery.colorbox', use_cdn, '/assets/js/jquery.colorbox-min.js') }}"></script>
{% endif %}
{% if colorbox_locales[lang] %}
<script src="/assets/js/colorbox-i18n/jquery.colorbox-{{ colorbox_locales[lang] }}.js"></script>
<script src="{{ cdn_url('jquery.colorbox::i18n/jquery.colorbox-${colorbox_locales[lang] }}.js', use_cdn, '/assets/js/colorbox-i18n/jquery.colorbox-{{ colorbox_locales[lang] }}.js')}"></script>
{% endif %}
{{ social_buttons_code }}
{% endmacro %}
Expand All @@ -102,14 +96,10 @@ lang="{{ lang }}">
{% endif %}
<link href="/assets/css/all.css" rel="stylesheet" type="text/css">
{% else %}
{% if use_cdn %}
- <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
{% else %}
<link href="/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
{% endif %}
- <link href="{{ cdn_url('twitter-bootstrap::bootstrap.css', use_cdn, '/assets/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css">
<link href="/assets/css/rst.css" rel="stylesheet" type="text/css">
<link href="/assets/css/code.css" rel="stylesheet" type="text/css">
<link href="/assets/css/colorbox.css" rel="stylesheet" type="text/css">
- <link href="{{ cdn_url('jquery.colorbox::colorbox.css', use_cdn, '/assets/css/colorbox.css') }}" rel="stylesheet" type="text/css">
<link href="/assets/css/theme.css" rel="stylesheet" type="text/css">
{% if has_custom_css %}
<link href="/assets/css/custom.css" rel="stylesheet" type="text/css">
Expand Down
25 changes: 8 additions & 17 deletions nikola/data/themes/bootstrap3/templates/base_helper.tmpl
Expand Up @@ -74,19 +74,14 @@ lang="${lang}">
%endif
<script src="/assets/js/all.js"></script>
%else:
%if use_cdn:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
%else:
<script src="/assets/js/jquery.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/moment-with-locales.min.js"></script>
<script src="/assets/js/fancydates.js"></script>
%endif
<script src="/assets/js/jquery.colorbox-min.js"></script>
<script src="${cdn_url('jquery', use_cdn, '/assets/js/jquery.min.js')}"></script>
<script src="${cdn_url('twitter-bootstrap', use_cdn, '/assets/js/bootstrap.min.js')}"></script>
<script src="${cdn_url('moment.js::moment-with-locales.min.js', use_cdn, '/assets/js/moment-with-locales.min.js')}"></script>
<script src="${cdn_url('fancydates.js', use_cdn, '/assets/js/fancydates.js')}"></script>
<script src="${cdn_url('jquery.colorbox', use_cdn, '/assets/js/jquery.colorbox-min.js')}"></script>
%endif
%if colorbox_locales[lang]:
<script src="/assets/js/colorbox-i18n/jquery.colorbox-${colorbox_locales[lang]}.js"></script>
<script src="${cdn_url('jquery.colorbox::i18n/jquery.colorbox-${colorbox_locales[lang]}.js', use_cdn, '/assets/js/colorbox-i18n/jquery.colorbox-${colorbox_locales[lang]}.js')}"></script>
%endif
${social_buttons_code}
</%def>
Expand All @@ -101,14 +96,10 @@ lang="${lang}">
%endif
<link href="/assets/css/all.css" rel="stylesheet" type="text/css">
%else:
%if use_cdn:
- <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
%else:
<link href="/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
%endif
- <link href="${cdn_url('twitter-bootstrap::bootstrap.css', use_cdn, '/assets/css/bootstrap.min.css')}" rel="stylesheet" type="text/css">
<link href="/assets/css/rst.css" rel="stylesheet" type="text/css">
<link href="/assets/css/code.css" rel="stylesheet" type="text/css">
<link href="/assets/css/colorbox.css" rel="stylesheet" type="text/css">
- <link href="${cdn_url('jquery.colorbox::colorbox.css', use_cdn, '/assets/css/colorbox.css')}" rel="stylesheet" type="text/css">
<link href="/assets/css/theme.css" rel="stylesheet" type="text/css">
%if has_custom_css:
<link href="/assets/css/custom.css" rel="stylesheet" type="text/css">
Expand Down
8 changes: 8 additions & 0 deletions nikola/plugins/task/bundles.py
Expand Up @@ -56,6 +56,14 @@ def set_site(self, site):
self.cdn_css_urls = []
super(BuildBundles, self).set_site(site)
self.inject_dependency('render_pages', 'create_bundles')
self.site.GLOBAL_CONTEXT['cdn_url'] = self.local_or_cdn_url_from_entry

def local_or_cdn_url_from_entry(self, entry, use_cdn, default):
"""Given a JS or CSS entry, returns a URL. Returns default if use_cdn is False."""
url = self.url_from_entry(entry)
if url is None:
return default
return url

def url_from_entry(self, entry):
"""Turn a bundles entry into a URL from cdnjs"""
Expand Down

0 comments on commit f83ebd5

Please sign in to comment.