Skip to content
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

If statement in .rambaspec #128

Closed
Antowkos opened this issue Aug 1, 2016 · 18 comments
Closed

If statement in .rambaspec #128

Antowkos opened this issue Aug 1, 2016 · 18 comments

Comments

@Antowkos
Copy link

Antowkos commented Aug 1, 2016

I use different classes for HTTP request, it parameters, path components and headers and it would be great if i could use only one template and just set some custom parameter like create_path_components:true and then path components class creates. Because not every request need to have path components or some parameters.

@Beniamiiin
Copy link
Contributor

Hi, @Antowkos. In last release we implement parameter custom-parameters for generamba gen command. Here is an example: generamba gen my_module my_template --custom-parameters=key1:value1 key2:value2. The value1 will be placed in your module for {{ module_info.custom_parameters.key1 }}. This is what you need?

@Antowkos
Copy link
Author

Antowkos commented Aug 1, 2016

Hi, @Beniamiiin. Thanks for so fast answer. Could i use it in .rambaspec file? I thought that {{ module_info.custom_parameters.key1 }} is only available in .liquid files for templates.

@etolstoy
Copy link
Member

etolstoy commented Aug 1, 2016

@Antowkos in what fields of .rambaspec do you want to use these parameters?

@Antowkos
Copy link
Author

Antowkos commented Aug 1, 2016

@etolstoy In code_files and test_files. But maybe it will be useful in dependencies too.

@etolstoy
Copy link
Member

etolstoy commented Aug 1, 2016

@Antowkos you can already use these parameters: #113

@Antowkos
Copy link
Author

Antowkos commented Aug 2, 2016

@etolstoy , @Beniamiiin . Correct me if i'm wrong. As i understand .rambaspec file is written in YAML and if it is then i don't know how i can use if statement there. Could you provide an example of how i can use if statement in .rambaspec file to add different files from one template base on custom-parameters key?

@Beniamiiin
Copy link
Contributor

@Antowkos if i understood you correctly, you want to do something like?

{% if create_path_components == true %}
   - {name: View/MyCustomViewInput.h, path: Code/View/view_input.h.liquid}
{% else %}
   - {name: View/ViewInput.h, path: Code/View/view_input.h.liquid}
{% endif %}

@Antowkos
Copy link
Author

Antowkos commented Aug 2, 2016

@Beniamiiin Yes. Is it possible now?

@Beniamiiin
Copy link
Contributor

@Antowkos unfortunately no, but we implement this ability in next release.

@Antowkos
Copy link
Author

Antowkos commented Aug 2, 2016

@Beniamiiin Cool! Thanks! 👍

@etolstoy etolstoy added this to the 1.1.0 milestone Aug 20, 2016
etolstoy added a commit that referenced this issue Sep 3, 2016
[RESOLVED] Added ability use custom parameters in rambaspec #128
@etolstoy etolstoy closed this as completed Sep 3, 2016
@Antowkos
Copy link
Author

@Beniamiiin Hi again! I just tried to use this new feature and it doesn't work.

I use syntax like this:

{% if create_path_components == true %}
   - {name: View/MyCustomViewInput.h, path: Code/View/view_input.h.liquid}
{% else %}
   - {name: View/ViewInput.h, path: Code/View/view_input.h.liquid}
{% endif %}

And got this error:

some_path/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/psych.rb:370:in `parse': (some_path/spec_name.rambaspec): found character that cannot start any token while scanning for the next token at line 11 column 52 (Psych::SyntaxError)

If i understand code of creation right then the error could be placed in creation of object ModuleTemplate. It waits for options to be passed to parse .rambaspec file as file with liquid markup, but it creates only in one place (lib/generamba/cli/gen_command.rb, line 48) this way template = ModuleTemplate.new(template_name), there are no options passed, as you can see, so i think this is the cause.

@Antowkos
Copy link
Author

@Beniamiiin @etolstoy Is anyone saw my comment?

@Beniamiiin
Copy link
Contributor

@Antowkos hi. Unfortunately we lost couple of code lines, when merged :) I already fixed this bug and we will release new version today.

@Beniamiiin Beniamiiin reopened this Sep 26, 2016
@Antowkos
Copy link
Author

Cool, thanks!

etolstoy added a commit that referenced this issue Sep 26, 2016
[RESOLVED] Added ability use custom parameters in rambaspec #128
@etolstoy
Copy link
Member

@etolstoy etolstoy reopened this Sep 26, 2016
@etolstoy etolstoy added the bug label Sep 26, 2016
@MaximBazarov
Copy link
Contributor

MaximBazarov commented Sep 26, 2016

seems like don't work, this is .rambaspec

# Template information section
name: nk-vicr-p
summary: NavigationKit based VICR module
author: Maksim Bazarov 
version: 1.0.0
license: MIT

# The declarations for code files
code_files:
- {name: Assembly.swift, path: Code/assembly.swift.liquid}
- {name: Module/View/View.swift, path: Code/view.swift.liquid}

{% if custom_parameters.type == 'table' %}
- {name: Module/View/DataSource.swift, path: Code/datasource.swift.liquid}
{% endif %}

And this is an error

ruby/2.3.0/psych.rb:377:in `parse': (swift-templates/nk-vicr-p/nk-vicr-p.rambaspec): found character that cannot start any token while scanning for the next token at line 13 column 2 (Psych::SyntaxError)
     lib/ruby/2.3.0/psych.rb:377:in `parse_stream'
     lib/ruby/2.3.0/psych.rb:325:in `parse'
     lib/ruby/2.3.0/psych.rb:252:in `load'
     lib/ruby/2.3.0/psych.rb:471:in `block in load_file'
     lib/ruby/2.3.0/psych.rb:471:in `open'
     lib/ruby/2.3.0/psych.rb:471:in `load_file'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/template/helpers/rambaspec_validator.rb:25:in `validate_spec'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/template/installer/local_installer.rb:20:in `install_template'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/template/processor/template_declaration.rb:32:in `install'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/template/processor/template_processor.rb:42:in `block in install_templates'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/template/processor/template_processor.rb:40:in `each'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/template/processor/template_processor.rb:40:in `install_templates'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/lib/generamba/cli/template/template_install_command.rb:18:in `install'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:115:in `invoke'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor.rb:235:in `block in subcommand'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
     lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
     lib/ruby/gems/2.3.0/gems/generamba-1.2.1/bin/generamba:5:in `<top (required)>'
     bin/generamba:23:in `load'
     bin/generamba:23:in `<main>'

@Antowkos
Copy link
Author

Antowkos commented Sep 27, 2016

@Beniamiiin @etolstoy I don't want to upset you, but there are also one more issue related to this feature. When i try to call generamba template install with template which is using this new feature i got same error as described above.

BTW template is working fine if i just use it by copy-paste to templates folder.

@etolstoy
Copy link
Member

generamba template install fixed in 1.2.2, thanks everyone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants