Class: Clerq::Cli
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #check ⇒ Object
- #new(project) ⇒ Object
- #node(id, title = '') ⇒ Object
- #promo ⇒ Object
- #toc ⇒ Object
- #version ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
17 18 19 |
# File 'lib/clerq/cli.rb', line 17 def self.exit_on_failure? false end |
Instance Method Details
#build ⇒ Object
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 = [:output] || Clerq.document + '.md' template = [:tt] || Clerq.template build = File.join(Clerq.bin, document) node = LoadAssembly.() node = QueryNode.(assembly: node, query: [:query]) if [:query] text = RenderNode.(node: node, template: template) File.write(build, text) say "'#{build}' created!" rescue StandardError => e stop!(e.) end |
#check ⇒ Object
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: [:template] || '') say "'#{fn}' created" rescue StandardError => e stop!(e.) end |
#promo ⇒ Object
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 |
#toc ⇒ Object
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: [:query]) if [: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.) end |