DEV: plugin generator will now ask for github username (#6337)

This commit is contained in:
Joffrey JAFFEUX
2018-08-30 12:03:30 +02:00
committed by GitHub
parent 9c7e029d01
commit acc96abe1a
4 changed files with 17 additions and 6 deletions

View File

@ -1,11 +1,12 @@
require 'rails/generators/named_base' require 'rails/generators/named_base'
class PluginGenerator < Rails::Generators::NamedBase class PluginGenerator < Rails::Generators::NamedBase
attr_writer :github_username
desc 'This generator creates a Discourse plugin skeleton' desc 'This generator creates a Discourse plugin skeleton'
source_root File.expand_path('templates', __dir__) source_root File.expand_path('templates', __dir__)
class_option :author, type: :string, desc: "Plugin author", required: true
class_option :stylesheet, type: :boolean, desc: "Generate Stylesheet", default: true class_option :stylesheet, type: :boolean, desc: "Generate Stylesheet", default: true
class_option :javascript, type: :boolean, desc: "Generate Javascript initializer", default: true class_option :javascript, type: :boolean, desc: "Generate Javascript initializer", default: true
class_option :scheduled_job, type: :boolean, desc: "Generate scheduled job", default: false class_option :scheduled_job, type: :boolean, desc: "Generate scheduled job", default: false
@ -18,14 +19,20 @@ class PluginGenerator < Rails::Generators::NamedBase
end end
def create_readme_file def create_readme_file
ensure_github_username
template 'README.md.erb', File.join('plugins', dasherized_name, "README.md") template 'README.md.erb', File.join('plugins', dasherized_name, "README.md")
end end
def create_license_file def create_license_file
ensure_github_username
template 'LICENSE.erb', File.join('plugins', dasherized_name, "LICENSE") template 'LICENSE.erb', File.join('plugins', dasherized_name, "LICENSE")
end end
def create_plugin_file def create_plugin_file
ensure_github_username
template 'plugin.rb.erb', File.join('plugins', dasherized_name, "plugin.rb") template 'plugin.rb.erb', File.join('plugins', dasherized_name, "plugin.rb")
end end
@ -49,6 +56,10 @@ class PluginGenerator < Rails::Generators::NamedBase
end end
end end
def ensure_github_username
@github_username ||= ask("Github username?")
end
def underscored_name def underscored_name
name.underscore name.underscore
end end

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2018 <%= @options['author'] %>. Copyright (c) 2018 <%= @github_username %>.
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View File

@ -5,7 +5,7 @@
## Installation ## Installation
Follow [Install a Plugin](https://meta.discourse.org/t/install-a-plugin/19157) Follow [Install a Plugin](https://meta.discourse.org/t/install-a-plugin/19157)
how-to from the official Discourse Meta, using `git clone https://github.com/<%= @options['author'] %>/<%= dasherized_name %>.git` how-to from the official Discourse Meta, using `git clone https://github.com/<%= @github_username %>/<%= dasherized_name %>.git`
as the plugin command. as the plugin command.
## Usage ## Usage

View File

@ -1,8 +1,8 @@
# name: <%= name %> # name: <%= name %>
# about: AWESOME_PLUGIN # about:
# version: 0.1 # version: 0.1
# authors: <%= @options['author'] %> # authors: <%= @github_username %>
# url: https://github.com/<%= @options['author'] %> # url: https://github.com/<%= @github_username %>
<% if @options["stylesheet"] %> <% if @options["stylesheet"] %>
register_asset "stylesheets/common/<%= dasherized_name %>.scss" register_asset "stylesheets/common/<%= dasherized_name %>.scss"