class Ruboty::Gen::Article

Article

Constants

RUBOTY_ARTICLE_TEMPLATE
RUBOTY_MEGEN_FILE
RUBOTY_MEGEN_TEMPLATE

Public Class Methods

generate() click to toggle source

generate ruboty Article Markdown template.

# File lib/ruboty/gen/article.rb, line 150
def self.generate
  src = read_dsl
  dsl = Ruboty::Dsl.new
  dsl.instance_eval src
  src = apply(dsl.ruboty_articlegen)
  File.open("ruboty-#{dsl.ruboty_articlegen.gem_name}.md", 'w:utf-8') do |file|
    file.puts src
  end
end
init() click to toggle source

generate Rubotyarticlegenfile to current directory.

# File lib/ruboty/gen/article.rb, line 143
def self.init
  File.open(RUBOTY_MEGEN_FILE, 'w') do |f|
    f.puts RUBOTY_MEGEN_TEMPLATE
  end
end

Private Class Methods

apply(config) click to toggle source

rubocop:disable UselessAssignment

# File lib/ruboty/gen/article.rb, line 166
def self.apply(config)
  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
  purpose = config.purpose

  erb = ERB.new(RUBOTY_ARTICLE_TEMPLATE)
  erb.result(binding)
end
command_table(commands) click to toggle source

rubocop:enable UselessAssignment

# File lib/ruboty/gen/article.rb, line 182
def self.command_table(commands)
  command_table = commands.each_with_object([]) do |e, memo|
    list = ['', e.read_name, 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/article.rb, line 214
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/article.rb, line 204
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/article.rb, line 224
def self.normalize_markdown_table(texts)
  texts.map { |e| e.gsub('|', '&#124;') }
end
read_dsl() click to toggle source
# File lib/ruboty/gen/article.rb, line 160
def self.read_dsl
  File.open(RUBOTY_MEGEN_FILE) { |f|f.read }
end
usages(commands) click to toggle source
# File lib/ruboty/gen/article.rb, line 192
def self.usages(commands)
  usages = commands.each_with_object([]) do |e, memo|
    name = e.read_name
    description = e.read_description
    example = e.read_example.chomp
    row = ["### #{name}", "* #{description}", '', '~~~', "#{example}", '~~~']
    memo << row.join("\n")
  end
  usages.join("\n\n")
end