Skip to content

Commit

Permalink
Use kemal and crystal 0.10.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
veelenga authored and zamith committed Dec 30, 2015
1 parent 5c8c04f commit 8319d63
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 20 deletions.
3 changes: 0 additions & 3 deletions .deps.lock

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
libs
.sass-cache
node_modules
.shards
3 changes: 0 additions & 3 deletions Projectfile

This file was deleted.

18 changes: 9 additions & 9 deletions app.cr
@@ -1,4 +1,4 @@
require "frank"
require "kemal"
require "http/client"
require "./views/index"
require "./models/github_repos"
Expand Down Expand Up @@ -27,24 +27,24 @@ def filter(repos, filter)
end

def fetch_sort(context)
sort = context.params["sort"]? || "stars"
sort = context.params["sort"]?.try(&.to_s) || "stars"
sort = "stars" unless SORT_OPTIONS.includes?(sort)
sort
end

def fetch_filter(context)
context.params["filter"]?.try(&.strip.downcase) || ""
def fetch_filter(env)
env.params["filter"]?.try(&.to_s.strip.downcase) || ""
end

private def matches_filter?(item: GithubRepo, filter: String)
private def matches_filter?(item : GithubRepo, filter : String)
item.name.downcase.includes?(filter) ||
item.description.try(&.downcase.includes? filter)
end

get "/" do |context|
sort = fetch_sort(context)
filter = fetch_filter(context)
context.response.content_type = "text/html"
get "/" do |env|
sort = fetch_sort(env)
filter = fetch_filter(env)
env.content_type = "text/html"
repos = REPOS_CACHE.fetch(sort) { crystal_repos(sort) }
repos = filter(repos, filter) unless filter.empty?
Views::Index.new repos, sort, filter
Expand Down
8 changes: 4 additions & 4 deletions models/github_repo.cr
@@ -1,18 +1,18 @@
require "json"

class GithubRepo
json_mapping({
JSON.mapping({
name: { type: String },
html_url: { type: String },
description: { type: String, nilable: true },
watchers_count: { type: Int32 }
watchers_count: { type: Int32 },
owner: Owner,
pushed_at: { type: Time, converter: TimeFormat.new("%FT%TZ") },
pushed_at: { type: Time, converter: Time::Format.new("%FT%TZ") },
forks: { type: Int32 },
})

struct Owner
json_mapping({
JSON.mapping({
login: String,
})
end
Expand Down
2 changes: 1 addition & 1 deletion models/github_repos.cr
Expand Up @@ -2,7 +2,7 @@ require "json"
require "./github_repo"

class GithubRepos
json_mapping({
JSON.mapping({
total_count: { type: Int32 },
items: { type: Array(GithubRepo) }
})
Expand Down
6 changes: 6 additions & 0 deletions shard.lock
@@ -0,0 +1,6 @@
version: 1.0
shards:
kemal:
github: sdogruyol/kemal
version: 0.5.0

8 changes: 8 additions & 0 deletions shard.yml
@@ -0,0 +1,8 @@
name: crystalshards
version: 0.1.0
author: Luis Ferreira

dependencies:
kemal:
github: sdogruyol/kemal
version: 0.5.0

0 comments on commit 8319d63

Please sign in to comment.