Module: Template
- Defined in:
- lib/template.rb,
lib/template/spec.rb,
lib/template/token.rb,
lib/template/required_file.rb
Defined Under Namespace
Classes: RequiredFile, Spec, Token
Class Method Summary
collapse
Class Method Details
.cli_list ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/template.rb', line 26
def self.cli_list
l = list
l.each do |template|
Formatador.display_line "* #{template[:repo]}/[green]#{template[:name].ljust(16)}[/]"
end
Formatador.display_line "You can use just the name in commands `#{l.first[:name]}`, as long as it's unambiguous."
Formatador.display_line "Otherwise include the repository, e.g. `#{l.first[:repo]+'/'+l.first[:name]}`"
end
|
.cli_spec(params) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/template.rb', line 43
def self.cli_spec(params)
params = Klipp::ParameterList.new(params)
identifier = params.shift_argument
raise Klipp::Hint.new("Add a new template name, like `klipp template spec AwesomeTemplate`") unless identifier && identifier.length > 0
raise "Invalid template name `#{identifier}`. Stick to simple characters and spaces." unless identifier.match(/^[ A-Za-z0-9_-]+$/)
spec = Template::Spec.new
spec.identifier = identifier.strip
file = File.join(Dir.pwd, "#{spec.identifier}.klippspec")
force = params.splice_option('-f')
file_existed = File.exists?(file)
allow_write = force || !file_existed
File.write(file, spec.klippspec) if allow_write
end
|
.route(*argv) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/template.rb', line 7
def self.route(*argv)
params = Klipp::ParameterList.new(argv)
command = params.shift_argument
commands = {
list: lambda { cli_list },
spec: lambda { cli_spec(params) }
}
case command
when nil
raise Klipp::Hint.new "Add a command to `klipp template [#{commands.keys.join('|')}]`"
else
if commands[command.to_sym]
commands[command.to_sym].call
else
raise "Unknown command `klipp template #{command}`"
end
end
end
|