Login

Tag "preprocessor"

Snippet List

Showell markup--DRY up your templates

The code shown implements a preprocessor for Django templates to support indentation-based syntax. The pre-markup language is called Showell Markup. It allows you to remove lots of close tags and random punctuation. It also has a syntax for cleaning up individual lines of HTML with a pipe syntax for clearly separating content from markup. You can read the docstrings to glean the interface. Here are examples: >> table >> tr >> td Right >> td Center >> td Left >> div class="spinnable" >> ul >> li id="item1" One >> li id="item2" Two %% extends 'base.html' %% load smartif %% block body %% for book in books {{ book }} %% if condition Display this %% elif condition Display that %% else %% include 'other.html' >> tr class="header_row" Original Author | th class="first_column" Commenters | th Title | th Action | th Last words | th By | th When | th >> ol class="boring_list" One | li Two | li Three | li {{ element4|join:',' }} | li Hello World! | b | span class="greeting" ; br Goodbye World! | i | span class="parting_words"; br ; hr >> p class="praise" Indentation-based syntax is so Pythonic! Archive LINK collection.archive referral.pk Home LINK home.home Friends LINK friendship.friends Create a card LINK referrals.create Recent changes LINK activity.recent_changes >> FORM referrals.create {{ form.as_p }} {{ referral.id } | HIDDEN referral

  • templates
  • dry
  • preprocessor
Read More

CSS Preprocessor

Here is a Django view that turns code like this: @variables { $varcolor: #333; } body { color: $varcolor; padding: 20px; } .space { padding: 10px; } .small { font-size: 10px; } #banana(.space, .small) { margin-bottom: 10px; } And turns it into something like this: body { color: #333; padding: 20px; } #banana { padding: 10px; font-size: 10px; margin-bottom: 10px; } .small { font-size: 10px; } .space { padding: 10px; } Notice the variables declaration at the top. The other feature is *extending* - here #banana extends .space and .small. The url.py entry might look something like this: (r'^css/(?P<css>(\w|-)+)\.css$','csspp.csspp'), Here referencing csspp.py in your path (root directory of your site probably). The code also looks for a CSS_DIR setting in your settings file. You will probably want to point straight to your media/css/ directory. **Known problems** * There is now way of extending selectors that are already extending something else. In the example code there is now way to extend #banana since it is already extending .small and .space.

  • css
  • preprocessor
  • csspp
Read More

2 snippets posted so far.