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

Templates engine & Examples #446

Open
AutomationD opened this issue Jan 9, 2016 · 5 comments
Open

Templates engine & Examples #446

AutomationD opened this issue Jan 9, 2016 · 5 comments
Assignees
Milestone

Comments

@AutomationD
Copy link

I would love to see templates in the projects, so when you init a project you could init it with an example, that will have certain information filled out, for example:

platformio init -b megaatmega2560 --ide clion --template BasicSerial will init Arduino basic serial project, so you don't have to copy-paste things.

Also, what can be done, is implementing jinja2 templating enging to replace certain values in the actual code (for example serial baud rate:)

void setup() {
    Serial.begin({{serial_baudrate}});    
}

Where serial_baudrate could be a parameter in the PIO global file or local (by the precedence).

Please let me know what do you guys think.

@ivankravets ivankravets self-assigned this Jan 13, 2016
@ivankravets
Copy link
Member

Good idea, thanks! Need to understand that these examples depend on framework type too.

@mogorman
Copy link

i like idea about serial_baud_rate, would be better better though ifi it was just passed via #defines though. although how those are set could be done in the platformio.ini file for sure

@ivankravets ivankravets modified the milestone: 3.0.0 Jan 19, 2016
@ivankravets ivankravets mentioned this issue Jan 31, 2016
37 tasks
@skorokithakis
Copy link

I would also love this. Ability to pull from a git repo directly would be great, but it's not too much hassle for me to just pull the repo somewhere and use it as a template locally.

@ivankravets ivankravets changed the title Templates engine & Exmples Templates engine & Examples Jun 13, 2016
@ivankravets ivankravets removed this from the 3.0.0 milestone Jun 13, 2016
@ivankravets ivankravets added this to the 3.3.0 milestone Mar 10, 2017
@ivankravets ivankravets modified the milestones: 3.3.0, 3.4.0 Mar 26, 2017
@ivankravets ivankravets modified the milestone: 3.4.0 Apr 29, 2017
@ivankravets ivankravets modified the milestone: 3.5.0 Jun 26, 2017
@ivankravets ivankravets modified the milestones: 3.5.0, 3.6.0 Jul 31, 2017
@ivankravets ivankravets modified the milestones: 3.5.0, 3.6.0 Oct 31, 2017
@DrSensor
Copy link

I think for template feature, it can be split into 2 kinds of template.

1. Scaffold Template

This template is a custom template for a very specific case. For example, template project for building Web Server in ESP8266 that will consist of Arduino code and SPA Framework specific code (Angular/Vue/React). However, Scaffold Template is a feature just to facilitate if anyone wants to make their own template project (like in the corporate when they need to integrate their Prototype with their own Service).

Usage

pio init gh:username/platformio-mytemplate

This will fetch template from that GitHub repo then generate the files and folder from that.

Technical Suggestion

Luckily in python, there is a command-line utility that creates projects from project template called cookiecutters. I think it's best if it builds on top of that to reduce the complexity and make the documentation more simple by linking it to cookie-cutter documentation. Also, it can be called from python


2. Template from Library Example

This feature is more like injector rather than template. Some Library (especially many Arduino Library) has Code Example like in here that can be treated as a Template then it can be analyzed then injected into the current project file.

Usage

pio example <lib_name> --list

Basic

pio lib example <lib_name> --print <example_name>                       # print code example to console
pio lib example <lib_name> --print <example_name> --output <filename>   # output code example to file

Inject

pio lib example <lib_name> --add
pio lib example <lib_name> --add <example_name>

For example, if we want inject/add the implementation of DHT11_Logger with Library AWS_IOT into the current project:

pio lib example AWS_IOT --add DHT11_Logger
command that's not necessery to implement

This command is not necessary to implement because better to delete it manually rather than automatically (as long as it's injecting into one file).

pio example <lib_name> --remove
pio example <lib_name> --remove <example_name>

Technical Suggestion

This feature is a little bit complex to implement, especially in inject usage. To implement that, it needs to parse AST of the example code then inject it into the main code (some of the javascript project generators usually use this technique). Python lib that I know support parsing AST of C++ source is pycparse (although it's not really well documented, there is code example for the starter). Also, note that the Example code of the Library is Framework and Platform specific. I think the simplest Framework to experiment this feature is Arduino.

@ivankravets ivankravets removed this from the 4.0 milestone Aug 2, 2018
@AlesSt
Copy link

AlesSt commented Nov 29, 2022

I would like to add my vote to this request/plea also as I would REALLY love to see this feature added.

I have about 3 or 4 different base "templates" that I usually start all my projects with (and usually always forget something hence my hairline thinning of all the head scratching where did I go wrong :) ).

So my suggestion/need would be:

Templates:

  • consists usually of custom platformio.ini file (mainly my own "half-libs")
  • also custom partition.csv file
  • and custom main.cpp file

As @DrSensor already mentioned years ago about Scaffold Template (project init with different template setups from git) would would be a spot on feature.

Otherwise ABSOLUTELY AMAZING work by PIO crew. So I would like to THANK YOU ALL that are working on this project that we all greatly benefit from.

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

6 participants