Sha256: 60ef390915915064217febd9165583535dce167e0b0faa2d42a57cd9fe41412f
Contents?: true
Size: 1.42 KB
Versions: 2
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true require 'pry' require 'rack/livereload' require 'rack' require 'sinatra/base' module Attractor # skeleton sinatra app class AttractorApp < Sinatra::Base def initialize(reporter) super @reporter = reporter end get '/javascripts/index.js' do @serve_static = false @values = @reporter.values erb File.read(File.expand_path('../../../app/assets/javascripts/index.js.erb', __dir__)), content_type: 'text/javascript' end enable :static set :public_folder, File.expand_path('../../../app/assets', __dir__) get '/' do @suggestions = @reporter.suggestions erb File.read(File.expand_path('../../../app/views/index.html.erb', __dir__)) end get '/values' do @reporter.values.to_json end get '/suggestions' do @reporter.suggestions.to_json end end # serving the HTML locally class SinatraReporter < Reporter def report super app = AttractorApp.new(self) puts 'Serving attractor at http://localhost:7890' Launchy.open('http://localhost:7890') Rack::Handler::WEBrick.run app, Port: 7890 end def watch @suggestions = @suggester.suggest app = AttractorApp.new(self) puts 'Serving attractor at http://localhost:7890' Launchy.open('http://localhost:7890') Rack::Handler::WEBrick.run Rack::LiveReload.new(app), Port: 7890 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
attractor-0.3.4 | lib/attractor/reporters/sinatra_reporter.rb |
attractor-0.3.3 | lib/attractor/reporters/sinatra_reporter.rb |