Class: Arcabouco::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/arcabouco/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServer

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

#envObject

Returns the value of attribute env.



77
78
79
# File 'lib/arcabouco/server.rb', line 77

def env
  @env
end

#rackObject

Returns the value of attribute rack.



76
77
78
# File 'lib/arcabouco/server.rb', line 76

def rack
  @rack
end

#rootObject

Returns the value of attribute root.



75
76
77
# File 'lib/arcabouco/server.rb', line 75

def root
  @root
end

#webObject

Returns the value of attribute web.



78
79
80
# File 'lib/arcabouco/server.rb', line 78

def web
  @web
end

Instance Method Details

#buildObject



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_envObject



100
101
102
# File 'lib/arcabouco/server.rb', line 100

def get_env
  self.env 
end

#get_rackObject



104
105
106
# File 'lib/arcabouco/server.rb', line 104

def get_rack
  self.rack
end

#prepare_env_for_buildObject



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_serverObject



137
138
139
# File 'lib/arcabouco/server.rb', line 137

def prepare_env_for_server
  self.env.append_path 'public/app.assets'
end

#runObject



156
157
158
159
# File 'lib/arcabouco/server.rb', line 156

def run
  thin = Rack::Handler.get('thin')
  thin.run self.rack
end

#setup_envObject



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 HandlebarsAssets.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_rackObject



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