-
Notifications
You must be signed in to change notification settings - Fork 0
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
source: allow optionally specifying an extension for looking up source files #17
Conversation
8e0c34a
to
bb55eab
Compare
This updates template sources to pass the extension that was used to register an engine to the engine as an option. The goal is to allow the engine to choose templates that match the extension that was used when configuring the extension. This is also part of fixing an issue with the engines not knowing which template file to pick because they no longer hard-code an extension that the templates have to use. The template source now always sets an ext option and passes it to the engines when they are registered. The ext will always be set and can't be different from how the engine is registered. It would be non-sensical to register with one engine ext and pass a different engine ext as an option. Sanford would either not use the registered engine to render the template or the template engine wouldn't find the file. Either case wouldn't produce the desired result. Specifically, this is part of fixing an issue with the nm template engine no longer forcing templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford will now pass to the engine) to address this issue (redding/nm#17). Finally, this also renames "path" variables to "name" in the template source and engine. The variables are expected to be names and not full paths. This doesn't change any functionality it just clarifies the variable names.
@kellyredding - Looks good 💥 |
This updates template sources to pass the extension that was used to register an engine to the engine as an option. The goal is to allow the engine to choose templates that match the extension that was used when configuring the extension. This is also part of fixing an issue with the engines not knowing which template file to pick because they no longer hard-code an extension that the templates have to use. The template source now always sets an ext option and passes it to the engines when they are registered. The ext will always be set and can't be different from how the engine is registered. It would be non-sensical to register with one engine ext and pass a different engine ext as an option. Sanford would either not use the registered engine to render the template or the template engine wouldn't find the file. Either case wouldn't produce the desired result. Specifically, this is part of fixing an issue with the nm template engine no longer forcing templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford will now pass to the engine) to address this issue (redding/nm#17). Finally, this also renames "path" variables to "name" in the template source and engine. The variables are expected to be names and not full paths. This doesn't change any functionality it just clarifies the variable names.
This updates the template engine to pass its ext to nm source. The template engine ext is set by sanford when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with sanford. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with sanford not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by deas when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with deas. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with deas not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one deas-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by sanford when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with sanford. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with sanford not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by deas when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with deas. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with deas not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one deas-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by deas when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with deas. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with deas not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one deas-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by sanford when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with sanford. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with sanford not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford-nm will now pass to it) to address this issue (redding/nm#17).
bb55eab
to
2f211b6
Compare
@jcredding I've reworked this to have the source expect its files to end with any optional extension if one is given and to also be aware if the given template name already ends in the extension. I'll make comments on what I've changed since you've looked at this and you can tell me what you think. Thanks man. |
def source_file_path(template_name) | ||
Dir.glob(self.root.join("#{template_name}*")).first | ||
def source_file_path(name) | ||
Dir.glob(self.root.join(name.end_with?(@ext) ? name : "#{name}*#{@ext}")).first |
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.
@jcredding Here is where I make the glob expect the the template to end with the ext if one is present. Notice I default the ext to nil
above. This allows me to not have to check whether an ext is present of not. If no extension is present, end_with?
is false the the string interpolations means the glob ends up being name*
.
Does this work for you?
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.
@kellyredding - Yeah this looks like what we discussed. I didn't know end_with?
was a thing. Nice.
2f211b6
to
f11cc03
Compare
template_desc += " with #{@ext.inspect} as an extension" | ||
end | ||
raise ArgumentError, "#{template_desc} does not exist" | ||
end |
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.
@jcredding here I add checking that a filename exists and raising a friendly argument error if not. I made the template description aware of any specified ext and if the given template name already ended with it.
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.
@kellyredding - I'm good with the better error here.
@kellyredding - I'm good with the changes. Thanks for working through what we discussed 💥 |
f11cc03
to
789cb9b
Compare
…e files This helps when you have two files names the same thing but with different extensions. Previously, only the first file globbed would be rendered. This allows you to prefer rendering one over the other. This scenario should have been covered in PR 16 but was missed. Note: this also changes to have Nm complain if asked to render a named template that doesn't exist (whether specifying an extension or not). This makes for more friendly errors in this scenario.
789cb9b
to
00dcc67
Compare
This updates the template engine to pass its ext to nm source. The template engine ext is set by sanford when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with sanford. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with sanford not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by deas when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with deas. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with deas not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one deas-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by sanford when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with sanford. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with sanford not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford-nm will now pass to it) to address this issue (redding/nm#17).
* source: allow optionally specifying an extension for looking up source files #17
This updates the template engine to pass its ext to nm source. The template engine ext is set by sanford when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with sanford. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with sanford not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one sanford-nm will now pass to it) to address this issue (redding/nm#17).
This updates the template engine to pass its ext to nm source. The template engine ext is set by deas when the engine is registered. This makes it so nm will use templates with the extension that was used when registering the engine with deas. This is the expected behavior and avoids confusion with nm randomly not using a template that matches the registered extension. This is part of fixing an issue with deas not rendering the expected nm template. This is because the nm engine no longer forced templates extension to be `nm` (see redding/nm#16). By not expecting an extension, the nm engine can't pick the correct file as the template if there are multiple files with the same name except for their extensions. For example, a common pattern is to name a handler file and the template the same only the handler will have `.rb` for its extension and the template would use `.nm`. In this scenario, it's possible for the nm engine to try and use the ruby file as its template. Nm is being updated to use a custom extension (the one deas-nm will now pass to it) to address this issue (redding/nm#17).
This helps when you have two files names the same thing but with
different extensions. Previously, only the first file globbed would
be rendered. This allows you to prefer rendering one over the other.
This scenario should have been covered in PR 16 but was missed.
Note: this also changes to have Nm complain if asked to render a named
template that doesn't exist (whether specifying an extension or not).
This makes for more friendly errors in this scenario.
See #16 for reference.
@jcredding ready for review.