-
Notifications
You must be signed in to change notification settings - Fork 0
/
thimblr.rb
71 lines (61 loc) · 1.68 KB
/
thimblr.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
require 'rubygems'
require 'sinatra'
require 'active_record'
require 'thimblr/parser'
require 'models/blog'
require 'models/post'
require 'models/page'
require 'models/theme_snippet'
configure :development do
dbconfig = YAML.load(File.read('config/database.yml'))
ActiveRecord::Base.establish_connection dbconfig['development']
end
configure :production do
dbconfig = YAML.load(File.read('config/database.yml'))
ActiveRecord::Base.establish_connection dbconfig['production']
end
configure do
ActiveRecord::Base.logger = Logger.new(STDOUT)
begin
ActiveRecord::Schema.define do
create_table :blogs do |t|
t.string :title
t.text :description
t.string :name
t.timestamps
end
create_table :posts do |t|
t.string :url, :url_with_slug, :post_type
t.datetime :date_gmt, :date
t.string :unix_timestamp, :format, :reblog_key, :slug
t.integer :width, :height, :audio_plays
t.string :postid
t.text :content
t.references :blog
t.timestamps
end
create_table :pages do |t|
t.string :url, :title, :link_title
t.boolean :render_in_theme
t.text :body
t.references :blog
t.timestamps
end
end
rescue ActiveRecord::StatementInvalid
puts "DB schema already exists. Not creating again."
end
end
get '/' do
redirect 'index.html'
end
# get '/env' do
# content_type 'text/plain'
# ENV.inspect
# end
post '/preview' do
# TODO add error handling when no theme_code supplied or doesn't seem to be a tumblr theme
params[:username].blank? ? username = 'demo' : username = params[:username]
parser = Parser.new(params[:theme_code], username)
parser.render_index
end