aboutsummaryrefslogtreecommitdiff
path: root/src/guff.cr
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2016-07-15 12:53:02 -0400
committerPaul Duncan <pabs@pablotron.org>2016-07-15 12:53:02 -0400
commit689fe828d60fdeff8842e25cf081b04bcb06f9d3 (patch)
tree26e54573ef99db039b17ed3f5b2b5a3e3536dab7 /src/guff.cr
parent73681b9e1f21bb0c8fbf7f231523f57bd96f6cb3 (diff)
downloadguff-689fe828d60fdeff8842e25cf081b04bcb06f9d3.tar.bz2
guff-689fe828d60fdeff8842e25cf081b04bcb06f9d3.zip
crystal 0.18 support
Diffstat (limited to 'src/guff.cr')
-rw-r--r--src/guff.cr247
1 files changed, 126 insertions, 121 deletions
diff --git a/src/guff.cr b/src/guff.cr
index bb46980..64c3b0e 100644
--- a/src/guff.cr
+++ b/src/guff.cr
@@ -182,18 +182,18 @@ module Guff
module MimeType
TYPES = {
- ".js": "text/javascript; charset=utf-8",
- ".css": "text/css; charset=utf-8",
- ".html": "text/html; charset=utf-8",
- ".png": "image/png",
- ".jpeg": "image/jpeg",
- ".jpg": "image/jpeg",
- ".otf": "application/vnd.ms-opentype",
- ".eot": "application/vnd.ms-fontobject",
- ".svg": "image/svg+xml",
- ".ttf": "application/x-font-ttf",
- ".woff": "application/font-woff",
- ".woff2": "application/font-woff",
+ ".js" => "text/javascript; charset=utf-8",
+ ".css" => "text/css; charset=utf-8",
+ ".html" => "text/html; charset=utf-8",
+ ".png" => "image/png",
+ ".jpeg" => "image/jpeg",
+ ".jpg" => "image/jpeg",
+ ".otf" => "application/vnd.ms-opentype",
+ ".eot" => "application/vnd.ms-fontobject",
+ ".svg" => "image/svg+xml",
+ ".ttf" => "application/x-font-ttf",
+ ".woff" => "application/font-woff",
+ ".woff2" => "application/font-woff",
}
def self.from_path(path : String) : String
@@ -560,8 +560,8 @@ module Guff
((page - 1) * LIMIT).to_s,
])) do |row|
# append row to result
- rows << row.reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ rows << row.reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1158,8 +1158,8 @@ module Guff
@context.dbs.ro.all(SQL[:get_users]) do |row|
# append row to result
- rows << row.reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ rows << row.reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1171,8 +1171,8 @@ module Guff
row = @context.dbs.ro.row(SQL[:get], [user_id.to_s])
raise "unknown user: #{user_id}" unless row
- row.reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ row.reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1303,8 +1303,8 @@ module Guff
rows = [] of Hash(String, String)
@context.dbs.ro.all(SQL[:get_states]) do |row|
- rows << row.reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ rows << row.reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1376,8 +1376,8 @@ module Guff
rows = [] of Hash(String, String)
@context.dbs.ro.all(SQL[:get_sites]) do |row|
- rows << row.reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ rows << row.reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1402,7 +1402,10 @@ module Guff
r = [] of Hash(String, String)
@context.dbs.ro.all(SQL[:get_roles]) do |row|
- r << { "role": row["role"] as String, "name": row["name"] as String }
+ r << {
+ "role" => row["role"] as String,
+ "name" => row["name"] as String,
+ }
end
r
@@ -1603,8 +1606,8 @@ module Guff
def do_page_get(params : HTTP::Params)
@context.models.page.get(
post_id: params["post_id"].to_i64
- ).reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ ).reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1648,8 +1651,8 @@ module Guff
def do_project_get(params : HTTP::Params)
@context.models.project.get(
post_id: params["post_id"].to_i64
- ).reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ ).reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1691,8 +1694,8 @@ module Guff
def do_blog_get(params : HTTP::Params)
@context.models.blog.get(
post_id: params["post_id"].to_i64
- ).reduce({} of String => String) do |r, k, v|
- r[k] = v.to_s
+ ).reduce({} of String => String) do |r, kv|
+ r[kv[0]] = kv[1].to_s
r
end
end
@@ -1893,77 +1896,77 @@ module Guff
TITLE = "Guff Admin"
TABS = {
- "admin": [{
- id: "home",
- css: "active",
- icon: "fa-home",
- name: "Home",
- text: "View home tab.",
+ "admin" => [{
+ :id => "home",
+ :css => "active",
+ :icon => "fa-home",
+ :name => "Home",
+ :text => "View home tab.",
}, {
- id: "posts",
- css: "",
- icon: "fa-cubes",
- name: "Posts",
- text: "Manage blog, pages, and projects.",
+ :id => "posts",
+ :css => "",
+ :icon => "fa-cubes",
+ :name => "Posts",
+ :text => "Manage blog, pages, and projects.",
}, {
- id: "files",
- css: "",
- icon: "fa-files-o",
- name: "Files",
- text: "Manage files.",
+ :id => "files",
+ :css => "",
+ :icon => "fa-files-o",
+ :name => "Files",
+ :text => "Manage files.",
}, {
- id: "settings",
- css: "",
- icon: "fa-cogs",
- name: "Settings",
- text: "Configure settings.",
+ :id => "settings",
+ :css => "",
+ :icon => "fa-cogs",
+ :name => "Settings",
+ :text => "Configure settings.",
}],
- "settings": [{
- id: "general",
- css: "active",
- icon: "fa-cog",
- name: "General",
- text: "Manage general settings.",
+ "settings" => [{
+ :id => "general",
+ :css => "active",
+ :icon => "fa-cog",
+ :name => "General",
+ :text => "Manage general settings.",
}, {
- id: "backups",
- css: "",
- icon: "fa-archive",
- name: "Backups",
- text: "Manage backups.",
+ :id => "backups",
+ :css => "",
+ :icon => "fa-archive",
+ :name => "Backups",
+ :text => "Manage backups.",
}, {
- id: "import",
- css: "",
- icon: "fa-upload",
- name: "Import / Export",
- text: "Import and export posts.",
+ :id => "import",
+ :css => "",
+ :icon => "fa-upload",
+ :name => "Import / Export",
+ :text => "Import and export posts.",
}, {
- id: "sites",
- css: "",
- icon: "fa-sitemap",
- name: "Sites",
- text: "Manage sites and domains.",
+ :id => "sites",
+ :css => "",
+ :icon => "fa-sitemap",
+ :name => "Sites",
+ :text => "Manage sites and domains.",
}, {
- id: "themes",
- css: "",
- icon: "fa-eye",
- name: "Themes",
- text: "Manage themes.",
+ :id => "themes",
+ :css => "",
+ :icon => "fa-eye",
+ :name => "Themes",
+ :text => "Manage themes.",
}, {
- id: "users",
- css: "",
- icon: "fa-users",
- name: "Users",
- text: "Manage users and permissions.",
+ :id => "users",
+ :css => "",
+ :icon => "fa-users",
+ :name => "Users",
+ :text => "Manage users and permissions.",
}],
}
TEMPLATES = {
- option: "
+ :option => "
<option value='%s'>%s</option>
",
- new_post_button: "
+ :new_post_button => "
<a
href='#'
class='btn btn-primary'
@@ -2014,7 +2017,7 @@ module Guff
</ul>
",
- state_button: "
+ :state_button => "
<a
href='#'
class='btn btn-default'
@@ -2059,9 +2062,9 @@ module Guff
private def authors_menu_items
@context.models.user.get_users.map do |row|
{
- id: row["user_id"],
- name: row["name"],
- text: "Show author \"%s\"." % [row["name"]],
+ :id => row["user_id"],
+ :name => row["name"],
+ :text => "Show author \"%s\"." % [row["name"]],
}
end
end
@@ -2069,9 +2072,9 @@ module Guff
private def sites_menu_items
@context.models.site.get_sites.map do |row|
{
- id: row["site_id"],
- name: row["name"],
- text: "Show site \"%s\"." % [row["name"]],
+ :id => row["site_id"],
+ :name => row["name"],
+ :text => "Show site \"%s\"." % [row["name"]],
}
end
end
@@ -2079,10 +2082,10 @@ module Guff
private def states_menu_items
@context.models.state.get_states.map do |row|
{
- id: row["state"],
- name: row["name"],
- icon: row["icon"],
- text: "Show state \"%s\"." % [row["name"]],
+ :id => row["state"],
+ :name => row["name"],
+ :icon => row["icon"],
+ :text => "Show state \"%s\"." % [row["name"]],
}
end
end
@@ -2238,7 +2241,9 @@ module Guff
if context.request.method == "GET"
# send body for GET requests
File.open(abs_path) do |fh|
+ STDERR.puts "sending #{abs_path}"
IO.copy(fh, context.response)
+ STDERR.puts "done sending #{abs_path}"
end
end
end
@@ -2319,7 +2324,7 @@ module Guff
# create session
session_id = @context.session.create({
- "user_id": login(context.request.body).to_s,
+ "user_id" => login(context.request.body).to_s,
})
# add cookie
@@ -2590,44 +2595,44 @@ module Guff
end
HANDLERS = [{
- dev: true,
- id: :error,
+ :dev => true,
+ :id => :error,
}, {
- dev: false,
- id: :log,
+ :dev => false,
+ :id => :log,
}, {
- dev: false,
- id: :deflate,
+ :dev => false,
+ :id => :deflate,
}, {
- dev: false,
- id: :assets,
+ :dev => false,
+ :id => :assets,
}, {
- dev: false,
- id: :page,
+ :dev => false,
+ :id => :page,
}, {
- dev: false,
- id: :project,
+ :dev => false,
+ :id => :project,
}, {
- dev: false,
- id: :blog_post,
+ :dev => false,
+ :id => :blog_post,
}, {
- dev: false,
- id: :blog_list,
+ :dev => false,
+ :id => :blog_list,
}, {
- dev: false,
- id: :login,
+ :dev => false,
+ :id => :login,
}, {
- dev: false,
- id: :session,
+ :dev => false,
+ :id => :session,
}, {
- dev: false,
- id: :api,
+ :dev => false,
+ :id => :api,
}, {
- dev: false,
- id: :admin,
+ :dev => false,
+ :id => :admin,
}, {
- dev: false,
- id: :logout,
+ :dev => false,
+ :id => :logout,
}]
def self.get(context : Context) : Array(HTTP::Handler)