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.



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

def initialize
  self.root = Arcabouco.root
  setup_env
  setup_rack
end

Instance Attribute Details

#envObject

Returns the value of attribute env.



70
71
72
# File 'lib/arcabouco/server.rb', line 70

def env
  @env
end

#rackObject

Returns the value of attribute rack.



69
70
71
# File 'lib/arcabouco/server.rb', line 69

def rack
  @rack
end

#rootObject

Returns the value of attribute root.



68
69
70
# File 'lib/arcabouco/server.rb', line 68

def root
  @root
end

#webObject

Returns the value of attribute web.



71
72
73
# File 'lib/arcabouco/server.rb', line 71

def web
  @web
end

Instance Method Details

#buildObject



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/arcabouco/server.rb', line 126

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.html", "save_app.html"
  compile_view "/manifest.appcache", "manifest.appcache"
end

#compile_view(path, output) ⇒ Object



112
113
114
115
116
117
118
# File 'lib/arcabouco/server.rb', line 112

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



89
90
91
# File 'lib/arcabouco/server.rb', line 89

def get_env
  self.env 
end

#get_rackObject



93
94
95
# File 'lib/arcabouco/server.rb', line 93

def get_rack
  self.rack
end

#prepare_env_for_buildObject



120
121
122
123
# File 'lib/arcabouco/server.rb', line 120

def prepare_env_for_build
  self.env.js_compressor = :uglify
  self.env.css_compressor = :sass
end

#runObject



140
141
142
143
# File 'lib/arcabouco/server.rb', line 140

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

#setup_envObject



79
80
81
82
83
84
85
86
87
# File 'lib/arcabouco/server.rb', line 79

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')
end

#setup_rackObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/arcabouco/server.rb', line 97

def setup_rack
  self.web = Arcabouco::WebServer.new
  web = self.web

  # app_css.write_to( Arcabouco.root + "/public/app-#{app_css.digest}.min.css" )
  $environment = self.get_env()
  self.rack = Rack::Builder.new do
    map '/app.assets' do
      run $environment
    end
    run web
  end
  self.rack
end