forked from rubyistokei/rubyistokei.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrubyistokei.rb
More file actions
42 lines (34 loc) · 769 Bytes
/
rubyistokei.rb
File metadata and controls
42 lines (34 loc) · 769 Bytes
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
require 'bundler'
Bundler.require
require 'yaml'
require 'json'
class Database
def initialize(path)
@data = Dir[File.join(path, '*.yaml')].sort.map do |yaml_path|
hash = YAML.load_file(yaml_path)
id = File.basename(yaml_path, '.yaml')
hash.merge(id: id)
end
end
attr_reader :data
end
module Rubyistokei
class Application < Sinatra::Application
configure do
set :protection, :except => :frame_options
data_path = File.join(__dir__, 'data')
database = Database.new(data_path)
DATA_JSON = JSON.dump(database.data)
end
get '/' do
haml :index
end
get '/css/screen.css' do
scss :screen
end
get '/data.json' do
content_type :json
DATA_JSON
end
end
end