From 473d85b580bb755476cec61ffead3cb6131ce6df Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 16 May 2016 11:06:47 -0700 Subject: [PATCH] Add CoC and README for theme; make standard with Rubocop --- lib/jekyll/commands/new_theme.rb | 11 ++-- lib/jekyll/errors.rb | 2 + lib/jekyll/theme_builder.rb | 20 +++--- lib/theme_template/CODE_OF_CONDUCT.md | 0 lib/theme_template/CODE_OF_CONDUCT.md.erb | 74 +++++++++++++++++++++++ lib/theme_template/README.md | 0 lib/theme_template/README.md.erb | 40 ++++++++++++ 7 files changed, 131 insertions(+), 16 deletions(-) delete mode 100644 lib/theme_template/CODE_OF_CONDUCT.md create mode 100644 lib/theme_template/CODE_OF_CONDUCT.md.erb delete mode 100644 lib/theme_template/README.md create mode 100644 lib/theme_template/README.md.erb diff --git a/lib/jekyll/commands/new_theme.rb b/lib/jekyll/commands/new_theme.rb index 3855c3f8..e8919ae3 100644 --- a/lib/jekyll/commands/new_theme.rb +++ b/lib/jekyll/commands/new_theme.rb @@ -1,11 +1,11 @@ -require 'erb' +require "erb" class Jekyll::Commands::NewTheme < Jekyll::Command class << self def init_with_program(prog) prog.command(:"new-theme") do |c| - c.syntax 'new-theme NAME' - c.description 'Creates a new Jekyll theme scaffold' + c.syntax "new-theme NAME" + c.description "Creates a new Jekyll theme scaffold" c.action do |args, _| Jekyll::Commands::NewTheme.process(args) @@ -14,7 +14,7 @@ class Jekyll::Commands::NewTheme < Jekyll::Command end def process(args) - raise InvalidThemeName, 'You must specify a theme name.' if args.empty? + raise Jekyll::Errors::InvalidThemeName, "You must specify a theme name." if args.empty? new_theme_name = args.join("_") theme = Jekyll::ThemeBuilder.new(new_theme_name) @@ -23,7 +23,8 @@ class Jekyll::Commands::NewTheme < Jekyll::Command end theme.create! - Jekyll.logger.info "Your new Jekyll theme, #{theme.name}, is ready for you in #{theme.path}!" + Jekyll.logger.info "Your new Jekyll theme, #{theme.name}," \ + " is ready for you in #{theme.path}!" Jekyll.logger.info "For help getting started, read #{theme.path}/README.md." end end diff --git a/lib/jekyll/errors.rb b/lib/jekyll/errors.rb index 322eb6af..01bc99b3 100644 --- a/lib/jekyll/errors.rb +++ b/lib/jekyll/errors.rb @@ -2,6 +2,8 @@ module Jekyll module Errors FatalException = Class.new(::RuntimeError) + InvalidThemeName = Class.new(FatalException) + DropMutationException = Class.new(FatalException) InvalidPermalinkError = Class.new(FatalException) InvalidYAMLFrontMatterError = Class.new(FatalException) diff --git a/lib/jekyll/theme_builder.rb b/lib/jekyll/theme_builder.rb index 8b352865..cde4eaff 100644 --- a/lib/jekyll/theme_builder.rb +++ b/lib/jekyll/theme_builder.rb @@ -1,12 +1,12 @@ class Jekyll::ThemeBuilder - SCAFFOLD_DIRECTORIES = %w{ + SCAFFOLD_DIRECTORIES = %w( _layouts _includes _sass - }.freeze + ).freeze attr_reader :name, :path def initialize(theme_name) - @name = theme_name.to_s.gsub(/ /, "_").gsub(/_+/, "_") + @name = theme_name.to_s.tr(" ", "_").gsub(/_+/, "_") @path = Pathname.new(File.expand_path(name, Dir.pwd)) end @@ -26,10 +26,8 @@ class Jekyll::ThemeBuilder def template_file(filename) [ root.join("theme_template", "#{filename}.erb"), - root.join("theme_template", "#{filename}") - ].find do |pathname| - pathname.exist? - end + root.join("theme_template", filename.to_s) + ].find(&:exist?) end def template(filename) @@ -43,14 +41,14 @@ class Jekyll::ThemeBuilder def mkdir_p(directories) Array(directories).each do |directory| full_path = path.join(directory) - Jekyll.logger.info "create", "#{full_path}" + Jekyll.logger.info "create", full_path.to_s FileUtils.mkdir_p(full_path) end end def write_file(filename, contents) full_path = path.join(filename) - Jekyll.logger.info "create", "#{full_path}" + Jekyll.logger.info "create", full_path.to_s File.write(full_path, contents) end @@ -64,13 +62,13 @@ class Jekyll::ThemeBuilder end def create_accessories - %w{README.md CODE_OF_CONDUCT.md LICENSE.txt}.each do |filename| + %w(README.md CODE_OF_CONDUCT.md LICENSE.txt).each do |filename| write_file(filename, template(filename)) end end def initialize_git_repo - Jekyll.logger.info "initialize", "#{path.join(".git")}" + Jekyll.logger.info "initialize", path.join(".git").to_s Dir.chdir(path.to_s) { `git init` } end diff --git a/lib/theme_template/CODE_OF_CONDUCT.md b/lib/theme_template/CODE_OF_CONDUCT.md deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/theme_template/CODE_OF_CONDUCT.md.erb b/lib/theme_template/CODE_OF_CONDUCT.md.erb new file mode 100644 index 00000000..2b2c7734 --- /dev/null +++ b/lib/theme_template/CODE_OF_CONDUCT.md.erb @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at <%= user_email %>. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/lib/theme_template/README.md b/lib/theme_template/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/theme_template/README.md.erb b/lib/theme_template/README.md.erb new file mode 100644 index 00000000..75909a49 --- /dev/null +++ b/lib/theme_template/README.md.erb @@ -0,0 +1,40 @@ +# <%= theme_name %> + +Welcome to your new Jekyll theme! In this directory, you'll find the files you need to be able to package up your theme into a gem. Put your layouts in `_layouts`, your includes in `_includes` and your sass in `_sass`. To experiment with this code, add some sample content and run `bundle exec jekyll serve` – this directory is setup just like a Jekyll site! + +TODO: Delete this and the text above, and describe your gem + +## Installation + +Add this line to your Jekyll site's Gemfile: + +```ruby +gem <%= theme_name.inspect %> +``` + +And add this line to your Jekyll site: + +```yaml +theme: <%= theme_name %> +``` + +And then execute: + + $ bundle + +Or install it yourself as: + + $ gem install <%= theme_name %> + +## Usage + +TODO: Write usage instructions here. Describe your available layouts, includes, and/or sass. + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hello. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. + +## License + +The theme is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). +