Skip to content

Instantly share code, notes, and snippets.

@samhiatt
Created February 12, 2021 03:58
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samhiatt/5fea77154d17566d6addf6d2c4505aeb to your computer and use it in GitHub Desktop.
Save samhiatt/5fea77154d17566d6addf6d2c4505aeb to your computer and use it in GitHub Desktop.
Patch eventmachine.rb to enable Jekyll livereload on Windows 10. Tested with Ruby 2.7. Resolves the following error on Windows 10: "Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'"
@ECHO off
REM Patch eventmachine.rb to enable Jekyll livereload (jekyll serve -l)
REM Resolves the following error on Windows 10:
REM "Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby'"
REM Tested on Ruby2.7, might also work on earlier versions.
REM See https://github.com/tabler/tabler/issues/155
REM Find eventmachine.rb
FOR /F "delims=" %%i IN ('gem environment gemdir') DO set gemdir=%%i
set gemdir=%gemdir:/=\%\gems\
FOR /F "delims=" %%i IN ('dir /b %gemdir%\eventmachine*') DO set emrb=%gemdir%%%i\lib\eventmachine.rb
REM Add "require 'em/pure_ruby'" to the beginning of eventmachine.rb if it isn't there already.
set /p firstline=< %emrb%
IF "require 'em/pure_ruby'"=="%firstline:~0,22%" (
echo eventmachine.rb is already patched. Jekyll livereload should work.
) else (
echo require 'em/pure_ruby' > tmpfile.txt
type %emrb% >> tmpfile.txt
move /y tmpfile.txt %emrb%
echo eventmachine.rb successfully patched. Go ahead and enjoy Jekyll live reload.
)
@samhiatt
Copy link
Author

I'm a Linux guy. Please forgive my ugly batch scripting skills.

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