Skip to content

Commit

Permalink
Fix root path
Browse files Browse the repository at this point in the history
Closes #58
  • Loading branch information
paulcsmith committed Jun 16, 2017
1 parent 5bc5d59 commit 0d3edee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/lucky_web/root_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require "../spec_helper"

class RootAction < LuckyWeb::Action
get "/" do
render_text "Hello there"
end
end

describe "root helpers" do
it "renders as /" do
RootAction.path.should eq "/"
RootAction.route.path.should eq "/"
end
end
8 changes: 7 additions & 1 deletion src/lucky_web/routeable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module LuckyWeb::Routeable
{{param.gsub(/:/, "").id}},
{% end %}
)
String.build do |path|
path = String.build do |path|
{% for part in path_parts %}
path << "/"
{% if part.starts_with?(":") %}
Expand All @@ -105,6 +105,9 @@ module LuckyWeb::Routeable
{% end %}
{% end %}
end
is_root_path = path == ""
path = "/" if is_root_path
path
end

def self.route(
Expand All @@ -122,6 +125,9 @@ module LuckyWeb::Routeable
{% end %}
{% end %}
end

is_root_path = path == ""
path = "/" if is_root_path
LuckyWeb::RouteHelper.new {{method}}, path
end
end
Expand Down

0 comments on commit 0d3edee

Please sign in to comment.