How can I conditionally include a LESS file with django-compressor? - django-compressor

I'd like to conditionally import a LESS file inside a {% compress css %} block like this:
{% compress css %}
<link href="{{ STATIC_URL }}common/css/style.css" media="screen" rel="stylesheet" type="text/css" />
{% ifequal app "custom" %}
<link href="{{STATIC_URL}}custom/less/style.less" rel="stylesheet" type="text/less">
{% endifequal %}
{% endcompress %}
I'm using offline compressions and getting an OfflineGenerationError, which makes sense, I just don't know how to go about fixing it.
I have a couple ideas:
move the logic of the import into a view and server one html file for the include and one without
move the logic into css (if/how this is possible)
provide a conditional include, which compresses the LESS file
remove compress and compile the LESS file to CSS, then the above code should work
Thanks,
Aleck

Have you remembered to set the COMPRESS_OFFLINE_CONTEXT setting, as documented here?
This is "the context to be used by the compress management command when rendering the contents of {% compress %} template tags and saving the result in the offline cache".
Since you're accessing the app context variable it could be what you need.

Related

orocommerce wysiwyg editor - file / image wrong src

I have similar issue that Wysiwyg images not moved to public cache
when I add a file or image in wysiwyg, it displays properly in editor but after saving, it doesn't display in admin nor front.
Generated markup src is incorrect/not properly replaced:
<picture id="irozi"><source srcset="{{ wysiwyg_image('22','d9ffaffc-f286-4707-bd4b-29504628acc2','wysiwyg_original','webp') }}" type="image/webp"><img src="{{ wysiwyg_image('22','0872c470-f50a-4290-8043-96ffd5e205d2','wysiwyg_original','') }}" id="icysf" alt="test picture"></picture>
my-file.csv
My field already exists (in a custom bundle) and "File applications" doesn't show in "Entity Management".
Do I need that conf? How to achieve it with a migration?
What else should I do to have a correct src for files and images?
File applications config is required if you want to display an image that is ACL protected within the application. You can set it using a migration, e.g.:
$queries->addQuery(
new UpdateEntityConfigFieldValueQuery(
'Acme\Demobundle\Entity\FancyFile',
'image',
'attachment',
'file_applications',
['default', 'commerce']
)
);
The issue might also be related to image processing. Please, check the log file for errors.
UPDATE
Also, as a WYSIWYG field has some twig placeholders it has to be rendered with the applied postprocessing.
On the storefront it should be rendered with:
{% if entity.contentStyle|length -%}
{%- apply spaceless -%}
<style type="text/css">{{ entity.contentStyle|render_content }}</style>
{%- endapply -%}
{%- endif %}
{{ entity.content|render_content }}
There are also ready-to-use layout block types: wysiwyg_style and text_with_placeholders.
On the back-office there is a macro
{% import '#OroEntityConfig/macros.html.twig' as entityConfig %}
{{ entityConfig.renderWysiwygContentPreview(entity.content)|raw }}
Where the entity.content is the field path to render.
The team will update the documentation to mention that.

How can I add proper tag support for jekyll blog hosted on GitHub?

Problem
Recently I added tag support for my personal blog, but I am not happy with a way that it was done.
Blog uses jekyll with github-pages, so my solution has many limitations that platform comes with.
In order to create tag javascript I created file tag/javascript/index.html with following content:
---
layout: tag
tag: javascript
---
And it in my tag layout file I have following code:
---
layout: default
---
<div class="tag-header">
posts related to <strong>{{ page.tag }}</strong>
</div>
{% for post in site.posts %}
{% if post.tags contains page.tag %}
<section class="post">
<header>
{{ post.title }}
</header>
<time>
{{ post.date | date_to_string }}
</time>
<summary>
{% if post.excerpt %}
{{ post.excerpt }}
read more
{% endif %}
</summary>
<div class="tags">
{% for tag in post.tags %}
<span>
#{{ tag }}
</span>
{% endfor %}
</div>
</section>
{% endif %}
{% endfor %}
Result is something like this posts related to javascript.
Question
How can I automate tag creation process, so it does not require manual tag file creation (tag/javascript/index.html from sample)?
Notice
I have read An easy way to support tags in a jekyll blog already, and the only working solution for github-pages was this one, which I don't like, because it puts all tags in one page.
Additionally note that I am using github-pages, so custom plugin is not an option.
You can find full sources here.
Current Jekyll (3.1.x) cannot generate tag page automatically. You need to use a custom plugin. But you don't want to.
Why ? It's not so difficult to change deployment process on github pages.
You can store you code in master and you generated page in gh-pages. This answer will give your more information on how to do it.

Can I use a filter on all compress blocks except for one?

In my settings for compressor I'm using SlimIt for most of my javascript:
COMPRESS_JS_FILTERS = ['compressor.filters.jsmin.SlimItFilter', ]
Some of my js files shouldn't go through SlimIt though because the file is already minified, or the javascript throws some error when its minified with other files. My template block ends up looking like this:
{# code that I minify #}
{% block compressed_libs %}
{% compress js %}
<script src="/static/js/compress_this.js"></script>
<script src="/static/js/also_compress_this.js"></script>
...
{% endcompress %}
{% endblock %}
{# code that shouldn't minify #}
{% block non-compressible_libs %}
<script src="/static/js/already.min.js"></script>
<script src="/static/js/breaks-everything.js"></script>
{% endblock %}
Can I set different compress filter rules for different blocks/files so that my "non-compressible" files can still be concatenated together by compressor while skipping SlimIt?
As approxiblue said, it doesn't look there's a way to specify which filters to use per compress block in a template (in Compressor 1.5).
I'll update this answer someone comes up with something.
It seems like this could be solved by adding a parameter to the compress template tag to allow it to return a CompressorNode with a flag to skip the filter in base.py hunks()
I'll see what the Compressor community thinks about this, but let me know if you have any ideas.

Symfony2 / Sonata SEO Bundle / og:image

Can't for the life of me seem to work this one out. I have added the following to my 'base' twig's head:
<html {{ sonata_seo_html_attributes() }}>
<head {{ sonata_seo_head_attributes() }}>
{{ sonata_seo_title() }}
{{ sonata_seo_metadatas() }}
{{ sonata_seo_link_canonical() }}
{{ sonata_seo_lang_alternates() }}
Which works great, but running Facebook debug, It is telling me I need to explicitly define og:image.
og:image is missing. The og:image meta tag is necessary for Facebook to render a News Feed story that generates a high click-through rate.
Now I've looked through the code and on Google but can't seem to find any mention of it, but I can't believe this is just an issue I am experiencing.
I'm trying to use it from within SonataNewsBundle / Media Bundle, and my images are loaded onto the page using:
<img data-interchange="[{% path post.image, 'small' %}, (small)], [{% path post.image, 'big' %},(large)]">
I have tried adding a Meta block to News/View and putting this:
{% block meta %}
<meta property="og:image" content="{% media post.image, 'big' %}" />
{% endblock meta %}
But get this when debugging:
Object at URL 'http://www."mysite".com/news/2014/6/17/woop-just-testing'
of type 'article' is invalid because the given value
'<img alt=' for property 'og:image:url'
could not be parsed as type 'url'.
So then I tried:
{% block meta %}
<meta property="og:image" content="{% path post.image, 'big' %}" />
{% endblock meta %}
But get this instead:
Object at URL 'http://www."mysite".com/news/2014/6/17/woop-just-testing' of type
'article' is invalid because the given value
'/uploads/media/news/0001/01/thumb_3_news_big.jpeg' for property
'og:image:url' could not be parsed as type 'url'.
Any help greatly appreciated.
Doug.
Managed to sort it, possibly not the best way but works...
In config,yml I have added the complete path to the Sonata_media section:
cdn:
server:
path: http://www.--mywebsite--.com/uploads/media/
Instead of:
cdn:
server:
path: /uploads/media/
And use this to set the Meta:
{% block meta %}
<meta property="og:image" content="{% path post.image, 'big' %}" />
{% endblock meta %}

Perl templates with inheritance

Exists in the Perl world any template system with template inheritance?
Just checked in the wikipedia Comparison_of_web_template_engines (really incomplete list) - and here isn't listed any.
Inheritance = Supports the ability to inherit a layout from a parent
template, separately overriding arbitrary sections of the parent
template's content.
Mean something like python's Jinja2:
#body.html
<body>
{% block content %}
<!-- the content go here -->
{% endblock %}
</body>
#hi.html
{% extends "body.html" %}
{% block content %}
<h1>Hi!</h1>
{% endblock %}
rendering hi.html gives
<body>
<h1>Hi!</h1>
</body>
Don't looking for exact Jinja2 syntax, simply looking for any template engine from the perl world what supports inheritance. (not only plain includes - like Template::Toolkit)
Asking here because searching CPAN is a pain for words like "template inheritance" - shows thousands modules what not related to this question.
Ps: ... and it shouldn't be something like embedded perl - should be "user editable" allowing users builds own templates without compromise a whole system - therefore can't use Mason or HTML::Mason)
I'll second the suggestion for Text::Xslate. Its syntax is even quite similar to your Jinja2 examples:
In layouts/main.tx:
...
<div id="page">
: block sidebar -> { }
<div id="content">
: block header-> { <h1>Default Title</h1> }
: block content -> { }
</div>
</div>
...
In another template:
: cascade layouts::main
: override header -> {
<div id="header">
...
</div>
: }
: override content -> {
<div id="content-body">
...
</div>
: }
A colleague recently started using Text::Xslate.
Template::Jade, a port of Jade to perl.
parent.jade
doctype html
html
head
title Jade template
body.class
p#id_name
block content
child.jade
extends parent
block content
p.
This is a test.
This is a test.
This is a test.
DTL::Fast Is my Perl implementation of Django templates with inheritance and other stuff.