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
-
.execute ⇒ Object
Public: CLI Stuff, parse command line inputs to determine what to do.
-
.templates_path ⇒ Object
Public: Retrieve the full path which stores templates.
Class Method Details
.execute ⇒ Object
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 = OpenStruct.new .output_dir = Dir.pwd .verbose = false .delete_dir = false # Defines options parser opt_parser = OptionParser.new do |opts| opts. = 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| .output_dir = dir end # Should we remove the output directory first opts.on('-d', '--delete', 'If set, clear the output directory first') do .delete_dir = true end opts.separator '' opts.separator 'Common options:' # Verbose mode opts.on('-v', '--verbose', 'Verbose mode') do .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], .output_dir, .delete_dir, .verbose) gen.build end |
.templates_path ⇒ Object
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 |