Sha256: f02295054568d2baee829f79a42b963293b901f6fdeb46733578294ded5a0cb3

Contents?: true

Size: 1.44 KB

Versions: 4

Compression:

Stored size: 1.44 KB

Contents

require 'sinatra'

require 'will_paginate'
require 'will_paginate/active_record'

module Rivendell::Import
  class Application < Sinatra::Application

    set :public_folder, ::File.expand_path('static', ::File.dirname(__FILE__))
    # set :static_cache_control, [:public, :max_age => 3600]
    set :bind, '0.0.0.0'

    get '/' do
      redirect "/tasks", 302
    end

    get '/tasks' do
      tasks = self.tasks.paginate(:page => params[:page], :per_page => (params[:per_page] or 15))
      tasks = tasks.search(params[:search]) if params[:search]
      erb :index, :locals => { :tasks => tasks }
    end

    get '/tasks.json' do
      tasks.to_json
    end

    def config_loader
      settings.config_loader
    end

    def edit_config
      erb :config, :locals => { :config => config_loader.current_config }
    end

    get '/config' do
      edit_config
    end

    post '/config' do
      config_loader.save params["config"]
      edit_config
    end

    def tasks
      Task.order("updated_at DESC")
    end

    helpers do
      def distance_of_time_in_words_from_now(time)
        distance = Time.now - time

        if distance < 43200 # less than 12 hours
          time.strftime("%H:%M")
        else
          time.strftime("%d/%m")
        end
      end

      def truncate_filename(path, length)
        path = path.to_s

        if path.size < length
          path
        else
          path[0..length] + "..."
        end
      end

    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rivendell-import-1.04 lib/rivendell/import/application.rb
rivendell-import-1.03 lib/rivendell/import/application.rb
rivendell-import-1.02 lib/rivendell/import/application.rb
rivendell-import-1.01 lib/rivendell/import/application.rb