Module: Templatron

Defined in:
lib/templatron/cli.rb,
lib/templatron/config.rb,
lib/templatron/version.rb,
lib/templatron/generator.rb

Defined Under Namespace

Classes: Generator

Constant Summary collapse

PREFIX =

This part will be joined to the user Dir.home

'.templatron'
VERSION =
'0.1.2'

Class Method Summary collapse

Class Method Details

.executeObject

Public: CLI Stuff, parse command line inputs to determine what to do



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/templatron/cli.rb', line 11

def self.execute

  usage = 'Usage: templatron TEMPLATE_NAME [args] [-o output_dir]'

  # If no argument has been given, print usage

  if ARGV.length == 0
    puts usage
    exit
  end

  # Defines the structure and default values

  options = OpenStruct.new
  options.output_dir = Dir.pwd
  options.verbose = false
  options.delete_dir = false

  # Defines options parser

  opt_parser = OptionParser.new do |opts|
    opts.banner = usage
    opts.default_argv = '-h'

    opts.separator ''
    opts.separator 'Features:'

    # Defines where to put generated files

    opts.on('-o', '--output PATH', 'Where to put the generated files') do |dir|
      options.output_dir = dir
    end

    # Should we remove the output directory first

    opts.on('-d', '--delete', 'If set, clear the output directory first') do
      options.delete_dir = true
    end

    opts.separator ''
    opts.separator 'Common options:'

    # Verbose mode

    opts.on('-v', '--verbose', 'Verbose mode') do
      options.verbose = true
    end

    # Print the help

    opts.on_tail('-h', '--help', 'Show this message') do
      puts opts
      puts ''
      puts "Templates path: #{Templatron::templates_path}"
      exit
    end

    # Print version number

    opts.on_tail('--version', 'Show version') do
      puts Templatron::VERSION
      exit
    end
  end

  opt_parser.parse!(ARGV)

  # Instantiate the generator and build the stuff

  gen = Generator.new(
    ARGV[0], 
    ARGV[1..ARGV.length], 
    options.output_dir,
    options.delete_dir, 
    options.verbose)
  gen.build
end

.templates_pathObject

Public: Retrieve the full path which stores templates



8
9
10
# File 'lib/templatron/config.rb', line 8

def self.templates_path
  File.join(Dir.home, PREFIX)
end