Skip to content

Instantly share code, notes, and snippets.

@ETBlue
Last active January 3, 2016 15:09
Show Gist options
  • Save ETBlue/8481193 to your computer and use it in GitHub Desktop.
Save ETBlue/8481193 to your computer and use it in GitHub Desktop.
Put this file in your project folder which will be watched by Fire.app. If you are using Windows, change the user name "etblue" in line 18 and line 19 to your username.
require 'tilt'
require 'open3'
if defined? Serve
if !Serve::DynamicHandler.extensions.include?('jade')
App.alert('未載入 Jade Template engine, 請重開 Fire.app 後先 watch 這個專案')
end
end
module Tilt
class JadeTemplate < Template
self.default_mime_type = "text/html"
def prepare
end
def evaluate(scope, locals, &block)
if File.exists?('c:/users/etblue/appdata/roaming/npm/node_modules/jade/bin/jade')
jade_cmd = 'node c:/users/etblue/appdata/roaming/npm/node_modules/jade/bin/jade --path . -O "{require: require}" -P '
else
jade_cmd = 'jade --path . -O "{require: require}" -P'
end
pwd = Dir.pwd
Dir.chdir('views')
body = Open3.popen3(jade_cmd) do |stdin, stdout, stderr|
stdin.write data
stdin.close
stdout.read + stderr.read.gsub(/\n/, '<br>')
end
Dir.chdir(pwd)
body
end
end
register JadeTemplate, 'jade'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment