-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Render using absolute path #146
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this implementation.
@@ -6,7 +6,11 @@ module Amber::Controller | |||
{% if filename.id.split("/").size > 2 %} | |||
Kilt.render("{{filename.id}}") | |||
{% else %} | |||
Kilt.render("#{{{path}}}/{{filename.id}}") | |||
{% if path == "src/views" %} | |||
Kilt.render("{{__FILE__.split('/')[0..-4].join('/').id}}/#{{{path}}}/{{filename.id}}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If absolute path is important then we should probably add so that all renders take it into account. Using it only when path = "src/views" only fixes this partially assuming it's something that actually needs fixed.
Seems a little funny using absolute paths for views in a web project though. Could you perhaps just fix your editor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__FILE__.split('/')[0..-4]
assumes that __FILE__
is always going to be at the same level. If someone were to render a view from presenter, or even another ecr file it will fail.
Yes, I wil try to fix my editor since this PR seems a bit hacky
:sweat_smile:
…On Sat, Jul 22, 2017 at 1:12 PM, Isaac Sloan ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Not sure about this implementation.
------------------------------
In src/amber/controller/render.cr
<#146 (comment)>:
> @@ -6,7 +6,11 @@ module Amber::Controller
{% if filename.id.split("/").size > 2 %}
Kilt.render("{{filename.id}}")
{% else %}
- Kilt.render("#{{{path}}}/{{filename.id}}")
+ {% if path == "src/views" %}
+ Kilt.render("{{__FILE__.split('/')[0..-4].join('/').id}}/#{{{path}}}/{{filename.id}}")
If absolute path is important then we should probably add it at a deeper
level so that all renders take it into account.
Seems a little funny using absolute paths for views in a web project
though. Could you perhaps just fix your editor?
------------------------------
In src/amber/controller/render.cr
<#146 (comment)>:
> @@ -6,7 +6,11 @@ module Amber::Controller
{% if filename.id.split("/").size > 2 %}
Kilt.render("{{filename.id}}")
{% else %}
- Kilt.render("#{{{path}}}/{{filename.id}}")
+ {% if path == "src/views" %}
+ Kilt.render("{{__FILE__.split('/')[0..-4].join('/').id}}/#{{{path}}}/{{filename.id}}")
__FILE__.split('/')[0..-4] assumes that __FILE__ is always going to be at
the same level. If someone were to render a view from presenter, or even
another ecr file it will fail.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#146 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AC7Nx4AuzNe7TxBJwh_5Firw5-oZkxWGks5sQjungaJpZM4OgClE>
.
|
This error also is happening with Kemal and other Crystal programs, so I opened a issue in vscode-crystal-lang instead 👉 https://github.com/faustinoaq/vscode-crystal-lang/issues/5 |
Now, My editor extension is fixed https://github.com/faustinoaq/vscode-crystal-lang/pull/10 😄 |
Description of the Change
This PR add absolute path to macro render_template.
Alternate Designs
The absolute path is used if path is equal to
"src/view"
Why Should This Be In Core?
Currently in my amber projects I have to rewrite the macro
render_template
adding support for absolute path, because vscode-crystal-lang extension can't find relative paths when analyze code.My
application_controller.cr
Some screenshots:
Show macro errors related to relative path of views:
Errors fixed using absolute path:
Benefits
This change add absolute path only if path is equal to
"src/view"
so, if path change the render process uses the path given.Possible Drawbacks
Absolute path is calculated using
__FILE__
only when path is default to views folder, if path changes then absolute path isn't used.Applicable Issues
Editor extensions like Scry can't find relative paths used by macros, so this PR help to users to avoid unnecessary macro errors.