Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

Feature/liquid review templates loading #20

Merged
merged 6 commits into from
May 31, 2017

Conversation

TomTom-Fr
Copy link
Contributor

@TomTom-Fr TomTom-Fr commented May 30, 2017

Load templates in generator initializer once using private class method. ( see https://github.com/NijiDigital/gyro/projects/1#card-3129113 )

@TomTom-Fr TomTom-Fr requested a review from AliSoftware May 30, 2017 13:41
@AliSoftware AliSoftware changed the base branch from master to liquid May 30, 2017 14:29
@@ -24,18 +24,22 @@ module Liquidgen
#
class Generator

attr_accessor :params, :output_dir, :template_dir
attr_accessor :params, :output_dir
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done see 5ae90bf

filename_template_string = filename_template_path.readlines.first
filename_template = Liquid::Template.parse(filename_template_string)
filename_template.render(context).chomp
@entity_filename_template.render(context).chomp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you removed/commented line 55 above, there's no more guarantee that the template use to provide the filename will render as a single line. In case the @*_filename_template.render(…) generates more than one line, that's gonna generate ugly/strange file names in the Finder with newlines…

We should add some sort of security for those, like replacing all "\n" by " " for example, or only take the first line into account… (chomp only remove the newline characters at the end of the string, not in the middle)

Copy link
Collaborator

@AliSoftware AliSoftware May 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or better, emit a warning (or even error out) as we discussed yesterday, to tell the user to fix the entity_filename.liquid template, because after all that's the template author's responsibility 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see 9b62c02

enum_filename_template_string = enum_filename_template_path.readlines.first
enum_filename_template = Liquid::Template.parse(enum_filename_template_string)
enum_filename_template.render(context).chomp
@enum_filename_template.render(context).chomp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, see 9b62c02

Gyro::Error.exit_with_error('Bad template directory content ! Your template need to ' + template_path.to_s + ' file') unless template_path.exist?
template_path_string = template_path.read
#filename_template_string = filename_template_path.readlines.first - filename.liquid
Gyro::Log.error('The given template ' + template_path.to_s + ' contains return line(s). This can lead to side effets.') unless !(preventReturnLine && template_path_string.include?("\n"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer if x to unless !x

@AliSoftware AliSoftware merged commit 3e06042 into liquid May 31, 2017
@AliSoftware AliSoftware deleted the feature/liquid_review_templates_loading branch June 2, 2017 19:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants