Sha256: f97e40ce0825bdcdd0ac9ceb36366dfaf9f0321062564ecc6cda86542cd1896e

Contents?: true

Size: 929 Bytes

Versions: 5

Compression:

Stored size: 929 Bytes

Contents

require "sinatra/base"

module Reloadlive
  class Frontend < Sinatra::Base
    STATIC = File.dirname(__FILE__) + "/static/"

    enable  :static
    set :views, STATIC
    set :public_folder, Reloadlive.options['static']

    get '/' do
      @last = last
      @port = Reloadlive.options['port']
      erb :index
    end

    get '/_reloadlive/style.css' do
      send_file STATIC + 'style.css'
    end

    get '/_reloadlive/client.js' do
      send_file STATIC + 'client.js'
    end

    def last
      last_file_changed = Reloadlive.last_file_changed
      body = "Save your document"
      title = "Reloadlive"
      if last_file_changed
        render = Reloadlive::Render.new(File.basename(last_file_changed), File.read(last_file_changed))
        body = render.formatted_data
        title = render.title
      end
      puts "PUSH " + File.basename(last_file_changed)
      { body: body, title: title}
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
reloadlive-1.0.4 lib/reloadlive/frontend.rb
reloadlive-1.0.3 lib/reloadlive/frontend.rb
reloadlive-1.0.2 lib/reloadlive/frontend.rb
reloadlive-1.0.1 lib/reloadlive/frontend.rb
reloadlive-1.0.0 lib/reloadlive/frontend.rb