Skip to content

Commit

Permalink
Rename render -> html
Browse files Browse the repository at this point in the history
Closes #904
  • Loading branch information
paulcsmith committed Sep 16, 2019
1 parent 5b50862 commit 34bf2c2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 28 deletions.
4 changes: 2 additions & 2 deletions spec/lucky/action_rendering_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ end

class Rendering::Index < TestAction
route do
render title: "Anything", arg2: "testing multiple args"
html title: "Anything", arg2: "testing multiple args"
end
end

class Namespaced::Rendering::Index < TestAction
route do
render ::Rendering::IndexPage, title: "Anything", arg2: "testing multiple args"
html ::Rendering::IndexPage, title: "Anything", arg2: "testing multiple args"
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lucky/action_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end

class Tests::Index < TestAction
route do
render
html
end
end

Expand Down
7 changes: 3 additions & 4 deletions spec/lucky/expose_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ class OnlyExpose < TestAction
expose :name

get "/expose" do
render
render OnlyExposePage
html OnlyExposePage
end

def name
Expand Down Expand Up @@ -44,8 +43,8 @@ class MultipleExposeAndAssigns < InheritedExposureAction
expose :expose_three

get "/mutli-expose" do
render arg1: "arg1", arg2: "arg2"
render MultipleExposeAndAssignsPage, arg1: "arg1", arg2: "arg2"
html arg1: "arg1", arg2: "arg2"
html MultipleExposeAndAssignsPage, arg1: "arg1", arg2: "arg2"
end

def expose_three
Expand Down
4 changes: 2 additions & 2 deletions spec/lucky/infer_page_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ end

class Rendering::Foo < TestAction
get "/foo" do
render Rendering::CustomPage, title: "EditPage", arg2: "testing_multiple_args"
html Rendering::CustomPage, title: "EditPage", arg2: "testing_multiple_args"
end
end

class Rendering::WithinSameNameSpace < TestAction
get "/in-namespace" do
render CustomPage, title: "WithinSameNameSpace", arg2: "testing_multiple_args"
html CustomPage, title: "WithinSameNameSpace", arg2: "testing_multiple_args"
end
end

Expand Down
8 changes: 4 additions & 4 deletions src/lucky/action_callbacks.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module Lucky::ActionCallbacks
# Run a method before an action is called
#
# Methods will run in the order that each `before` is defined. Also, each
# method must return a `Lucky::Response` like `redirect`, `render`, `json`,
# method must return a `Lucky::Response` like `redirect`, `html`, `json`,
# etc, or call `continue`:
#
# ```crystal
Expand Down Expand Up @@ -90,7 +90,7 @@ module Lucky::ActionCallbacks
# `after` isn't as common as `before` but can still be useful. One example
# would be to log a successful transaction to analytics. Methods will run in
# the order that each `after` is defined. Also, each method must return
# either a `Lucky::Response` like `redirect`, `render`, `json`, etc, or call
# either a `Lucky::Response` like `redirect`, `html`, `json`, etc, or call
# `continue`:
#
# ```crystal
Expand Down Expand Up @@ -119,7 +119,7 @@ module Lucky::ActionCallbacks
callback_result = {{ callback_method }}
ensure_callbacks_return_response_or_continue(callback_result)
# Callback {{ callback_method }} should return a Lucky::Response or Lucky::ActionCallbacks::Continue
# Do this by using `continue` or one of rendering methods like `render` or `redirect`
# Do this by using `continue` or one of rendering methods like `html` or `redirect`
#
# def {{ callback_method }}
# cookies["name"] = "John"
Expand All @@ -144,7 +144,7 @@ module Lucky::ActionCallbacks

ensure_callbacks_return_response_or_continue(callback_result)
# Callback {{ callback_method }} should return a Lucky::Response or Lucky::ActionCallbacks::Continue
# Do this by using `continue` or one of rendering methods like `render` or `redirect`
# Do this by using `continue` or one of rendering methods like `html` or `redirect`
#
# def {{ callback_method }}
# cookies["name"] = "John"
Expand Down
12 changes: 6 additions & 6 deletions src/lucky/exposable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ module Lucky::Exposable
# ```
# class Messages::Index < BrowserAction
# route do
# render IndexPage, current_user: current_user
# html IndexPage, current_user: current_user
# end
# end
#
# class Messages::New < BrowserAction
# route do
# render NewPage, current_user: current_user
# html NewPage, current_user: current_user
# end
# end
# ```
Expand All @@ -68,13 +68,13 @@ module Lucky::Exposable
# ```
# class Messages::Index < BrowserAction
# route do
# render IndexPage
# html IndexPage
# end
# end
#
# class Messages::New < BrowserAction
# route do
# render NewPage
# html NewPage
# end
# end
# ```
Expand All @@ -88,7 +88,7 @@ module Lucky::Exposable
# expose message
#
# route do
# render ShowPage
# html ShowPage
# end
#
# private def message
Expand All @@ -102,7 +102,7 @@ module Lucky::Exposable
#
# ```
# route do
# render ShowPage, message: message
# html ShowPage, message: message
# end
# ```
macro expose(method_name)
Expand Down
16 changes: 10 additions & 6 deletions src/lucky/renderable.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module Lucky::Renderable
# Render a page and pass it data
#
# `render` is used to pass data to a page. Each key/value pair must match up
# with each `needs` declarations for that page. For example, if we have a
# page like this:
# `html` is used to pass data to a page and render it. Each key/value pair
# must match up with each `needs` declarations for that page. For example, if
# we have a page like this:
#
# ```crystal
# class Users::IndexPage < MainLayout
Expand All @@ -17,12 +17,12 @@ module Lucky::Renderable
# end
# ```
#
# Our action must pass a `users` key to the `render` method like this:
# Our action must pass a `users` key to the `html` method like this:
#
# ```crystal
# class Users::Index < BrowserAction
# route do
# render IndexPage, users: UserQuery.new
# html IndexPage, users: UserQuery.new
# end
# end
# ```
Expand All @@ -43,7 +43,7 @@ module Lucky::Renderable
# end
# end
# ```
macro render(page_class = nil, **assigns)
macro html(page_class = nil, **assigns)
validate_page_class!({{ page_class }})

render_html_page(
Expand All @@ -56,6 +56,10 @@ module Lucky::Renderable
)
end

private def render(*args, **named_args)
{% raise "'render' in actions has been renamed to 'html'" %}
end

macro validate_page_class!(page_class)
{% if page_class && page_class.resolve? %}
{% ancestors = page_class.resolve.ancestors %}
Expand Down
10 changes: 7 additions & 3 deletions src/lucky/secure_headers/set_xss_guard.cr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
module Lucky
module SecureHeaders
# This module sets the HTTP header [X-XSS-Protection](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection).
# It's job is responsible for telling the browser to not render a page if it detects cross-site scripting.
# Lucky disables this header for Internet Explorer version < 9 for you as per recommendations. Read more on [Microsoft](https://blogs.msdn.microsoft.com/ieinternals/2011/01/31/controlling-the-xss-filter/).
# This module sets the HTTP header
# [X-XSS-Protection](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection).
# It's job is responsible for telling the browser to not render a page if
# it detects cross-site scripting. Lucky disables this header for Internet
# Explorer version < 9 for you as per recommendations. Read more on
# [Microsoft](https://blogs.msdn.microsoft.com/ieinternals/2011/01/31/controlling-the-xss-filter/).
#
# Include this module in the actions you want to add this to.

# ```
# class BrowserAction < Lucky::Action
# include Lucky::SecureHeaders::SetXSSGuard
Expand Down

0 comments on commit 34bf2c2

Please sign in to comment.