lib/attractor/reporter.rb in attractor-0.3.0 vs lib/attractor/reporter.rb in attractor-0.3.1
- old
+ new
@@ -62,18 +62,23 @@
puts 'Generating an HTML report'
FileUtils.mkdir_p './attractor_output'
+ File.open('./attractor_output/main.css', 'w') { |file| file.write(css) }
File.open('./attractor_output/index.html', 'w') { |file| file.write(render) }
puts "Generated HTML report at #{File.expand_path './attractor_output/index.html'}"
Launchy.open(File.expand_path('./attractor_output/index.html'))
end
+ def css
+ File.read(File.expand_path('../../app/assets/stylesheets/main.css', __dir__))
+ end
+
def render
- template = Tilt.new(File.expand_path('../templates/index.html.erb', __dir__))
+ template = Tilt.new(File.expand_path('../../app/views/index.html.erb', __dir__))
template.render self
end
end
# serving the HTML locally
@@ -85,14 +90,18 @@
Rack::Handler::WEBrick.run app, Port: 7890
end
def render
- template = Tilt.new(File.expand_path('../templates/index.html.erb', __dir__))
+ template = Tilt.new(File.expand_path('../../app/views/index.html.erb', __dir__))
template.render self
end
+ def css
+ File.read(File.expand_path('../../app/assets/stylesheets/main.css', __dir__))
+ end
+
def watch
@suggestions = @suggester.suggest
app = serve_via_rack
@@ -100,16 +109,25 @@
end
private
def serve_via_rack
- app = lambda do |_env|
- [200, { 'Content-Type' => 'text/html' }, [render]]
+ app = lambda do |env|
+ route(env['PATH_INFO'])
end
puts 'Serving attractor at http://localhost:7890'
Launchy.open('http://localhost:7890')
app
+ end
+
+ def route(path_info)
+ case path_info
+ when /main.css$/
+ [200, { 'Content-Type' => 'text/css' }, [css]]
+ else
+ [200, { 'Content-Type' => 'text/html' }, [render]]
+ end
end
end
end