-
-
Save sukima/2925325 to your computer and use it in GitHub Desktop.
A trivial CoffeeScript.org -> Javascript plugin for OLDER OctoPress. Put this file in 'plugins/' and write a YAML header to your .coffee files (i.e. "---\nlayout:nil\n---\n")
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jekyll | |
require 'coffee-script' | |
class CoffeeScriptConverter < Converter | |
safe true | |
priority :normal | |
def matches(ext) | |
ext =~ /coffee/i | |
end | |
def output_ext(ext) | |
".js" | |
end | |
def convert(content) | |
begin | |
content = CoffeeScript.compile content | |
# OctoPress will pass all content though a RubyPants filter. | |
# RubyPants will conver quotes to smart quotes. | |
# RubyPants will ignore any convertions when content is surrounded by HTML <script> tags | |
# This adds HTML <script> tags to the output to prevent RubyPants from processing the JavaScript code. | |
<<EOS | |
// <script> To prevent OctoPress filtering through RubyPants ([See Gist][1]) | |
#{content} | |
// [1]: https://gist.github.com/2925325 | |
// </script> | |
EOS | |
rescue StandardError => e | |
puts "CoffeeScript error:" + e.message | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HTML comments will fail if you have a '>' character in your source.
Use
<script>
tags instead. Be careful as the same rules apply as they do for embeded JavaScript inside HTML documents. You can not use the string</script>
or you'll turn on RubyPants processing again. Instead escape this with"<"+"/"+"script>"
(normal CoffeeScript string concatenation will not work here you must explicitly use the + operator to separate the characters and prevent parsing).EDIT: Source patched to use
<script>
tags.