Sha256: 4cf082260afb5baa04ccf06a9a535f5f21eb343a02238caf7f07a05771f01b32

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 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]

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

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

    get '/tasks.json' do
      tasks.to_json
    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-0.0.5 lib/rivendell/import/application.rb
rivendell-import-0.0.4 lib/rivendell/import/application.rb
rivendell-import-0.0.3 lib/rivendell/import/application.rb
rivendell-import-0.0.2 lib/rivendell/import/application.rb