Class: Clerq::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/clerq/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/clerq/cli.rb', line 17

def self.exit_on_failure?
  false
end

.source_rootObject



13
14
15
# File 'lib/clerq/cli.rb', line 13

def self.source_root
  File.join Clerq.root, "lib/assets"
end

Instance Method Details

#buildObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# 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

#checkObject



114
115
116
117
118
# File 'lib/clerq/cli.rb', line 114

def check
  stop_unless_clerq!
  puts "Checking assembly for writing errors..."
  CheckAssembly.(LoadAssembly.())
end

#new(project) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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 = '') ⇒ Object



137
138
139
140
141
142
143
# 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

#promoObject



88
89
90
91
92
# File 'lib/clerq/cli.rb', line 88

def promo
  say "Copying promo content ..."
  directory('promo', Dir.pwd)
  say "Copied!"
end

#tocObject



122
123
124
125
126
127
128
129
130
131
132
133
# 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

#versionObject



22
23
24
# File 'lib/clerq/cli.rb', line 22

def version
  puts "Clerq v#{Clerq::VERSION}"
end