Class: JavascriptLoader

Inherits:
Loader
  • Object
show all
Includes:
Singleton
Defined in:
bin/rip-comments,
bin/rip-comments~

Instance Method Summary collapse

Constructor Details

#initialize ⇒ JavascriptLoader

Returns a new instance of JavascriptLoader.



37
38
39
40
# File 'bin/rip-comments', line 37

def initialize
	require 'javascript/comment_stripper'
	@parser = CommentRipper::Javascript.new
end

Instance Method Details

#load(filename, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'bin/rip-comments', line 42

def load(filename, options={})
	File.open(filename) do |file|
		input = file.read
		output = @parser.strip(input)
		if(!options.nil? && options.has_key?(:outfile))
			outfile = options[:outfile]
			if(outfile != filename)
				File.open(outfile, 'w') {|f| f.write(output) }
			else
				$stderr.puts("Infile and outfile are the same (#{outfile}), and won't overwrite without force flag.")
			end
		else
			puts output
		end
	end
end