Class: Arcabouco::Server
- Inherits:
-
Object
- Object
- Arcabouco::Server
- Defined in:
- lib/arcabouco/server.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#rack ⇒ Object
Returns the value of attribute rack.
-
#root ⇒ Object
Returns the value of attribute root.
-
#web ⇒ Object
Returns the value of attribute web.
Instance Method Summary collapse
- #build ⇒ Object
- #compile_view(path, output) ⇒ Object
- #get_env ⇒ Object
- #get_rack ⇒ Object
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #prepare_env_for_build ⇒ Object
- #prepare_env_for_server ⇒ Object
- #run ⇒ Object
- #setup_env ⇒ Object
- #setup_rack ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
80 81 82 83 84 |
# File 'lib/arcabouco/server.rb', line 80 def initialize self.root = Arcabouco.root setup_env setup_rack end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
77 78 79 |
# File 'lib/arcabouco/server.rb', line 77 def env @env end |
#rack ⇒ Object
Returns the value of attribute rack.
76 77 78 |
# File 'lib/arcabouco/server.rb', line 76 def rack @rack end |
#root ⇒ Object
Returns the value of attribute root.
75 76 77 |
# File 'lib/arcabouco/server.rb', line 75 def root @root end |
#web ⇒ Object
Returns the value of attribute web.
78 79 80 |
# File 'lib/arcabouco/server.rb', line 78 def web @web end |
Instance Method Details
#build ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/arcabouco/server.rb', line 142 def build FileUtils.mkpath Arcabouco.root + "/public" FileUtils.mkpath Arcabouco.root + "/public/app.assets" prepare_env_for_build manifest = Sprockets::Manifest.new(env, Arcabouco.root + "/public/app.assets/manifest.json") manifest.compile Arcabouco.asset_list compile_view "/", "index.html" compile_view "/save_app", "save_app.html" compile_view "/manifest.appcache", "manifest.appcache" end |
#compile_view(path, output) ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/arcabouco/server.rb', line 124 def compile_view(path,output) browser = Rack::Test::Session.new(Rack::MockSession.new(rack)) response = browser.get path, {} File.open(Arcabouco.root + "/public/" + output, 'w+') do |f| f.puts response.body end end |
#get_env ⇒ Object
100 101 102 |
# File 'lib/arcabouco/server.rb', line 100 def get_env self.env end |
#get_rack ⇒ Object
104 105 106 |
# File 'lib/arcabouco/server.rb', line 104 def get_rack self.rack end |
#prepare_env_for_build ⇒ Object
132 133 134 135 |
# File 'lib/arcabouco/server.rb', line 132 def prepare_env_for_build self.env.js_compressor = :uglify self.env.css_compressor = :sass end |
#prepare_env_for_server ⇒ Object
137 138 139 |
# File 'lib/arcabouco/server.rb', line 137 def prepare_env_for_server self.env.append_path 'public/app.assets' end |
#run ⇒ Object
156 157 158 159 |
# File 'lib/arcabouco/server.rb', line 156 def run thin = Rack::Handler.get('thin') thin.run self.rack end |
#setup_env ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/arcabouco/server.rb', line 86 def setup_env self.env = Sprockets::Environment.new self.env.append_path 'app/media' self.env.append_path 'app/js' self.env.append_path 'app/css' self.env.append_path .path self.env.append_path File.join(Arcabouco.gem_root,'assets','css') self.env.append_path File.join(Arcabouco.gem_root,'assets','js') Sprockets::Helpers.configure do |config| config.prefix = '/app.assets' config.digest = true end end |
#setup_rack ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/arcabouco/server.rb', line 108 def setup_rack self.web = Arcabouco::WebServer.new web = self.web # app_css.write_to( Arcabouco.root + "/public/app-#{app_css.digest}.min.css" ) self.prepare_env_for_server() $environment = self.get_env() self.rack = Rack::Builder.new do map '/app.assets' do run $environment end run web end self.rack end |