Add CoC and README for theme; make standard with Rubocop

This commit is contained in:
Parker Moore 2016-05-16 11:06:47 -07:00
parent e3df910533
commit 473d85b580
No known key found for this signature in database
GPG Key ID: 193CDEBA72063C58
7 changed files with 131 additions and 16 deletions

View File

@ -1,11 +1,11 @@
require 'erb' require "erb"
class Jekyll::Commands::NewTheme < Jekyll::Command class Jekyll::Commands::NewTheme < Jekyll::Command
class << self class << self
def init_with_program(prog) def init_with_program(prog)
prog.command(:"new-theme") do |c| prog.command(:"new-theme") do |c|
c.syntax 'new-theme NAME' c.syntax "new-theme NAME"
c.description 'Creates a new Jekyll theme scaffold' c.description "Creates a new Jekyll theme scaffold"
c.action do |args, _| c.action do |args, _|
Jekyll::Commands::NewTheme.process(args) Jekyll::Commands::NewTheme.process(args)
@ -14,7 +14,7 @@ class Jekyll::Commands::NewTheme < Jekyll::Command
end end
def process(args) 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("_") new_theme_name = args.join("_")
theme = Jekyll::ThemeBuilder.new(new_theme_name) theme = Jekyll::ThemeBuilder.new(new_theme_name)
@ -23,7 +23,8 @@ class Jekyll::Commands::NewTheme < Jekyll::Command
end end
theme.create! 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." Jekyll.logger.info "For help getting started, read #{theme.path}/README.md."
end end
end end

View File

@ -2,6 +2,8 @@ module Jekyll
module Errors module Errors
FatalException = Class.new(::RuntimeError) FatalException = Class.new(::RuntimeError)
InvalidThemeName = Class.new(FatalException)
DropMutationException = Class.new(FatalException) DropMutationException = Class.new(FatalException)
InvalidPermalinkError = Class.new(FatalException) InvalidPermalinkError = Class.new(FatalException)
InvalidYAMLFrontMatterError = Class.new(FatalException) InvalidYAMLFrontMatterError = Class.new(FatalException)

View File

@ -1,12 +1,12 @@
class Jekyll::ThemeBuilder class Jekyll::ThemeBuilder
SCAFFOLD_DIRECTORIES = %w{ SCAFFOLD_DIRECTORIES = %w(
_layouts _includes _sass _layouts _includes _sass
}.freeze ).freeze
attr_reader :name, :path attr_reader :name, :path
def initialize(theme_name) 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)) @path = Pathname.new(File.expand_path(name, Dir.pwd))
end end
@ -26,10 +26,8 @@ class Jekyll::ThemeBuilder
def template_file(filename) def template_file(filename)
[ [
root.join("theme_template", "#{filename}.erb"), root.join("theme_template", "#{filename}.erb"),
root.join("theme_template", "#{filename}") root.join("theme_template", filename.to_s)
].find do |pathname| ].find(&:exist?)
pathname.exist?
end
end end
def template(filename) def template(filename)
@ -43,14 +41,14 @@ class Jekyll::ThemeBuilder
def mkdir_p(directories) def mkdir_p(directories)
Array(directories).each do |directory| Array(directories).each do |directory|
full_path = path.join(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) FileUtils.mkdir_p(full_path)
end end
end end
def write_file(filename, contents) def write_file(filename, contents)
full_path = path.join(filename) full_path = path.join(filename)
Jekyll.logger.info "create", "#{full_path}" Jekyll.logger.info "create", full_path.to_s
File.write(full_path, contents) File.write(full_path, contents)
end end
@ -64,13 +62,13 @@ class Jekyll::ThemeBuilder
end end
def create_accessories 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)) write_file(filename, template(filename))
end end
end end
def initialize_git_repo 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` } Dir.chdir(path.to_s) { `git init` }
end end

View File

@ -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/

View File

@ -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).