jekyll / jekyll-coffeescript

A CoffeeScript converter for Jekyll.
MIT License
53 stars 20 forks source link

Load converter when used. #11

Closed wh0 closed 9 years ago

wh0 commented 9 years ago

cross reference: jekyll/jekyll#2327

Make it so that you can use Jekyll 2.x without a JavaScript runtime, as long as you don't need to compile CoffeeScript.

Sample error when you try to do that:

$ jekyll b
Configuration file: /home/guest1212/Workspaces/site/_config.yml
            Source: /home/guest1212/Workspaces/site
       Destination: /home/guest1212/Workspaces/site/_site
      Generating... 
  Conversion error: Jekyll::Converters::CoffeeScript encountered an error while converting 'test.coffee':
                    Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
jekyll 2.5.3 | Error:  Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.
parkr commented 9 years ago

Great! In the Markdown Converter in Jekyll core, this is gated via an instance variable. I think requiring each time could be dangerous performance wise, so doing something like this would be preferable:

def setup
  require "coffee-script"
  @setup = true
end

def convert(content)
  setup unless @setup
  ::CoffeeScript...
end
wh0 commented 9 years ago

Thanks, I've updated it to be like https://github.com/jekyll/jekyll/blob/master/lib/jekyll/converters/markdown.rb.

:information_source: http://ruby-doc.org/core-2.2.3/Kernel.html#method-i-require Kernel::require has its own mechanism for preventing multiple loads of the same module though.

parkr commented 9 years ago

I'm trying to reduce method calls. Did you not like my example above?

wh0 commented 9 years ago

force pushed.

parkr commented 9 years ago

Ok, just asking. Thank you! This looks good to me. :shipit: