lib/sourcemaps.rb in vitrine-0.0.15 vs lib/sourcemaps.rb in vitrine-0.0.16

- old
+ new

@@ -1,8 +1,41 @@ require 'pathname' require 'json' module Vitrine + + # Compile a script (String or IO) to JavaScript. + # This is a version lifted from here + # https://github.com/josh/ruby-coffee-script/blob/114b65b638f66ba04b60bf9c24b54360260f9898/lib/coffee_script.rb + # which propagates error line + def self.compile_coffeescript(script, options = {}) + script = script.read if script.respond_to?(:read) + + if options.key?(:bare) + elsif options.key?(:no_wrap) + options[:bare] = options[:no_wrap] + else + options[:bare] = false + end + + wrapper = <<-WRAPPER + (function(script, options) { + try { + return CoffeeScript.compile(script, options); + } catch (err) { + if (err instanceof SyntaxError && err.location) { + throw new SyntaxError([options.filename, err.location.first_line + 1, err.location.first_column + 1].join(":") + ": " + err.message) + } else { + throw err; + } + } + }) + WRAPPER + CoffeeScript::Source.context.call(wrapper, script, options) + end + + # Compile a CS source map. + # TODO: this method should be married to the method that compiles the source code itself def self.build_coffeescript_source_map_body(full_coffeescript_file_path, public_folder_path) script = File.read(full_coffeescript_file_path) # We need to feed paths ON THE SERVER so that the browser can connect the coffee file, the map and the JS file \ No newline at end of file