Class: Closure::Compiler::Compilation
- Inherits:
-
Object
- Object
- Closure::Compiler::Compilation
- Defined in:
- lib/closure/compiler.rb
Instance Attribute Summary (collapse)
-
- js_output_file
readonly
Returns the value of attribute js_output_file.
-
- log
readonly
Returns the value of attribute log.
Instance Method Summary (collapse)
-
- <<(javascript)
Appends a string to the javascript.
-
- (Boolean) compiled?
True when compilation actually happened.
-
- (Compilation) initialize(env, js_output_file = nil, log = nil)
constructor
A new instance of Compilation.
-
- javascript
(also: #to_s)
Always returns the compiled javascript (possibly an empty string).
-
- (Rack::Response) to_response
Turn the compiled javascript into a Rack::Response object.
Constructor Details
- (Compilation) initialize(env, js_output_file = nil, log = nil)
Returns a new instance of Compilation
97 98 99 100 101 102 |
# File 'lib/closure/compiler.rb', line 97 def initialize(env, js_output_file=nil, log=nil) @javascript = [] @env = env @js_output_file = js_output_file @log = log end |
Instance Attribute Details
- js_output_file (readonly)
Returns the value of attribute js_output_file
95 96 97 |
# File 'lib/closure/compiler.rb', line 95 def js_output_file @js_output_file end |
- log (readonly)
Returns the value of attribute log
94 95 96 |
# File 'lib/closure/compiler.rb', line 94 def log @log end |
Instance Method Details
- <<(javascript)
Appends a string to the javascript.
138 139 140 141 |
# File 'lib/closure/compiler.rb', line 138 def <<(javascript) @javascript << javascript self end |
- (Boolean) compiled?
True when compilation actually happened. False when build was up to date.
106 107 108 |
# File 'lib/closure/compiler.rb', line 106 def compiled? !!@log end |
- javascript Also known as: to_s
Always returns the compiled javascript (possibly an empty string).
146 147 148 149 150 151 152 153 |
# File 'lib/closure/compiler.rb', line 146 def javascript if @js_output_file file_js = File.read(@js_output_file) rescue '' ([file_js] + @javascript).join nil else @javascript.join nil end end |
- (Rack::Response) to_response
Turn the compiled javascript into a Rack::Response object. Success and warning messages, which aren't raised like errors, will be logged to the javascript console.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/closure/compiler.rb', line 116 def to_response if !log and @javascript.empty? and @js_output_file response = FileResponse.new @env, @js_output_file, 'application/javascript' else response = Rack::Response.new response.headers['Content-Type'] = 'application/javascript' response.headers["Cache-Control"] = 'max-age=0, private, must-revalidate' if log consolable_log = '"Closure Compiler: %s\n\n", ' + log.rstrip.dump if log.split("\n").first =~ / 0 warn/i response.write "try{console.log(#{consolable_log})}catch(err){};\n" else response.write "try{console.warn(#{consolable_log})}catch(err){};\n" end end response.write javascript end response end |