class Clerq::Cli
Public Class Methods
exit_on_failure?()
click to toggle source
# File lib/clerq/cli.rb, line 17 def self.exit_on_failure? false end
source_root()
click to toggle source
# File lib/clerq/cli.rb, line 13 def self.source_root File.join Clerq.root, "lib/assets" end
Public Instance Methods
build()
click to toggle source
# File lib/clerq/cli.rb, line 98 def build stop_unless_clerq! document = options[:output] || Clerq.document + '.md' template = options[:tt] || Clerq.template build = File.join(Clerq.bin, document) node = LoadAssembly.() node = QueryNode.(assembly: node, query: options[:query]) if options[:query] text = RenderNode.(node: node, template: template) File.write(build, text) say "'#{build}' created!" rescue StandardError => e stop!(e.message) end
check()
click to toggle source
# File lib/clerq/cli.rb, line 114 def check stop_unless_clerq! puts "Checking assembly for writing errors..." CheckAssembly.(LoadAssembly.()) end
clerq_project?()
click to toggle source
# File lib/clerq/cli.rb, line 40 def clerq_project? File.exist?(Clerq::Settings::STORAGE) || Dir.exist?(Clerq.settings.src) end
new(project)
click to toggle source
# File lib/clerq/cli.rb, line 61 def new(project) stop! "'#{project}' folder already exists!" if Dir.exist?(project) say "Creating project '#{project}'..." settings = Clerq.settings tts = [ {tt: 'new/README.md.tt', target: 'README.md'}, {tt: 'new/clerq.yml.tt', target: Clerq::Settings::STORAGE}, {tt: 'new/clerq.thor.tt', target: thor_filename(project)}, {tt: 'new/content.md.tt', target: File.join(settings.src, "#{project}.md")} ] config = {project: project, klass: ruby_class_name(project)} Dir.mkdir(project) Dir.chdir(project) do settings.folders.each{|f| Dir.mkdir(f)} tts.each do |tt| template(tt[:tt], File.join(Dir.pwd, tt[:target]), config) end directory('tt', File.join(Dir.pwd, 'tt')) directory('lib', File.join(Dir.pwd, 'lib')) say "Project created!" end end
node(id, title = '')
click to toggle source
# File lib/clerq/cli.rb, line 137 def node(id, title = '') stop_unless_clerq! fn = CreateNode.(id: id, title: title, template: options[:template] || '') say "'#{fn}' created" rescue StandardError => e stop!(e.message) end
promo()
click to toggle source
# File lib/clerq/cli.rb, line 88 def promo say "Copying promo content ..." directory('promo', Dir.pwd) say "Copied!" end
query_assembly(query)
click to toggle source
# File lib/clerq/cli.rb, line 52 def query_assembly(query) # TODO pretty errors ...OK, ... 1 error found, ... 2 errors found on_parse = lambda {|src| puts "Reading '#{src}'... "} on_error = lambda {|err| puts "\terror: #{err} "} QueryAssembly.(query: query, on_parse: on_parse, on_error: on_error) end
ruby_class_name(str)
click to toggle source
@param [String] @returns [String] usual name for ruby class
# File lib/clerq/cli.rb, line 36 def ruby_class_name(str); str.split(/[\W+_]/).map(&:capitalize).join end
stop!(msg)
click to toggle source
# File lib/clerq/cli.rb, line 48 def stop!(msg) raise Thor::Error, msg end
stop_unless_clerq!()
click to toggle source
# File lib/clerq/cli.rb, line 44 def stop_unless_clerq! stop! "Clerq project required!" unless clerq_project? end
thor_filename(str)
click to toggle source
@param [String] @returns [String] usual name for ruby file
# File lib/clerq/cli.rb, line 30 def thor_filename(str); str.split(/[\W+_]/).map(&:downcase).join('_') + '.thor' end
toc()
click to toggle source
# File lib/clerq/cli.rb, line 122 def toc stop_unless_clerq! node = LoadAssembly.() node = QueryNode.(assembly: node, query: options[:query]) if options[:query] puts "% #{node.title}" puts "% #{node[:query]}" if node[:query] node.to_a.drop(1).each{|n| puts "#{' ' * (n.nesting_level - 1)}[#{n.id}] #{n.title}" } rescue StandardError => e stop!(e.message) end
version()
click to toggle source
# File lib/clerq/cli.rb, line 22 def version puts "Clerq v#{Clerq::VERSION}" end