Is it possible to use premailer with mako templates? - mako

Premailer seems to convert my mako templates:
<div>
<%block name="email_content">
</%block>
</div>
Into a series of escaped sequences:
<div>
%block>
</div>
This is with premailer 1.8.2; there is some talk in various places of using premailer-ignore as a style tag or similar, but the premailer documentation seems severely lacking.
Is there some way of using escape sequences with premailer?

The answer is that nokogiri is currently broken somehow (there are few vaguely related open tickets on github, but nothing specifically relating to this).
Anyhow, you have to use hpricot (despite it being EOL) for this to work.
Be aware that hpricot won't install on OSX cleanly, and currently requires:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install hpricot --no-rdoc --no-ri
All in all; messy and bad.
Simple solution: don't use premailer.

Related

Markdown for codes on webpage

I am experienced with CSS and a beginner in Python. In the past, while writing blogs/webpages with codes, I would simply just create a div with a particular class and make it a code bloc with different colour and font-family, etc.
However, these days I've seen so many beautiful applications of markdown such as github-markdown-css or dillinger. But I really don't know where to start learning. For instance, I am not even sure where to execute the installation instruction below...
$ npm install --global generate-github-markdown-css
If I really want to really go beyond linking html files/blog posts with CSS and do some nice-looking markups, what are the steps necessary?
To make it more solvable as a question in this forum: if I just have a html file and want to create a code bloc showed above by typing
> line 1
> line 2
instead of
<div class="codebloc">
line 1<br/>
line2
</div>
Where should I start?
For instance, I am not even sure where to execute the installation instruction below...
npm install --global generate-github-markdown-css
This command, which you can execute in your terminal, will install the specified npm package generate-github-markdown globally, making it available from anywhere on your system. To execute it you'll need npm installed on your computer. If you're not already familiar with npm, I suggest reading the official documentation or this guide on Sitepoint. Since it installs the package globally, you can execute the command from pretty much anywhere on your computer.
How do I make code blocks in Markdown?
Markdown will automatically convert text with for spaces in front to code, which looks like this:
console.log("This code is cool");
If the Markdown parser supports GitHub Flavoured Markdown, which most parsers do, you can also wrap your code with three back-ticks ```. If you want inline code you can use just a single back-tick ` on both side of the code.
If you want to learn more about how to do various things with Markdown, including some more examples on how to write code blocks, I recommend looking at this page.

What's the difference between these JSON Perl modules?

What's the difference between the Perl JSON modules below?
I have come across JSON::PP and JSON::XS. The documentation of JSON::PP says it is compatible with JSON::XS. What does that mean?
I am not sure what the difference between them are, let alone which of them to use. Can someone clarify?
Perl modules sometimes have different implementations. The ::PP suffix is for the Pure Perl implementation (i.e. for portability), the ::XS suffix is for the C-based implementation (i.e. for speed), and JSON is just the top-level module itself (i.e. the one you actually use).
As noted by #Quentin, this site has a good description of them. To quote:
JSON
JSON.pm is a wrapper around JSON::PP and JSON::XS - it also does a bunch of moderately crazy things for compatibility reasons, including extra shim code for very old perls [...]
JSON::PP
This is the standard pure perl implementation, and if you're not performance dependent, there's nothing wrong with using it directly [...]
JSON::XS
Ridiculously fast JSON implementation in C. Absolutely wonderful [...]
As you can see, just installing the top-level JSON module should do it for you. The part about compatibility just means that they both do the same thing, i.e. you should get the same output from both.
I installed the Perl JSON module a few years ago on a RHEL server I managed and it was a really straightforward process: just install (or build) the module from the CPAN site and you're done.
Installing should be a simple case of either using the OS package manager (if in GNU/Linux), using the cpan utility, or building from source. The OS package manager is recommended, as it helps keep things updated automatically.
To verify that it's installed, just try the following command from the terminal (assuming GNU/Linux):
$ perl -e 'use JSON;'
If it doesn't complain, then you should be good to go. If you get errors, then you should get ready to go in an adventure.
You can install JSON module, cpan install JSON
use JSON;
my $result = from_json($json);
if($result->{field})
{
# YOUR CODE
};

OpenShift catridge using yum and augeas

What is the best way to create a custom OpenShift cartridge?
Looking at documentation and examples, I am seeing a lot of old-school compiling from source installation of the component that the cartridge needs to run.
Some examples https://www.openshift.com/blogs/lightweight-http-serving-using-nginx-on-openshift https://github.com/boekkooi/openshift-diy-nginx-php/blob/master/.openshift/action_hooks/build_nginx https://github.com/razorinc/redis-openshift-example/blob/master/.openshift/action_hooks/build and a ton of others are compiling from source..
I need to create some custom cartridges on my project, but doing it this way feels wrong.
Is there any reason I cant use yum and puppet/augeas to do the building, instead of curl, make and sed?
Or is this the best practice? In that case, why are we doing this 2000 style?
I'll do my best to explain this the best way I can. Feel free to let me know If I need to explain anything in more detail.
I'm assuming you're creating a custom binary cartridge (ie. you're creating a language cartridge such as ruby, python, etc.). Since none of the nodes have that binary installed on the system the custom cartridge you're creating will need to provide that binary and its libraries.
When you install a package with yum its going to install items in several different directories (/etc, /usr/, /var, etc). Since you're creating cartridge that will be copied over to several nodes you'll need to package all these items in a way that can be copied over to a node and then be executed without having to install them to the system.
As for doc's, I would suggest taking a look at these:
https://www.openshift.com/developers/download-cartridges
https://www.openshift.com/blogs/new-openshift-cartridge-format-part-1
https://www.openshift.com/blogs/new-openshift-cartridge-format-part-2

Parse HTML using ruby core libraries? (ie, no gems required)

Some friends and I have been working on a set of scripts that make it easier to do work on the machines at uni. One of these tools currently uses Nokogiri, but in order for these tools to run on all machines with as little setup as possible we've been trying to find a 'native' html parser, instead of requiring users to install RVM and custom gems (due to disk space limitations for most users).
Are we pretty much restricted to Nokogiri/Hpricot/? Should we look at just writing our own custom parser that fits our needs?
Cheers.
EDIT: If there's posts on here that I've missed in my searches, let me know! S.O. is sometimes just too large to find things effectively...
There is no html parser in ruby stdlib
html parsers have to be more forgiving of bad markup than xml parsers
You could run the html though tidy (http://tidy.sourceforge.net)
to tidy up the html and produce valid markup
This can now be read via rexml :-) which is in stdlib
rexml is much slower than nokogiri, last checked in 2009
Sam Ruby had been working on making rexml faster though
A better way would be to have a better deployment
Take a look at http://gembundler.com/bundle_package.html and using capistrano (or some such) to provision servers

Using syntax highlight from GitHub

What syntax highlighting is used on GitHub (for HTML, CSS, JavaScript, C#) when viewing source code-file and is it available for the public to use?
It works on the page and it works when embedding on a page (from a Gist), like this:
<script src="https://gist.github.com/1009439.js"></script>
But can I just include their JavaScript-library and let it highlight my code?
Github uses pygments to highlight syntax. Pygments is running on the server, instead of a pure Javascript client solution. If you're looking for a Javascript solution check out this review of the various options.
According to this help page, GitHub currently highlights syntax with the open-source Linguist library for Ruby. Linguist highlights each language using the tmLanguage files linked in vendor/grammars.
Since Linguist is written in Ruby, it can only be used on the server. If you want a client-side JavaScript library that you can just include on a page, you will have to find a different library.
According to this: http://www.infoq.com/news/2008/03/github-git-repository-hosting
they are using Python Pygments
Chris Wanstrath shared some
information about the inner workings
of GitHub with InfoQ:
GitHub is mostly implemented in Rails.
The post-commit integration mini-apps
we're working on are all written in
Merb, we use the Python Pygments for
syntax highlighting, and we use Ara T.
Howard's Bj plus some Ruby scripts for
our queueing system. And, of course,
we use the Ruby Grit library to
interface with Git.
I believe they use their albino gem. It is a Ruby wrapper for the pygments syntax highlighter.
Here is an article of a comparison I read recently on javascript based syntax highlighters (if that is what you need): http://softwaremaniacs.org/blog/2011/05/22/highlighters-comparison/
As others have said previously, GitHub uses Pygments. You can achieve the same effect by using it together with pygments-style-github.