Class: Rocket::JS::Builder
- Inherits:
-
Object
- Object
- Rocket::JS::Builder
- Defined in:
- lib/rocket/js/builder.rb
Constant Summary collapse
- CONTENTS =
[ "rocket.license.js", ]
- SCRIPTS =
[ "vendor/json/json2.js", "vendor/web-socket-js/swfobject.js", "vendor/web-socket-js/FABridge.js", "vendor/web-socket-js/web_socket.js", "rocket.core.js", "rocket.channels.js", "rocket.defaults.js", ]
- ASSETS =
[ "vendor/web-socket-js/WebSocketMain.swf", "vendor/web-socket-js/WebSocketMainInsecure.zip", ]
Instance Attribute Summary collapse
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#minified ⇒ Object
readonly
Returns the value of attribute minified.
Instance Method Summary collapse
- #bundle ⇒ Object
- #copy_assets ⇒ Object
- #generate ⇒ Object
- #generate_script ⇒ Object
-
#initialize(dest, minified = true) ⇒ Builder
constructor
A new instance of Builder.
- #minify(src) ⇒ Object
- #save_script(source) ⇒ Object
Constructor Details
#initialize(dest, minified = true) ⇒ Builder
Returns a new instance of Builder.
31 32 33 34 |
# File 'lib/rocket/js/builder.rb', line 31 def initialize(dest, minified=true) @dest = dest @minified = minified end |
Instance Attribute Details
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
28 29 30 |
# File 'lib/rocket/js/builder.rb', line 28 def dest @dest end |
#minified ⇒ Object (readonly)
Returns the value of attribute minified.
29 30 31 |
# File 'lib/rocket/js/builder.rb', line 29 def minified @minified end |
Instance Method Details
#bundle ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/rocket/js/builder.rb', line 48 def bundle SCRIPTS.map {|script| source = "/* #{File.basename(script)} */\n" source += File.read(File.("../../../../src/#{script}", __FILE__)) source }.join("\n\n") end |
#copy_assets ⇒ Object
74 75 76 77 78 79 |
# File 'lib/rocket/js/builder.rb', line 74 def copy_assets ASSETS.each {|asset| src = File.("../../../../src/#{asset}", __FILE__) FileUtils.cp(src, dest) } end |
#generate ⇒ Object
36 37 38 39 |
# File 'lib/rocket/js/builder.rb', line 36 def generate generate_script copy_assets end |
#generate_script ⇒ Object
41 42 43 44 45 46 |
# File 'lib/rocket/js/builder.rb', line 41 def generate_script FileUtils.mkdir_p(dest) source = bundle source = minify(source) if minified save_script(source) end |
#minify(src) ⇒ Object
56 57 58 59 |
# File 'lib/rocket/js/builder.rb', line 56 def minify(src) compressor = YUI::JavaScriptCompressor.new(:munge => true) compressor.compress(src) end |
#save_script(source) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rocket/js/builder.rb', line 61 def save_script(source) scriptname = "rocket-#{Rocket.version}#{'.min' if minified}.js" File.open(File.(scriptname, dest), 'w+') {|f| contents = CONTENTS.map {|content| File.read(File.("../../../../src/#{content}", __FILE__)) }.join("\n\n").sub(/<%= VERSION %>/, Rocket.version) f.write(contents) f.write("\n\n") f.write(source) } end |