This repository has been archived by the owner on Dec 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Gen liquid templates #16
Merged
Merged
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
59574e6
refact gyro to generate json and create liquid script to generate mod…
StevenWatremez 2852062
change spec for better visualisation
StevenWatremez c794367
manage templates and file system
StevenWatremez 0fe2bd6
integrate liquid generator inside gyro
StevenWatremez 4f766c0
manage comments
StevenWatremez c6df48d
improve loop to write non empty output
StevenWatremez 460eff2
add --param option for gyro cli
StevenWatremez fde6cd2
Manage default template with -t
StevenWatremez 024fdf2
improve spec tests with array
StevenWatremez 9806371
add rspec for liquid generation
StevenWatremez 7ada300
add realm test for liquid template.
StevenWatremez 6aadca7
manage fixtures with 2 spaces for indentations
StevenWatremez ed46bac
improve gyro cli and error messages
StevenWatremez 6704dd8
manage json_key_path for attributes/relationships/enums
StevenWatremez 7d89bf0
Revert "manage json_key_path for attributes/relationships/enums"
StevenWatremez 9383bca
add object mapper and Decodable template
StevenWatremez b85d512
improve gyro --template command line treatment
StevenWatremez 3f970ae
manage swift3 templates with Digiposte+ project
StevenWatremez 3f39574
update object mapper template to match with existing generation
StevenWatremez f15e927
re add android command line
StevenWatremez 9e692c9
fix bad behaviour for android generation and clean code inside gyro b…
StevenWatremez 4dd1c32
update fixtures for liquid TU
StevenWatremez b688c89
remove unused code
StevenWatremez 148500e
rename templates
StevenWatremez a7e84eb
fix bad condition for json key
StevenWatremez 6c5104e
remove useless type interpolation
StevenWatremez 97ba058
add wip java template
StevenWatremez 58c4fe0
finalize java template
StevenWatremez e19bdf7
improve android template. wip.
StevenWatremez dedab03
manage gemspec and gemfile
StevenWatremez 4cca27b
fix gemspec error
StevenWatremez 7cd5ff1
Fixed gem dependencies
b865016
Add patch for whitespace support in Liquid 3 :)
AliSoftware 5f38367
Fix the algorithm searching for templates in the data/templates dir
AliSoftware bee9d04
Generate a clean error when the output dir does not exist (instead of…
AliSoftware 02fb999
[rubocop] Replace License Block-Comments with standard comments
AliSoftware 31e2d0b
[rubocop] Additional style fixes
AliSoftware c1d565b
[Rubocop] Fix alias_method
AliSoftware 1d28c7f
[Rubocop] Style/AlignHash rule + Style/BracesAroundHashParameters
AliSoftware 5d3b970
[rubocop] Use `delete` or `tr` instead of `gsub` ; + lines too long
AliSoftware 7ff2939
[rubocop] And/Or style
AliSoftware b3759a3
[rubocop] case indentation
AliSoftware 65d49ee
[Rubocop] Style/ColonMethodCall
AliSoftware 5dd6ceb
[Rubocop] Style/ConditionalAssignment
AliSoftware 5e2b8af
[Rubocop] Style/DotPosition
AliSoftware ebe1040
[Rubocop] Style/EmptyLineBetweenDefs + Style/EmptyLines
AliSoftware aa8a8e2
[Rubocop] Style: Empty Lines
AliSoftware 268cf60
[Rubocop] Style/EmptyLiteral
AliSoftware 1adf222
[rubocop] Indentation
AliSoftware 4a33e86
[rubocop] freeze constants
AliSoftware c3e6e12
[rubocop] avoid semicolons
AliSoftware 002be8b
[rubocop] Fix spaces
AliSoftware 235e45f
Remove $LOAD_PATH.unshft(lib) in spec_helper
AliSoftware 829fd91
[Rubocop] Style/StringLiterals
AliSoftware ced3d50
[Rubocop] Style/TrailingBlankLines + Style/TrailingWhitespace
AliSoftware c65c9ec
[rubocop] Unneeded %q & Proc/block
AliSoftware 28e674e
[rubocop] Naming + Array literals
AliSoftware 60784e5
[Rubocop] Replace unless…else with if…else inverted logic
AliSoftware 16b440c
Fix "has_number_attribute?" for readability
AliSoftware 75c51e4
[rubocop] Use `next` when appropriate instead of big `if` blocks
AliSoftware 2c88cfe
[Rubocop] Useless return
AliSoftware f6b2afb
Methods & Modules Documentation
AliSoftware 6ca48e0
Clean-up Code Style using the `rubocop` tool
AliSoftware 6d66999
manage templates to match with whitespace support workaround
StevenWatremez 8ca157a
manage and test androi templates with SmartAssistan
StevenWatremez aae2052
move filters inside a specific file
StevenWatremez 7dafa9b
refact initializer methods for LiquidGen
StevenWatremez 786946a
improve documentation definition inside gemspec
StevenWatremez 1e8551b
move templates from data to lib folder
StevenWatremez ad38c6b
refact methods for LiquidGen file
StevenWatremez c5d2e8d
delete android cli
StevenWatremez 8da65ed
remove require for android gen and remove unsuse cli options
StevenWatremez b23952d
improve android templates
StevenWatremez 94c225e
implement code review feedbacks
StevenWatremez a15b405
manage fixtures
StevenWatremez d701d87
Fix Android UnitTests
TomTom-Fr 0563733
Add “\v” and liquid patch
TomTom-Fr 738c5ad
Add second ignore attribut for TU
TomTom-Fr 9b01178
Rename primitive with isPrimitives
TomTom-Fr aff6099
Use “|” separator (previous : “,”)
TomTom-Fr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,81 +24,56 @@ module Liquidgen | |
# | ||
class Generator | ||
|
||
attr_accessor :root_template, :filename_template, :params, :output_dir | ||
attr_accessor :enum_filename_template, :enum_filename_template_path, :enum_template_path, :enum_template | ||
attr_accessor :params, :output_dir, :template_dir | ||
|
||
# PUBLIC METHODS ####################################################### | ||
def initialize(template_dir, output_dir, params) | ||
Gyro::Log.title('Generating Model') | ||
|
||
@params = params | ||
@output_dir = output_dir | ||
|
||
# Parse object template name | ||
root_template_path = template_dir + 'root.liquid' | ||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to include root.liquid file') unless root_template_path.exist? | ||
root_template_string = root_template_path.read | ||
@root_template = Liquid::Template.parse(root_template_string) | ||
@template_dir = template_dir | ||
|
||
# Define Template path for Liquid file system to use Include Tag | ||
Liquid::Template.file_system = Liquid::LocalFileSystem.new(template_dir) | ||
# Parse object template | ||
filename_template_path = (template_dir + 'filename.liquid') | ||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to include filename.liquid file') unless filename_template_path.exist? | ||
filename_template_string = filename_template_path.readlines.first | ||
@filename_template = Liquid::Template.parse(filename_template_string) | ||
|
||
# Parse enum template | ||
@enum_template_path = (template_dir + 'enum.liquid') | ||
|
||
enum_template_string = enum_template_path.read | ||
@enum_template = Liquid::Template.parse(enum_template_string) | ||
|
||
# Parse enum template name | ||
@enum_filename_template_path = (template_dir + 'enum_filename.liquid').exist? ? (template_dir + 'enum_filename.liquid') : (template_dir + 'filename.liquid') | ||
enum_filename_template_string = enum_filename_template_path.readlines.first | ||
@enum_filename_template = Liquid::Template.parse(enum_filename_template_string) | ||
end | ||
|
||
def generate(xcdatamodel) | ||
generate_root_template(xcdatamodel) | ||
Gyro::Log.success('Model objects are generated !') | ||
end | ||
|
||
def generate(xcdatamodel) | ||
private ################################################################ | ||
|
||
def generate_root_template(xcdatamodel) | ||
xcdatamodel.to_h['entities'].each do |entity| | ||
entity_context = { 'params' => @params, 'entity' => entity } | ||
# Rendering template using entity and params context | ||
output = @root_template.render(entity_context, filters: [CustomFilters]) | ||
.gsub(/^ +$/, '') | ||
output = root_template_rendering(entity_context) | ||
# Don't generate empty output | ||
next if output.delete("\n").empty? | ||
|
||
filename_context = { 'params' => @params, 'name' => entity['name'] } | ||
# Rendering filename template using entity name and params context | ||
filename = @filename_template.render(filename_context).chomp | ||
filename = filename_rendering(filename_context) | ||
Gyro::Log.success("#{filename} is created !") | ||
# Write model object | ||
Gyro.write_file_with_name(@output_dir, filename, output) | ||
# Generate model object enums | ||
generate_enums(entity['attributes']) | ||
end | ||
|
||
Gyro::Log.success('Model objects are generated !') | ||
end | ||
|
||
private ################################################################ | ||
|
||
|
||
def generate_enums(attributes) | ||
enums = [] | ||
attributes.each do |attribute| | ||
enum_type = attribute['enum_type'] | ||
next unless !enums.include?(enum_type) && !enum_type.empty? | ||
enums.push(enum_type) | ||
next unless @enum_template_path.exist? | ||
|
||
enum_context = { 'params' => @params, 'attribute' => attribute } | ||
# Rendering enum template using attribute and params context | ||
output = @enum_template.render(enum_context, filters: [CustomFilters]) | ||
.gsub(/^ +$/, '') | ||
output = enum_template_rendering(enum_context) | ||
# Don't generate empty output | ||
next if output.delete("\n").empty? | ||
|
||
|
@@ -107,14 +82,49 @@ def generate_enums(attributes) | |
end | ||
|
||
def generate_enum(enum_name, output) | ||
|
||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to have enum_filename.liquid or filename.liquid file !') unless @enum_filename_template_path.exist? | ||
# Rendering enum filename template using enum name and params context | ||
enum_filename_context = { 'params' => @params, 'name' => enum_name } | ||
enum_filename = @enum_filename_template.render(enum_filename_context).chomp | ||
|
||
enum_filename = enum_filename_template_rendering(enum_filename_context) | ||
Gyro.write_file_with_name(@output_dir, enum_filename, output) | ||
end | ||
|
||
def root_template_rendering(context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename that |
||
# Parse object template | ||
root_template_path = @template_dir + 'root.liquid' | ||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to include root.liquid file') unless root_template_path.exist? | ||
root_template_string = root_template_path.read | ||
root_template = Liquid::Template.parse(root_template_string) | ||
root_template.render(context, filters: [CustomFilters]) | ||
.gsub(/^ +$/, '') | ||
end | ||
|
||
def filename_rendering(context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename that |
||
# Parse object template name | ||
filename_template_path = (@template_dir + 'filename.liquid') | ||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to include filename.liquid file') unless filename_template_path.exist? | ||
filename_template_string = filename_template_path.readlines.first | ||
filename_template = Liquid::Template.parse(filename_template_string) | ||
filename_template.render(context).chomp | ||
end | ||
|
||
def enum_template_rendering(context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename that |
||
# Parse enum template | ||
enum_template_path = (@template_dir + 'enum.liquid') | ||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to have enum.liquid file !') unless enum_template_path.exist? | ||
enum_template_string = enum_template_path.read | ||
enum_template = Liquid::Template.parse(enum_template_string) | ||
enum_template.render(context, filters: [CustomFilters]) | ||
.gsub(/^ +$/, '') | ||
end | ||
|
||
def enum_filename_template_rendering(context) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename that |
||
# Parse enum template name | ||
enum_filename_template_path = (@template_dir + 'enum_filename.liquid').exist? ? (@template_dir + 'enum_filename.liquid') : (@template_dir + 'filename.liquid') | ||
Gyro::Error.exit_with_error('Bad template directory content ! Your template need to have enum_filename.liquid or filename.liquid file !') unless enum_filename_template_path.exist? | ||
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 | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'd rather rename that
generate_entities_files
orgenerate_entities_from_root_template
, as it generates files from templates, it doesn't generate the root template itself.