class Ruboty::Gen::Readme
ReadmeGen Core
Constants
- README
- RUBOTY_MEGEN_FILE
- RUBOTY_MEGEN_TEMPLATE
- RUBOTY_README_EMOJI_TEMPLATE
- RUBOTY_README_TEMPLATE
Public Class Methods
generate(options = {})
click to toggle source
generate ruboty README.md template.
# File lib/ruboty/gen/readme.rb, line 197 def self.generate(options = {}) src = read_dsl dsl = Ruboty::Dsl.new dsl.instance_eval src src = apply(dsl.ruboty_megen, options) File.open(README, 'w:utf-8') { |file|file.puts src } end
init()
click to toggle source
generate Rubotymegenfile to current directory.
# File lib/ruboty/gen/readme.rb, line 190 def self.init File.open(RUBOTY_MEGEN_FILE, 'w') do |f| f.puts RUBOTY_MEGEN_TEMPLATE end end
Private Class Methods
apply(config, options)
click to toggle source
rubocop:disable UselessAssignment
# File lib/ruboty/gen/readme.rb, line 211 def self.apply(config, options) gem_class_name = config.gem_class_name gem_name = config.gem_name title = config.title command_table = command_table(config.commands) usages = usages(config.commands) env_table = env_table(config.env) dependency_table = dependency_table(config.dependencies) user_name = config.user_name erb = ERB.new(choose_template(options)) erb.result(binding) end
choose_template(options)
click to toggle source
# File lib/ruboty/gen/readme.rb, line 275 def self.choose_template(options) options[:emoji] ? RUBOTY_README_EMOJI_TEMPLATE : RUBOTY_README_TEMPLATE end
command_table(commands)
click to toggle source
rubocop:enable UselessAssignment
# File lib/ruboty/gen/readme.rb, line 227 def self.command_table(commands) command_table = commands.each_with_object([]) do |e, memo| command_link = "[#{e.read_name}](##{e.read_name})" list = ['', command_link, e.read_pattern, e.read_description, ''] list = normalize_markdown_table(list) memo << list.join('|') end command_table.join("\n") end
dependency_table(dependencies)
click to toggle source
# File lib/ruboty/gen/readme.rb, line 260 def self.dependency_table(dependencies) dependency_table = dependencies.each_with_object([]) do |e, memo| list = ['', e.read_name, e.read_description, ''] list = normalize_markdown_table(list) memo << list.join('|') end dependency_table.join("\n") end
env_table(env)
click to toggle source
# File lib/ruboty/gen/readme.rb, line 250 def self.env_table(env) env_table = env.each_with_object([]) do |e, memo| list = ['', e.read_name, e.read_description, ''] list = normalize_markdown_table(list) memo << list.join('|') end env_table.join("\n") end
normalize_markdown_table(texts)
click to toggle source
# File lib/ruboty/gen/readme.rb, line 270 def self.normalize_markdown_table(texts) texts.map { |e| e.gsub('|', '|') } end
read_dsl()
click to toggle source
# File lib/ruboty/gen/readme.rb, line 205 def self.read_dsl File.open(RUBOTY_MEGEN_FILE) { |f|f.read } end
usages(commands)
click to toggle source
# File lib/ruboty/gen/readme.rb, line 238 def self.usages(commands) usages = commands.each_with_object([]) do |e, memo| name = e.read_name description = e.read_description example = e.read_example row = ["### #{name}", "* #{description}", '', '~~~', example.chomp, '~~~'] memo << row.join("\n") end usages.join("\n\n") end