Sha256: 970ae6a64376b4e3316ad7507865fcaec5537b1b97724cd3489e45876079e340
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true require 'open3' require 'tilt' require 'json' module Pug class << self def compile(source, options = {}) source = source.read if source.respond_to?(:read) # Command line arguments take precedence over json options in Jade binary # @link https://github.com/jadejs/jade/blob/master/bin/jade.js # @link https://github.com/pugjs/pug-cli/blob/master/index.js cmd = [ options.fetch(:executable) ] cmd.push('--client') cmd.push('--path', options[:filename]) if options[:filename] cmd.push('--pretty') if options[:pretty] cmd.push('--no-debug') unless options[:debug] cmd.push('--obj', JSON.generate(options)) stdout, stderr, exit_status = Open3.capture3(*cmd, stdin_data: source) raise CompileError.new(stderr) unless exit_status.success? stdout end def find_executable %w( pug jade ).find do |name| `which #{name}` $?.success? end end end class CompileError < ::StandardError end end require 'pug/template' require 'pug/railtie' if defined?(Rails)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pug-rails-1.11.0.1 | lib/pug-rails.rb |