Module: Cadenza::Cli

Extended by:
Cli
Included in:
Cli
Defined in:
lib/cadenza/cli.rb,
lib/cadenza/cli/options.rb

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Instance Method Details

#parse(path, options) ⇒ Object


34
35
36
# File 'lib/cadenza/cli.rb', line 34

def parse(path, options)
  $stdout.puts context.load_template!(path).to_tree
end

#render(path, options) ⇒ Object


38
39
40
# File 'lib/cadenza/cli.rb', line 38

def render(path, options)
  Cadenza.render_template path, options[:context], {:context => context}
end

#run!(path, options = {}) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cadenza/cli.rb', line 9

def run!(path, options={})
  # set up the load paths
  if options[:root]
    load_paths.push(options[:root])
  elsif options.fetch(:load_paths, []).any?
    load_paths.concat(options[:load_paths])
  else
    load_paths.push(Dir.pwd)
  end

  # add load paths to the context
  load_paths.each do |load_path|
    context.add_load_path load_path
  end

  # based on the action, perform whatever the user has asked
  send(options[:action], path, options)
end

#tokenize(path, options) ⇒ Object


28
29
30
31
32
# File 'lib/cadenza/cli.rb', line 28

def tokenize(path, options)
  lexer = Cadenza::Lexer.new
  lexer.source = context.load_source!(path)
  $stdout.puts lexer.remaining_tokens.map(&:inspect).join("\n")
end