-
Notifications
You must be signed in to change notification settings - Fork 1
/
kraxnet.rb
46 lines (36 loc) · 831 Bytes
/
kraxnet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'rubygems'
require 'sinatra'
require 'open-uri'
require 'rss'
module Kraxnet
class BlogFeed
FEED_URL = 'http://blog.xnet.cz/feed/'
def self.load
open(FEED_URL) { |http| RSS::Parser.parse(http.read, false).items[0..10] }
end
end
end
helpers do
def human_date(datetime)
datetime.strftime('%d|%m|%Y').gsub(/([^0-9]+)0{1}(\d{1})/, '\1\2')
end
def truncate(chars, limit = 50)
chars.size > limit ? chars.to_s[0...limit] + '…' : chars
end
def css_class_for_menuitem(id=nil)
'active' if params[:id].to_s == id.to_s
end
end
get '/' do
@blog_items = Kraxnet::BlogFeed.load[0...3]
erb :index
end
get '/novinky' do
@blog_items = Kraxnet::BlogFeed.load
@page_title = "Novinky"
params[:id] = 'novinky'
erb :novinky
end
get '/:id' do
erb params[:id].to_sym
end