Skip to content

Instantly share code, notes, and snippets.

@sukima
Forked from phaer/coffeescript_converter.rb
Created June 13, 2012 17:13
Show Gist options
  • Save sukima/2925325 to your computer and use it in GitHub Desktop.
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")
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
@sukima
Copy link
Author

sukima commented Jun 14, 2012

This Hack is no longer required for latest OctoPress. Use this gist instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment