Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Easy generators #118

Merged
merged 1 commit into from
Jul 29, 2014
Merged

Easy generators #118

merged 1 commit into from
Jul 29, 2014

Conversation

adamhjk
Copy link
Contributor

@adamhjk adamhjk commented Jul 29, 2014

Depends on PR #117

Adds ChefDK::Generator.add_attr_to_context, which handles adding
instance variables (and optionally their values) to the
ChefDK::Generator::Context and ChefDK::Generator::TemplateHelper. This
makes writing new generators much easier, because you don't have to be
aware of how/when/where the context variables are set up - you can just
focus in on the generator you are adding.

Additionally, any option added to a generator is dynamically added to
the Context and TemplateHelper if it has a value, making the barrier
even smaller. One thing to note is that generator options really should
either be true/false or have default values that make sense for the
generator, or you're liable to get errors. (This is appropriate, I
think)

While cleaning up the existing context accessors, I noticed that at
least one of them (license_description) existed in a template, but was
never set anywhere. I implemented the method within the TemplateHelper,
so that you can dynamically ask for the correct license description to
embedd in a file, including what to comment the license with.


Create new cookbooks in this directory with Knife.

knife cookbook create COOKBOOK
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: (why) are we not encouraging chef generate cookbook NAME?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will change them as soon as the rest of the pending workflow RFC gets
merged/we have time.

On Mon, Jul 28, 2014 at 5:30 PM, Claire McQuin notifications@github.com
wrote:

In
lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/README.md:

  • current_dir = File.dirname(FILE)
  • cookbook_path ["#{current_dir}/../cookbooks"]

+Which will set current_dir to the location of the knife.rb file itself (e.g. ~/chef-repo/.chef/knife.rb).
+
+Configure knife to use your preferred copyright holder, email contact and license. Add the following lines to .chef/knife.rb.
+

+Supported values for cookbook_license are "apachev2", "mit","gplv2","gplv3", or "none". These settings are used to prefill comments in the default recipe, and the corresponding values in the metadata.rb. You are free to change the the comments in those files.
+
+Create new cookbooks in this directory with Knife.
+

  • knife cookbook create COOKBOOK

Question: (why) are we not encouraging chef generate cookbook NAME?


Reply to this email directly or view it on GitHub
https://github.com/opscode/chef-dk/pull/118/files#r15500302.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! Good information to know. :)

@mcquin
Copy link
Contributor

mcquin commented Jul 29, 2014

Super cool. I like the readmes... very delightful.

@adamhjk
Copy link
Contributor Author

adamhjk commented Jul 29, 2014

The readmes are actually part of the other PR - I'm not sure how to have (can you have?) dependent review requests with Github. But this one builds on top of the other PR.

@mcquin
Copy link
Contributor

mcquin commented Jul 29, 2014

You can PR on a PR but it gets weird quickly.

@adamhjk
Copy link
Contributor Author

adamhjk commented Jul 29, 2014

I liked the terseness of writing:

Generator.add_attr_to_context(:thing)

Vs:

Generator::Context.add_attr(:thing)

In particular because it's not just adding to context, but the template helper as well. Happy to change it if you would rather.

@adamhjk
Copy link
Contributor Author

adamhjk commented Jul 29, 2014

Fixed both of Dan's suggestions (public_send and moved add_attr to a method on context)

Adds ChefDK::Generator.add_attr_to_context, which handles adding
instance variables (and optionally their values) to the
ChefDK::Generator::Context and ChefDK::Generator::TemplateHelper. This
makes writing new generators much easier, because you don't have to be
aware of how/when/where the context variables are set up - you can just
focus in on the generator you are adding.

Additionally, any option added to a generator is dynamically added to
the Context and TemplateHelper if it has a value, making the barrier
even smaller. One thing to note is that generator options really should
either be true/false or have default values that make sense for the
generator, or you're liable to get errors. (This is appropriate, I
think)

While cleaning up the existing context accessors, I noticed that at
least one of them (license_description) existed in a template, but was
never set anywhere. I implemented the method within the TemplateHelper,
so that you can dynamically ask for the correct license description to
embedd in a file, including what to comment the license with.
attr_accessor :copyright_holder
attr_accessor :email
attr_accessor :policy_only
def self.add_attr(name)

Choose a reason for hiding this comment

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

👍 to the cleanliness, but this definitely needs some docs and @example tags for future developers please 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - my plan is to write docs on how to write generators easily.

Choose a reason for hiding this comment

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

❤️

adamhjk added a commit that referenced this pull request Jul 29, 2014
@adamhjk adamhjk merged commit 2ff9a14 into chef-boneyard:master Jul 29, 2014
@adamhjk adamhjk deleted the easy_generators branch July 29, 2014 20:41
ksubrama pushed a commit that referenced this pull request Jan 11, 2016
Pick libyaml 0.1.5 in builds.
@chef-boneyard chef-boneyard locked and limited conversation to collaborators Feb 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants